/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.xXjD9KSIUzx/rev.1380
*
* authors:
* alexsmith540
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// Pressing Control-R will render this sketch.
int i = 0;
float originx, originy, q1x, q1y, q2x,q2y, q3x,q3y, q4x,q4y, q4x1,q4x1;
float q1dir,q2dir,q3dir,q4dir,origindir, colordir = 1;
float r,g,b = 0;
void setup() { // this is run once.
// set the background color
background(255);
// canvas size (Variable aren't evaluated. Integers only, please.)
size(500, 500, P3D);
originx = random(width/2-100,width/2+100);
originy = random(height/2-100,height/2+100);
q1x = random(0,width/2);
q1y = random(0,height/2);
q2x = random(width/2,width);
q2y = random(0,height/2);
q3x = random(0,width/2);
q3y = random(height/2,height);
q4x = random(width/2,width);
q4y = random(height/2,height);
q4x1 = random(q4x,originx);
q4y1 = random(q4y,originy);
// smooth edges
smooth();
// limit the number of frames per second
frameRate(30);
// set the width of the line.
stroke(color(r,g,b));
}
void draw() { // this is run repeatedly.
noFill();
strokeWeight(0.1);
//stroke(0);
beginShape();
curveVertex(originx,originy);
curveVertex(originx,originy);
curveVertex(q1x,q1y);
curveVertex(q2x,q2y);
curveVertex(q3x,q3y);
curveVertex(q4x,q4y);
curveVertex(q4x1,q4y1);
curveVertex(originx,originy);
curveVertex(originx,originy);
endShape();
reCalc();
}
void reCalc(){
q1dir = q1x < width && q1y < height ? (q1x > 0 && q1y > 0 ? q1dir : 1) : (q1dir == 1 ? 0 : 1);
q2dir = q2x < width && q2y < height ? (q2x > 0 && q2y > 0 ? q2dir : 1) : (q2dir == 1 ? 0 : 1);
q3dir = q3x < width && q3y < height ? (q3x > 0 && q3y > 0 ? q3dir : 1) : (q3dir == 1 ? 0 : 1);
q4dir = q4x < width && q4y < height ? (q4x > 0 && q4y > 0 ? q4dir : 1) : (q4dir == 1 ? 0 : 1);
origindir = originx < width && originy < height ? (originx > 0 && originy > 0 ? origindir : 1) : (origindir == 1 ? 0 : 1);
//random makes it a little rougher...
q1x += q1dir == 1 ? random(0,1): random(0,-1);
q1y += q1dir == 1 ? random(0,1): random(0,-1);
q2x += q2dir == 1 ? random(0,1): random(0,-1);
q2y += q2dir == 1 ? random(0,1): random(0,-1);
q3x += q3dir == 1 ? random(0,1): random(0,-1);
q3y += q3dir == 1 ? random(0,1): random(0,-1);
q4x += q4dir == 1 ? random(0,1): random(0,-1);
q4y += q4dir == 1 ? random(0,1): random(0,-1);
originx += origindir == 1 ? random(0,1): random(0,-1);
originy += origindir == 1 ? random(0,1): random(0,-1);
//change colors?
float m = millis();
if(m % m == 0){
colordir = r == 0 ? (colordir == 0 ? 1 :colordir) : (r >= 255 ? 0 : colordir);
r += colordir == 1 ? 1 : -1;
//g += colordir == 1 ? 1 : -1;
//b += colordir == 1 ? 1 : -1;
stroke(color(r,g,b));
}
}