Created
April 26, 2020 10:10
-
-
Save kenoir/247f8ffb47d953b0349dc1ee6fafd693 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
float x,y,z,w,h,rotationX,rotationY; | |
int step; | |
void setup() { | |
size(800,800,P3D); | |
x = width/2; | |
y = height/2; | |
z = -100; | |
step = 15; | |
w = width; | |
h = height; | |
} | |
void draw() { | |
translate(x,y,z); | |
rotationY = (mouseX / w) * PI * -2; | |
rotationX = (mouseY / h) * PI * -2; | |
if (mousePressed) { | |
if(mouseButton == LEFT) { | |
z+=10; | |
} else if(mouseButton == RIGHT) { | |
z-=10; | |
} | |
} | |
rotateX(rotationX); | |
rotateY(rotationY); | |
background(255); | |
rainbowBlock(0,0,0, step); | |
} | |
void rainbowBlock(float bx, float by, float bz, int step) { | |
pushMatrix(); | |
translate(bx, by-7, bz); | |
int translate = ((255 / step) + 1) * -step; | |
for(int r = 0; r <= 255; r+=step) { | |
for(int g = 0; g <= 255; g+=step) { | |
for(int b = 0; b <= 255; b+=step) { | |
fill(r,g,b); | |
box(step, step, step); | |
translate(0, step); | |
} | |
translate(step, translate); | |
} | |
translate(translate, 0, step); | |
} | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment