(另外按鈕上面印文字,可以用貼圖)
cake_1228_buttom
目前可以利用陣列在平面印上圓球
PImage imgCake1; PImage ballImg; PShape ball; ArrayList<PVector> pt; void setup(){ size(1920,1080,P3D); imgCake1= loadImage("cakeMaterial.png"); ballImg = loadImage("cakeMaterial2.jpg"); noStroke(); ball = createShape(SPHERE, 30); ball.setTexture(ballImg); noStroke(); pt = new ArrayList<PVector>(); } void draw(){ background(#D8E3FF); directionalLight(50, 50, 50, 0.5, 1,1);///直射光 ambientLight( 255, 255, 255, 500, 500, 1000);//環境光 //fill(165,163,245,80); rect(1550,50,300,800,50);//右邊的操作台 //fill(165,163,245,100); rect(50,50,450,150,20);//Title1 //fill(220,219,252,100); rect(50,50,430,130,20);//Title2 //fill(0);textSize(68);//文字 //text("Hello", 1590, 900); int end = 0; if (mousePressed && (mouseButton == LEFT) && (mouseX>=1590) && (mouseX<=1790) && (mouseY>=900)&&(mouseY<=1000)) { fill(240,150,150); end=1;///跳下一個畫面 } else { fill(245,200,200); } rect(1590,900,200,100,20);//完成了!! pushMatrix();/////////////////////////////////地板 translate(0, 0,-130); fill(237,204,132); rect(-200,600,2300,600); popMatrix(); pushMatrix();///////////////////////////////////plan translate(width/2, height/1.475); rotateX(45); rotateZ(radians(middleRotate));//jsyeh stroke(0); fill(240,240,240); drawCylinder(80,300,20); popMatrix(); pushMatrix();/////////////////////////////Cake1 translate(width/2, height/1.77);///移到想放的位置 rotateX(45); rotateZ(radians(middleRotate));//jsyeh stroke(0); texture(imgCake1); drawCylinder(40, 230,180); popMatrix(); pushMatrix();/////////////////////////////Cake2 translate(width/2, height/2.65); rotateX(45); rotateZ(radians(middleRotate));//jsyeh stroke(0); texture(imgCake1); drawCylinder(40,200,140); popMatrix(); for (PVector p: pt){///特殊的for迴圈,會得到小的資料結1111 //ellipse( p.x, p.y, 50, 50); // translate( 300, 300,150); //sphere(30); shape(ball, p.x, p.y); } } void drawCylinder(int sides, float r, float h) {///畫Cylinder float angle = 2 * PI / sides; float halfHeight = h / 2; beginShape(TRIANGLE_FAN);////////////////////畫頂面 if (h==20){ fill(#FFFFFF); }else { texture(imgCake1); } for (int i = 0; i < sides; i++) { float x = cos( i * angle ) * r; float y = sin( i * angle ) * r; vertex( x, y, halfHeight ); } endShape(); beginShape(TRIANGLE_STRIP); if (h==20){ fill(#FFFFFF); }else { texture(imgCake1); } for (int i = 0; i < sides + 1; i++) { float x = cos( i * angle ) * r; float y = sin( i * angle ) * r; vertex( x, y, halfHeight); vertex( x, y, -halfHeight); } endShape(); } float middleRotate=0; PVector ans = null;//空指標 void mouseDragged(){ if(mouseButton==CENTER) middleRotate -= (mouseX-pmouseX)*0.5; } void mousePressed(){ if(mouseButton==LEFT)pt.add(new PVector(mouseX,mouseY));//當滑鼠點下去add一個new點 }
上面部分的蛋糕利用按鈕加貼圖可改變蛋糕頂面得圖片,側邊有加奶油的選項,之後或許可以加顏色
沒有留言:
張貼留言