Created
October 11, 2016 08:59
-
-
Save pouretrebelle/4875b93350f050e8d68a2f7eb43efcfa to your computer and use it in GitHub Desktop.
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
// Painting things | |
//================ | |
int screenWidth = 1800; | |
int screenHeight = 1800; | |
int predraw = 1000; // frames per paint | |
Dot[] dots = new Dot[10]; // amount of paints | |
int iteration = 1; // name of saved png | |
boolean saving = false; // save to png | |
float framesPerSec = 1; // frame rate | |
int sizeMin = 50; | |
int sizeMax = 150; | |
float rotateMin = 0.01; | |
float rotateMax = 0.06; | |
float speedMin = 2; | |
float speedMax = 6; | |
float shadowMag = 10; | |
int hueMain = 300; | |
int hueVariance = 50; | |
int hueInverse = 160; | |
void settings() { | |
size(screenWidth, screenHeight); | |
} | |
void setup() { | |
background(255); | |
noStroke(); | |
frameRate(framesPerSec); | |
colorMode(HSB, 360, 100, 100, 1); | |
} | |
void draw() { | |
// print the frame rate and iteration number | |
println(iteration + " " + frameRate); | |
// wipe the background | |
background(360); | |
// generate dots | |
makeDots(); | |
// draw [predraw] frames | |
int tempPredraw = predraw; | |
while (tempPredraw > 0) { | |
for (int i = 0; i < dots.length; i ++ ) { | |
dots[i].draw(); | |
} | |
tempPredraw--; | |
} | |
// save piece as a png | |
if (saving) { | |
save("art" + iteration + ".png"); | |
} | |
iteration++; | |
} | |
void makeDots() { | |
for (int i = 0; i < dots.length; i ++ ) { | |
dots[i] = new Dot(int(random(screenWidth)), int(random(screenHeight))); | |
} | |
} | |
class Dot { | |
PVector pos; | |
PVector vel; | |
PVector shadow; | |
color c; | |
float rotate; | |
float size; | |
float speed; | |
boolean righting; | |
Dot(int x, int y) { | |
// make position vector based on x,y coordinates | |
pos = new PVector(x, y); | |
// pick a random color | |
float hue = hueMain+random(hueVariance); | |
float sat = random(30, 50); | |
float bri = random(90, 100); | |
c = color(hue, sat, bri); | |
// pick a random size | |
size = random(sizeMin, sizeMax); | |
// pick random rotation strength | |
rotate = random(rotateMin, rotateMax); | |
// pick a random speed or movement | |
speed = random(speedMin, speedMax); | |
// create random velocity vector and set its speed | |
vel = PVector.random2D().setMag(speed); | |
// create random shadow vector and set its magnitude | |
shadow = PVector.random2D().setMag(shadowMag); | |
// randomly chose left/right leaning | |
righting = (Math.random() < 0.5); | |
} | |
void update() { | |
// change direction if it gets too big or too small | |
if (size > sizeMax || size < sizeMin) { | |
righting = !righting; | |
} | |
// rotate left or right based on righting | |
if (righting) { | |
vel.rotate(rotate); | |
size++; | |
} else { | |
vel.rotate(-rotate); | |
size--; | |
} | |
// add the velocity to the vector | |
pos.add(vel); | |
// protect from going off screen | |
if (pos.x > screenWidth+size) { | |
pos.x = -size/2; | |
} | |
if (pos.x < -size) { | |
pos.x = screenWidth+size/2; | |
} | |
if (pos.y > screenHeight+size) { | |
pos.y = -size/2; | |
} | |
if (pos.y < -size) { | |
pos.y = screenHeight+size/2; | |
} | |
} | |
void render() { | |
// make another coloured ellipse under the main one | |
fill(color(hue(c)-hueMain+hueInverse, saturation(c), brightness(c))); | |
ellipse(pos.x+shadow.x, pos.y+shadow.y, size, size); | |
fill(c); | |
ellipse(pos.x, pos.y, size, size); | |
} | |
void draw() { | |
update(); | |
render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment