try pressing '1', '2' or '3'
/**
* based on the example "TexturedCube"
* by Dave Bollinger.
*
* just added some animated texture
*
* Drag mouse to rotate cube.
*/
PGraphics[] ebene = new PGraphics[6];
float rotx = PI/4;
float roty = PI/4;
float rt = 0;
float sk = 0;
PShape house;
void setup()
{
size(600, 600, P3D);
for(int i =0; i<6; i++){
ebene[i] = createGraphics( 400, 400, P2D );
ebene[i].background(0);
}
textureMode(NORMALIZED);
shapeMode (CENTER);
house = loadShape( "House.svg" );
house.disableStyle();
smooth();
}
void draw()
{
for(int i =0; i<6; i++){ //draw texture-layers
draw_ebene(i);
}
rt += 0.8;
sk += 0.02;
background(0);
translate(width/2.0, height/2.0, -100);
rotateX(rotx);
rotateY(roty);
scale(150);
TexturedCube(); //draw a cube
if(!mousePressed){
roty+=0.01;
rotx+=0.02;
}
}
void TexturedCube() {
beginShape(QUADS);
// +Z "front" face
texture(ebene[0]);
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);
endShape();
beginShape(QUADS);
// -Z "back" face
texture(ebene[1]);
vertex( 1, -1, -1, 0, 0);
vertex(-1, -1, -1, 1, 0);
vertex(-1, 1, -1, 1, 1);
vertex( 1, 1, -1, 0, 1);
endShape();
beginShape(QUADS);
// +Y "bottom" face
texture(ebene[2]);
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();
beginShape(QUADS);
// -Y "top" face
texture(ebene[3]);
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);
endShape();
beginShape(QUADS);
// +X "right" face
texture(ebene[4]);
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);
endShape();
beginShape(QUADS);
// -X "left" face
texture(ebene[5]);
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 1, 1, 0);
vertex(-1, 1, 1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();
}
void mouseDragged() { //rotation of cube
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}
void draw_ebene(int i){
ebene[i].beginDraw();
ebene[i].colorMode(HSB, 60);
ebene[i].fill(10*i+abs(20-(frameCount)%40),100, 100, 20);
ebene[i].translate( width/(i+2), height/(i/2+2) );
ebene[i].rotate( rt/(i+1) );
ebene[i].scale( sk );
ebene[i].shape(house , 0,0,width/4,height/4 );
ebene[i].endDraw();
}
/**
* based on the example "TexturedCube"
* by Dave Bollinger.
*
* just added some animated texture
*
* Drag mouse to rotate cube.
* pressing '1', '2' or '3' will restart in little different modes
*/
PGraphics[] ebene = new PGraphics[6];
float rotx = PI/4;
float roty = PI/4;
float rt = 0;
float sk = 0.1;
PShape house;
int a=1;
int schalter = 1;
int mode = 3;
float shift_x = 0;
float shift_y = 0;
void setup()
{
size(600, 600, P3D);
for(int i =0; i<6; i++){
ebene[i] = createGraphics( 400, 400, P2D );
ebene[i].background(0);
}
textureMode(NORMALIZED);
shapeMode (CENTER);
house = loadShape( "House.svg" );
house.disableStyle();
house.translate(20, 20);
smooth();
}
void draw()
{
for(int i =0; i<6; i++){ //draw texture-layers
draw_ebene(i);
}
if(rt>200){
sk = 0;
rt=0.1;
a++;
schalter = schalter*(-1);
}
else{
rt += 0.8;
sk += 0.03;
}
background(0);
translate(width/2.0, height/2.0, -100);
rotateX(rotx);
rotateY(roty);
scale(150);
TexturedCube(); //draw a cube
if(!mousePressed){
roty+=0.01;
rotx+=0.02;
}
}
void TexturedCube() {
beginShape(QUADS);
// +Z "front" face
texture(ebene[0]);
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);
endShape();
beginShape(QUADS);
// -Z "back" face
texture(ebene[1]);
vertex( 1, -1, -1, 0, 0);
vertex(-1, -1, -1, 1, 0);
vertex(-1, 1, -1, 1, 1);
vertex( 1, 1, -1, 0, 1);
endShape();
beginShape(QUADS);
// +Y "bottom" face
texture(ebene[2]);
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();
beginShape(QUADS);
// -Y "top" face
texture(ebene[3]);
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);
endShape();
beginShape(QUADS);
// +X "right" face
texture(ebene[4]);
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);
endShape();
beginShape(QUADS);
// -X "left" face
texture(ebene[5]);
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 1, 1, 0);
vertex(-1, 1, 1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();
}
void mouseDragged() { //rotation of cube
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}
void keyPressed(){ // r - reset
switch(key){
case '1':
schalter = 1;
for(int i =0; i<6; i++){
ebene[i] = createGraphics( 400, 400, P2D );
ebene[i].background(0);
}
rt = 0;
sk = 0;
if(mode==3){
house.translate(-30, -30);
}
mode = 1;
break;
case '2':
for(int i = 0; i < 6; i++){
ebene[i] = createGraphics( 400, 400, P2D );
ebene[i].background(0);
}
rt = 0;
sk = 0;
if(mode==3){
house.translate(-30, -30);
}
mode = 2;
break;
case '3':
for(int i = 0; i < 6; i++){
ebene[i] = createGraphics( 400, 400, P2D );
ebene[i].background(0);
}
rt = 0;
sk = 0;
if(mode!=3){
house.translate(30, 30);
}
mode = 3;
break;
}
}
void draw_ebene(int i){
ebene[i].beginDraw();
ebene[i].colorMode(HSB, 60);
switch(mode){
case 1:
if(schalter == 1){
ebene[i].fill((10*i+abs(20-(frameCount/2)%40))%60,100, 100, 10);
ebene[i].noStroke();
}
else{
ebene[i].noFill();
ebene[i].stroke(0, 50);
}
break;
case 2:
ebene[i].noFill();
ebene[i].stroke((10*i+abs(20-(frameCount/2)%40))%60,100, 100, 100);
break;
case 3:
ebene[i].fill(10*i+abs(20-(frameCount)%40),100, 100, 20);
break;
}
ebene[i].translate( width/(i+2)+shift_x, height/(i/2+2)+shift_y );
ebene[i].rotate( rt/(i+2) );
ebene[i].scale( sk );
ebene[i].shape(house , 0,0,width/4,height/4 );
ebene[i].endDraw();
}
just added some code to the example-sketch of Dave Bollinger.
you may drag the mouse to rotate the cube.
You can restart the sketch by pressing '1', '2' or '3'.