Last active
March 6, 2021 15:56
-
-
Save shyamalschandra/cdf936d425f9569e8dded809de664d5f to your computer and use it in GitHub Desktop.
Line drawing program for Processing for Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import de.looksgood.ani.*; | |
PGraphics topLayer, bottomLayer; | |
int widthandheight = 10; | |
int smallestwidthandheight = 5; | |
float numSeconds = 1.5; | |
int boxColor = 255; | |
int x, y; | |
boolean debugMode = false; | |
int stepSize = 5; | |
int prevX, prevY; | |
void setup() { | |
frameRate(60); | |
randomSeed(0); | |
size(800, 800); | |
background(0); | |
surface.setTitle("Blocks game"); | |
Ani.init(this); | |
topLayer = createGraphics(800,800); | |
bottomLayer = createGraphics(800,800); | |
} | |
void draw() { | |
background(0); | |
topLayer.beginDraw(); | |
topLayer.line(prevX, prevY, x, y); | |
topLayer.stroke(255); | |
topLayer.endDraw(); | |
bottomLayer.beginDraw(); | |
bottomLayer.line(prevX, prevY, x, y); | |
bottomLayer.stroke(random(255), random(255), random(255)); | |
bottomLayer.strokeWeight(10); | |
bottomLayer.strokeCap(ROUND); | |
bottomLayer.endDraw(); | |
fill(random(0,255),random(0,255),random(0,255)); | |
rect(x, y, widthandheight, widthandheight); | |
prevX = x; | |
prevY = y; | |
image(bottomLayer, 0, 0); | |
image(topLayer, 0, 0); | |
} | |
void mousePressed() { | |
if (debugMode == true) { | |
debugPrint("mouseX", str(mouseX)); | |
debugPrint("mouseY", str(mouseY)); | |
} | |
Ani.to(this, numSeconds, "x", mouseX); | |
Ani.to(this, numSeconds, "y", mouseY); | |
//Ani.to(this, numSeconds, "widthandheight", widthandheight+=stepSize); | |
} | |
void debugPrint(String variableName, String output) { | |
println(variableName); | |
println("---------------------"); | |
println(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to run inside Processing, please go to the "Sketch" menu item, select "Import Library..." -> "Add Library...", go to the "Libraries" pane and then, search "Ani" and press the "Install" button. That's it!