Skip to content

Instantly share code, notes, and snippets.

@Morpholux
Last active May 10, 2018 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Morpholux/55d669d423c0557d51c54e9049bd6950 to your computer and use it in GitHub Desktop.
Save Morpholux/55d669d423c0557d51c54e9049bd6950 to your computer and use it in GitHub Desktop.
Example of a simple drawing machine
// renaud.jean-francois(arobas)uqam(point)ca
// Syntaxe Processing version 3.3.7
// mercredi, 9 mai 2018
// Press spacebar to draw white lines segment while caret is moving.
color c = color(40);
int posX, posY;
int stepLength = 2;
int margin = 50;
void setup() {
size(600, 600);
background(0);
noStroke();
posX = margin;
posY = margin;
rectMode(CENTER);
}
void draw() {
//background(0); // keep uncommented to leave a trace of the moving rectangle
posX += stepLength; // moving forward
if (posX >= width-margin) {
posX = margin;
posY+= 50;
}
if (posY > height-margin) {
background(0); // arrived at bottom, erase all lines
posY = margin; // move back to top
}
fill(c);
rect(posX, posY, stepLength+1, 4);
}
void keyPressed() {
if (key==' ') {
c = color(255);
}
}
void keyReleased() {
c = color(40);
}
@Morpholux
Copy link
Author

Example of render :

Sketch render example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment