Coder Social home page Coder Social logo

processinglite's Introduction

ProcessingLite

This mini-project aims to recreate some basic processing functions in Unity3D, using a single file that you can just drop in the project.

This is made for Unity3D version 2020.2 or newer but is largely untested, the limit is because it uses some C# version 8 syntax.

Usage / Installation

  1. Download the ProcessingLite.cs file.
  2. Drag and drop the ProcessingLite.cs file into your unity project.
    (Don't add it to your scene! It just need to be in the project)
  3. Change inherence from the class MonoBehaviour to ProcessingLite.GP21.
    (You will still have all MonoBehaviour functionality).
  4. Use the supported commands, listed below, in the normal Unity Start and/or Update functions.

Differences From Processing

Please note that the origin of the program will be different from processing. The camera is automatically moved so that origin is placed in the lower left corner of the screen.

The positions is measured in Unity Units and not pixels.

These changes have been made to make the future transition into Unity much easier.

Supported Commands

All of the listed commands will not have full processing functionality Example: basic rectangles are supported but not rounded corners. The "basic" version of these commands should work.

Processing documentation

Environment

  • Height, this returns the height of the screen in Unity-units.
  • Width, this returns the width of the screen in Unity-units.

Shape

  • Attributes
    • StrokeWeight(width), sets line width
  • Vertex
    • BeginShape()
    • EndShape()
    • Vertex(x, y)
  • 2D primitives
    • Circle(x, y, diameter)
    • Ellipse(x, y, height, width)
    • Line(x1, y1, x2, y2)
    • Point(x, y)
    • Quad(x1, y1, x2, y2, x3, y3, x4, y4)
    • Rect(x1, y1, x2, y2)
    • Square(x1, y1, size)
    • Triangle(x1, y1, x2, y2, x3, y3)

Color

  • Background(color)
  • Fill(color)
  • NoFill()
  • NoStroke()
  • Stroke(color)

Text

  • Text(string, x, y), Only supports center align text for now
  • FontSize(size)

Input

  • MouseX
  • MouseY

Features covered by Unity

Some features from Processing will not be ported over since the already exist in Unity, and the end goal is to move over to Unity.

  • Data
  • Input (MouseX, MouseY is supported)
  • Transform
  • Math and Constants
  • PVector

Known Issues

  • ProcessingLite creates objects in a way that's invalid and gives a warning in Unity, this can be ignored.
  • Don't change scenes, it will break.

Test Code

In Unity, create a class called Test. Change the inheritance from MonoBehaviour to ProcessingLite.GP21. Add the code below, run the program. If you see the word Hi on the screen, then it's working as intended.

using UnityEngine;

public class Test : ProcessingLite.GP21
{
  void Start()
  {
    Line(4, 7, 4, 3);
    Line(4, 5, 6, 5);
    Line(6, 7, 6, 3);
    Line(8, 5.5f, 8, 3);
    Line(8, 7, 8, 6.8f);
  }
}

Contributors

References

processinglite's People

Contributors

millenniumambiguity avatar wowbagger84 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

processinglite's Issues

Shape normal can face the wrong direction

When drawn in the wrong order, the fill of a shape (Triangle, Quad, or Vertex) will not be visible from the perspective of the camera.
Possible solutions that come to mind:

  1. checking the normal of faces and then inverting those that have an incorrect face orentation.
  2. checking first face's normal and if it is in the wrong orientation, reverse the order in which they are created/drawn.
  3. use a material with dual side rendering / disabled culling.

see ProcessingLite.PShape.ShapeFill for mesh creation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.