/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.n$ZB7B1F$EV/rev.939
*
* authors:
* frederic.vernier
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
PImage bg, pacman;
int i = 0;
float ab = PI/8;
float s = 0.8;
float ds = 0.005;
float da = 0.05;
float x = 0;
float dx = 5;
void setup() { // this is run once.
// set the background color
background(255);
// canvas size (Variable aren't evaluated. Integers only, please.)
size(300, 300);
// smooth edges
smooth();
bg = createImage(width, height, RGB);
bg.loadPixels();
for (int j = 0; j < bg.height; j++) {
for (int i = 0; i < bg.width; i++) {
float dj = 1*bg.height/3-j;
bg.pixels[j*bg.width+i] = color((0.5+0.5*abs(dj)/height)*noise(i/10.0,dj*dj/500.0)*164, (0.5+0.5*abs(dj)/height)*64, 0);
}
}
bg.updatePixels();
// Pressing Control-R will render this sketch.
// limit the number of frames per second
frameRate(30);
//noLoop();
}
void draw() {
if (ab>=PI/4 || ab<=PI/16) da = da*-1;
ab = ab+da;
if (s>=1.0 || s<=0.6) ds = ds*-1;
s = s+ds;
x = x+dx;
background(0, 64, 64);
image(bg,x%width,0);
image(bg,x%width-width,0);
fill(255);
for (int i=+x%30; i<width/2; i+=40)
ellipse(i, 2*height/3, 20, 20);
loadPixels();
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
float d = dist(i,j, width/2, height/2);
float dl = dist(i,j, width/4, height/4);
float d0 = dist(i,j, 4*width/7, 2*height/7);
float d1 = dist(i,j, 4*width/7-10, 2*height/7-10);
float d2 = dist(i,j, 4*width/7-10+ab*4, 2*height/7+10-ab*8);
float a = atan2(j-2*height/3, i-2*width/3);
float a2 = atan2(j-8*height/12, i-7*width/12);
if (d<width/3 && a>ab-PI && a<PI-ab/3 && (d0>20 || j+(i-4*width/7)/2<2*height/7-10-ab*10))
pixels[j*width+i] = color(s*(255-dl/2), s*(255-dl/2), 0);
else if (d<width/3 && a2>ab+0.1-PI && a2<PI-ab/3-0.1 && (d0>20 || j+(i-4*width/7)/2<2*height/7-10-ab*10))
pixels[j*width+i] = color((0.5+ab/3)*(192-dl/2), (0.5+ab/3)*(96-dl/2), 0);
else if (d2<=10)
pixels[j*width+i] = color(0, 128-d2*3, 128-d2*3);
else if (d0<=20)
pixels[j*width+i] = color(255-d1*3, 255-d1*3, 255-d1*3);
}
}
updatePixels();
}