Skip to content

Instantly share code, notes, and snippets.

@sidgabriel
Created February 14, 2012 01:34
Show Gist options
  • Save sidgabriel/1822347 to your computer and use it in GitHub Desktop.
Save sidgabriel/1822347 to your computer and use it in GitHub Desktop.
2D GRAPHICS LIBRARY, 3D LIGHTING, DEPTH OF FIELD
//open code by sid gabriel, no lic disclosed run it in the processing ide http://processing.org/
//working demo posted here: http://sidhubbard.com/2d-graphics-li…depth-of-field/
int counter = 1;
int countthresh = 17;
boolean videg = true;
color backc = color(8,16,96);
void setup() {
size(777, 333);
rectMode(CENTER_DIAMETER);
//frameRate(96);
//smooth();
}
float del= random(TWO_PI);
float spin = 0.0;
float movementn = 90.0;
boolean leezo = true;
boolean backr = false;
void draw() {
if (spin > 1){
if(backr){
background(backc);
}}else{
background(backc);
} spin += 0.01;
float ang=PI;
float size = 25.0;
float gam = 197.7;
tint(255, 96);
for (int n=1; n<(32); n++) {
n=n*counter;
pushMatrix();
translate(width/2+sin(ang)*(width/2)*((float)n/128), height/1.61803399+cos(ang)*(height/1.61803399)*((float)n/128)+(((height/1.61803399)-height)/1.61803399+cos(ang))*((float)n/10248));
rotate(ang+spin);
if (videg) {
if (leezo) {
strokeWeight(abs(2.1-(map(n, 1, 64, 0.3, 3.3)))+radians(n));
stroke(abs(gam-n+(map(n, 1, 64, 1, 255))),
(gam-n+(map(n, 1, 64, 1, 255))),
(gam-n+(map(n, 1, 64, 1, 255))),
(32+(map(n, 1, 64, 36, 200))));
beginShape(POINTS);
}
else {
noStroke();
beginShape(POINTS);//TRIANGLE_STRIP);//QUAD_STRIP);//TRIANGLE_FAN);//POINTS);//);
tint(255-(map(n, 1, 512, 1, 255)), 96-(map(n, 1, 512, 1, 128)));//255-n*1.0,n*1.0-96);
}
vertex(width/8*(1.0f-0.5*(float)n/128), height/8*(1.0f-0.5*(float)n/128), width, height);//thisone2.width, thisone2.height);
vertex(width/8*(1.0f-0.5*(float)n/128), 0, width, 0);//thisone.width
vertex(0, 0);
vertex(0, 0);
vertex(0, height/20*(1.0f-0.5*(float)n/128), 0, height);
vertex(width/8*(1.0f-0.5*(float)n/128), 0, width, 0);
vertex(0, height/8*(1.0f-0.5*(float)n/128), height, 0);
vertex(width/8*(1.0f-0.5*(float)n/128), height/8*(1.0f-0.5*(float)n/128), 0, 0);
vertex(0, height/8*(1.0f-0.5*(float)n/128), 0, height);
vertex(0, 0, 0, 0);
endShape(CLOSE);
}
strokeWeight(abs(2.3-(map(n, 1, 64,0.3, 3.3)))+radians(n));
stroke(gam-n+(map(n, 1, 64,1, 255)),
gam-n+(map(n, 1, 64,1, 255)),
gam-n+(map(n, 1, 64,1, 255)),
64-n+(map(n, 1, 512, 36, 200)));
beginShape(POINTS);
// vertex(n, n*ang);
// vertex(ang/n, -n);
vertex(0, height/6*(1.0f-0.5*(float)n/128));
// vertex( 0, height);
// vertex(width/6*(1.0f-0.5*(float)n/128), 0);
// vertex(height/6*(1.0f-0.5*(float)n/128), 0);
// vertex(width, height);
// vertex(width/6*(1.0f-0.5*(float)n/128), 0);
// //vertex( width, 0);
// vertex(ang*n, n*3);
// vertex(n/ang, ang*n);
// vertex(n, n*3);
// vertex(n/ang, n);
// vertex( n*3, ang*n);
// vertex(n/ang, -n);
// vertex(n, -n);
// vertex(-n, ang*n);
// vertex(-n, n/ang);
endShape(CLOSE);
popMatrix();
if (videg) {
float movementn = 0.03179 * (random(.01111, 1.0111111) * 0.07693 );
del += abs(movementn);
}
else {
float movementn = 0.0309 * (random(.01111, 1.011111) * 0.3963);
del += abs(movementn);
}
ang += del;
n=n/counter;
}
if (counter > countthresh) {
counter = 0;
}
if (counter < countthresh) {
counter = counter+1;
}
if(backr){
//background(0);
}else{fill(0, 1);
rect(0, 0, width*2, height*2);
fill(1, 2);
rect(0, 0, width*2, height*2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment