Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PGraphics cube;
- int scale=120;
- void setup() {
- size(150, 200);
- noSmooth();
- }
- PGraphics drawCube(int size, color rgb){
- PGraphics temp=createGraphics(scale,scale+scale/3);
- temp.beginDraw();
- temp.stroke(0,0,0,0);
- temp.fill(rgb);
- temp.quad((size/2),0, //draw top of cube (top)(right)(bottom)(left)
- size,(size/3),
- (size/2),((size/3)*2),
- 0,(size/3));
- temp.fill(color(red(rgb)-20, //dim fill by 20
- green(rgb)-20,
- blue(rgb)-20),
- alpha(rgb));
- temp.quad(0,(size/3), //draw left of cube (top left)(top right)(bottom right)(bottom left)
- (size/2),((size/3)*2),
- (size/2),(size/3)*4,
- 0,size);
- temp.fill(color(red(rgb)-40, //dim fill by 20
- green(rgb)-40,
- blue(rgb)-40),
- alpha(rgb));
- temp.quad(size,(size/3), //draw right of cube (top right)(bottom right)(bottom left)(top left)
- size,size,
- (size/2),(size/3)*4,
- (size/2),((size/3)*2));
- temp.fill(rgb); //restore fill for storage of rgb in the PGraphics object
- temp.endDraw();
- return temp;
- }
- boolean keyp=false;
- void keyPressed(){
- if(key=='a'){
- keyp=true;
- }
- }
- void keyReleased(){
- if(key=='a'){
- keyp=false;
- }
- }
- void printCube(int x, int y){
- color temp=g.fillColor; //store current fill and stroke temporarily
- color stemp=g.strokeColor;
- stroke(0,0,0,0); //stroke transparent
- quad(x+(scale/2),y, //draw top of cube (top)(right)(bottom)(left)
- x+scale,y+(scale/3),
- x+(scale/2),y+((scale/3)*2),
- x,y+(scale/3));
- fill(color(red(g.fillColor)-20, //dim fill by 20
- green(g.fillColor)-20,
- blue(g.fillColor)-20),
- alpha(g.fillColor));
- quad(x,y+(scale/3), //draw left of cube (top left)(top right)(bottom right)(bottom left)
- x+(scale/2),y+((scale/3)*2),
- x+(scale/2),y+(scale/3)*4,
- x,y+scale);
- fill(color(red(g.fillColor)-20, //dim fill by 20
- green(g.fillColor)-20,
- blue(g.fillColor)-20),
- alpha(g.fillColor));
- quad(x+scale,y+(scale/3), //draw right of cube (top right)(bottom right)(bottom left)(top left)
- x+scale,y+scale,
- x+(scale/2),y+(scale/3)*4,
- x+(scale/2),y+((scale/3)*2));
- fill(temp); //restore fill
- stroke(stemp); //restore stroke
- }
- void draw(){
- background(200);
- fill(30,200,200);
- if(cube==null){cube=drawCube(scale,color(200,200,30));} //If cube doesn't exist, make it
- if(!keyp){ //If A button isn't pressed
- image(cube,9,30); //Print Cube using New Method
- }
- else{
- printCube(20,30); //Print cube using old method
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement