Created
May 14, 2019 10:25
-
-
Save ciaron/3073aa173f78ff1f93dd74183d554ce1 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
PShader kaleidoscope; | |
Rect[] rects; | |
boolean applyFilter; | |
boolean PAUSE=false; | |
float bg = 255; | |
float fg = 0; | |
float span=0.25; | |
int nelems=9; | |
float xoff = 0.0; | |
color randomcolor() { | |
color c=color(0,0,0); | |
float r = random(1); | |
if (r<0.333) c = color(255,0,0); | |
else if (r<0.666) c = color(127,255,0); | |
else if (r<0.999) c = color(0,0,255); | |
return c; | |
} | |
void genRects() { | |
rects=new Rect[nelems]; | |
for (int i=0; i<rects.length; i++) { | |
rects[i]= | |
new Rect(randomcolor(), | |
random(-span*width, span*width), random(-span*height, span*height), | |
random(100, 230), random(10, 230)); | |
} | |
} | |
void setup() { | |
size(1000, 1000, OPENGL); | |
smooth(8); | |
frameRate(60); | |
// get kaleidoscope.glsl here, and put in the sketch "data" folder: | |
//http://pastebin.com/CWX1xCiR | |
kaleidoscope=loadShader("kaleidoscope.glsl"); | |
kaleidoscope.set("sides", 6.0); | |
kaleidoscope.set("offset", 1200); | |
colorMode(RGB); //or HSB | |
genRects(); | |
fill(fg,32); | |
} | |
void draw() { | |
background(0); | |
translate(width/2, height/2); | |
rotateZ(radians(frameCount/2)); | |
translate(0, 0); | |
for (Rect rect : rects) { | |
rect.draw(); | |
} | |
if (applyFilter) filter(kaleidoscope); | |
if (frameCount %60 == 0) println(frameRate); | |
} | |
void mousePressed() { | |
applyFilter=!applyFilter; | |
} | |
class Rect { | |
color c; | |
float x, y, w, h; | |
int d; | |
Rect(color cc, float xx, float yy, float ww, float hh) { | |
c=cc; | |
x=xx; | |
y=yy; | |
w=ww; | |
h=hh; | |
d=1; | |
} | |
void draw() { | |
// fat colourful circles | |
strokeWeight(4); | |
stroke(fg); | |
fill(c); | |
if (x<200) { | |
rect(x,y,w,h); | |
} else { | |
ellipse(x,y,w,w); | |
} | |
} | |
} | |
// screenshot organizer | |
void keyPressed(){ | |
if (key == ' ') { | |
if (PAUSE) loop(); | |
else noLoop(); | |
PAUSE=!PAUSE; | |
} | |
if (key == 's' || key == 'S') { | |
java.util.Date dNow = new java.util.Date( ); | |
java.text.SimpleDateFormat ft = new java.text.SimpleDateFormat ("yyyy_MM_dd_hhmmss_S"); | |
saveFrame("/home/linstead/Dropbox/screenshots/"+this.getClass().getName()+"/"+this.getClass().getName()+"_"+ft.format(dNow)+ ".png"); | |
} | |
if (key == 'r' || key == 'R') { | |
genRects(); | |
} | |
if (key == 'c' || key == 'C') { | |
for (Rect rect : rects) { | |
rect.c = randomcolor(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment