Emergence Kaleidoscope version beta1.0
From Physical Programming
/*The Final version of the Emergence Kaleidoscope Project.
- Press 1 for 90-45-45degree reflection
- Press 2 for 60-60-60degree reflection
- Press 3 for 30-60-90degree reflection
- Press 4 for 2 mirrors, 30degree reflection
- move the mouse to draw with ellipses
- Click mouse to see how those ellipses move
- And save your image with 'S' key
RGB of the ellipses change according to the coordinate of the mouse
Also found something similar here[1]
++This is an updated version for full screen.
++Thank you to Scott for making the code much shorter, I get it now, Thanks ^^ Link to the edited/shorter version here. [[2]]
ENJOY :D */
float x, y;
int i, j;
int a, z;
int checkPress = 0;
void setup(){
frameRate(15);
size(screen.width, screen.height);
background(0);
noStroke();
smooth();
//Import an image for your cover with these codes
//PImage img;
//img = loadImage("cover.jpg");
//image(img, screen.width,/2-250, screen.height/2-250);
}
void draw(){
translate(screen.width/2, screen.height/2);
if (mousePressed){
if ((keyPressed == true) && (key == '1')) {
checkPress = 1;
}
if (checkPress == 1){
background(0);
x=-300;
y=-300;
gridA(true);
}
if ((keyPressed == true) && (key == '2')) {
checkPress = 2;
}
if (checkPress == 2){
background(0);
x=-490;
y=-386.6;
gridB(x, true);
x=-415;
y=-343.3;
gridB(x, true);
}
if ((keyPressed == true) && (key == '3')) {
checkPress = 3;
}
if (checkPress == 3){
background(0);
x=-290;
y=-310;
gridC(x, true);
x=-330;
y=-350;
gridC(x, true);
}
if ((keyPressed == true) && (key == '4')){
checkPress = 4;
}
if (checkPress == 4){
background(0);
x=(-30/tan(PI/12))-230;
y=(-30/tan(PI/12))-250;
gridD(x, true);
x=(-50/tan(PI/12))-230;
y=(-50/tan(PI/12))-250;
gridD(x, true);
}
}
else {
if ((keyPressed == true) && (key == '1')) {
checkPress = 1;
background(0);
}
if (checkPress == 1){
x=-300;
y=-300;
gridA(false);
}
if ((keyPressed == true) && (key == '2')) {
checkPress = 2;
background(0);
}
if (checkPress == 2){
x=-490;
y=-386.6;
gridB(x, false);
x=-415;
y=-343.3;
gridB(x, false);
}
if ((keyPressed == true) && (key == '3')) {
checkPress = 3;
background(0);
}
if (checkPress == 3){
x=-290;
y=-310;
gridC(x, false);
x=-330;
y=-350;
gridC(x, false);
}
if ((keyPressed == true) && (key == '4')){
checkPress = 4;
background(0);
}
if (checkPress == 4){
x=(-30/tan(PI/12))-230;
y=(-30/tan(PI/12))-250;
gridD(x, false);
x=(-50/tan(PI/12))-230;
y=(-50/tan(PI/12))-250;
gridD(x, false);
}
}
if ((keyPressed == true) && (key == 's'))
save ("kaleidoscope.tiff");
}
void gridA(boolean checkalpha){
for (a=0;a<5;a++){
y+=100;
for (z=0;z<5;z++){
x+=100;
translate(x,y);
for (j=0;j<4;j++){
noFill();
if (checkalpha == false)
drawCell(0, 0, -50, 50, 50, 50, 20, 30, 30, 30);
else
drawCell(0, 0, -50, 50, 50, 50, 255, 255, 255, 255);
rotate(PI/2);
}
translate(-x,-y);
}
x=-300;
}
}
void gridB(float origin, boolean checkalpha){
for (a=0;a<7;a++){
y+=86.6;
for (z=0;z<5;z++){
x+=150;
translate(x,y);
for (j=0;j<6;j++){
noFill();
if (checkalpha == false)
drawCell(0, 0, -25, (sqrt(sq(50)-sq(25))), 25, (sqrt(sq(50)-sq(25))), 20, 30, 30, 30);
else
drawCell(0, 0, -25, (sqrt(sq(50)-sq(25))), 25, (sqrt(sq(50)-sq(25))), 255, 255, 255, 255);
rotate(PI/3);
}
translate(-x,-y);
}
x=origin;
}
}
void gridC(float origin, boolean checkalpha){
for (a=0;a<7;a++){
y+=80;
for (z=0;z<7;z++){
x+=80;
translate(x,y);
for (j=0;j<4;j++){
noFill();
if (checkalpha == false)
drawCell(0, 0, 0, 40, -40, 0, 20, 30, 30, 30);
else
drawCell(0, 0, 0, 40, -40, 0, 255, 255, 255, 255);
rotate(PI/2);
}
translate(-x,-y);
}
x=origin;
}
}
void gridD(float origin, boolean checkalpha){
for (a=0;a<4;a++){
y+=(40/tan(PI/12));
for (z=0;z<4;z++){
x+=(40/tan(PI/12));
translate(x, y);
for (j=0;j<12;j++){
noFill();
if (checkalpha == false)
drawCell(0, 0,-20, 20/(tan(PI/12)), 20, 20/(tan(PI/12)), 20, 30, 30, 30);
else
drawCell(0, 0,-20, 20/(tan(PI/12)), 20, 20/(tan(PI/12)), 255, 255, 255, 255);
rotate(PI/6);
}
translate(-x,-y);
}
x=origin;
}
}
void drawCell(float x1, float y1, float x2, float y2, float x3, float y3, float A1, float A2, float A3, float A4){
triangle (x1, y1, x2, y2, x3, y3);
int r = int(mouseX);
int g = int(mouseY);
int b = int(abs(mouseX-mouseY));
fill(abs(r-200), abs(g-50), abs(b-100),A1);
ellipse (mouseX/10, mouseY/10, 7, 7);
ellipse (-mouseX/10, mouseY/10, 7, 7);
fill(abs(r-100), abs(g-100), abs(b-200), A2);
ellipse (mouseY/20, mouseX/20, 5, 5);
ellipse (-mouseY/20, mouseX/20, 5, 5);
fill(abs(r-50), abs(g-200), abs(b-50), A3);
ellipse (mouseX/20, mouseX/20, 3, 3);
ellipse (-mouseX/20, mouseX/20, 3, 3);
fill(r, g, b, A4);
ellipse (mouseY/20, mouseY/20, 3, 3);
ellipse (-mouseY/20, mouseY/20, 3, 3);
}

