Skip to content

Instantly share code, notes, and snippets.

@sasamijp
Created April 14, 2014 07:12
Show Gist options
  • Save sasamijp/10623373 to your computer and use it in GitHub Desktop.
Save sasamijp/10623373 to your computer and use it in GitHub Desktop.
回る箱
RollingBox box3d;
float counter;
void setup(){
size(500, 800, P3D);
box3d = new RollingBox();
counter = 0;
frameRate(60);
}
void draw(){
background(0);
box3d.rotate3d(width/2,height/2,counter);
counter += 1;
}
class RollingBox {
float angle = 0;
color c = color(0,0,0);
float boxSize = 100;
int plus;
RollingBox () {
angle=0;
boxSize = 300;
plus = 0;
}
void rotate3d(int xpos,int ypos, float counter){
translate(xpos, ypos, 0);
rotateY(angle);
if((counter % 2) == 0){
boxSize -= 3;
}else{
boxSize += 3;
}
if((counter % 30) == 0){
c = randomColor();
}
box(boxSize);
fill(c);
angle += 0.03;
if(angle == 360){
angle = 0;
}
}
private color randomColor(){
color c = color(random(255),random(255),random(255));
return c;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment