Last active
May 10, 2018 03:53
-
-
Save Morpholux/55d669d423c0557d51c54e9049bd6950 to your computer and use it in GitHub Desktop.
Example of a simple drawing machine
This file contains 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
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of render :