Last active
December 22, 2015 03:18
-
-
Save julioterra/6409228 to your computer and use it in GitHub Desktop.
This is the base sketch for the Spacebrew workshop at NYC-CHI event on 9/5.
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
/** | |
* Rainbow. | |
* Click the mouse anywhere on the sketch to activate the rainbow animation. | |
* | |
*/ | |
int barWidth = 20; | |
int barCurrent = 0; | |
int barTotal = 0; | |
boolean drawingRainbow = false; | |
void setup() | |
{ | |
size(640, 360); // create window | |
frameRate(20); // set framerate | |
background(0); // draw a black background | |
colorMode(HSB, width, height, height); // set color mode to Hue/Saturation/Brightness | |
noStroke(); // turn off stroke | |
barTotal = width / barWidth; // calculate total number of bars that fit on window | |
} | |
void draw() { | |
// draw rainbow when flag set to true | |
if (drawingRainbow == true) { | |
// determine the X location of the current bar | |
int drawBarXpos = barCurrent * barWidth; | |
// step 1: draw rainbow bars | |
if (barCurrent < barTotal ) { | |
fill(drawBarXpos, height, height); // set fill color | |
rect(drawBarXpos, 0, barWidth, height); // draw bar at appropriate position | |
barCurrent += 1; // increment the number of the current bar | |
} | |
// step 2: finish animation | |
else { | |
drawingRainbow = false; // set drawing flag to false | |
background(0); // set background to black | |
} | |
} | |
} | |
void mousePressed() { | |
barCurrent = 0; // start drawing at beginning | |
drawingRainbow = true; // set draw flag to true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment