2023年12月28日 星期四

WW-Week15_期末作業製作

cake_1221_buttom

PImage imgCake1;

ArrayList<PVector> pt;
void setup(){
  size(1920,1080,P3D);
  imgCake1= loadImage("cakeMaterial.png");
  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);//右邊的操作台
  
  textSize(35);///////////////////////////////////放大字體
  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(240,150,150); rect(1590,900,200,100,20);//完成了!!
  fill(245,200,200); rect(1590,900,190,90,20);//完成了!!
  //if(mousePressed){//如果mouse有按下去
  //  line(mouseX,mouseY,pmouseX,pmouseY);
  //}
  
  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迴圈,會得到小的資料結構
    ellipse( p.x, p.y, 20, 20);

  }
}
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;
void mouseDragged(){
  if(mouseButton==CENTER) middleRotate -= (mouseX-pmouseX)*0.5;
}
void mousePressed(){
  pt.add(new PVector(mouseX,mouseY));//當滑鼠點下去add一個new點
}

沒有留言:

張貼留言