2025年3月13日 星期四

12750202 week04

 作業1


//week04-1-atan2_dy-dx-cos-sin

void setup(){

  size(600,300);

}

void draw(){

  background(#C0FFEE); //粉青咖啡色

  ellipse(150,150,100,100);//大眼睛

 // ellipse(150+25,150,50,50);

  float dx=mouseX-150,dy=mouseY-150;

  float a=atan2(dy,dx);//算出角度

  ellipse(150+cos(a)*+25,150+sin(a)*25,50,50);

}

作業2

//week04-2-atan2-for-x-dx-dy-cos-sin

void setup(){
  size(600,300);
}
void draw(){
  background(#C0FFEE); //粉青咖啡色
  for(int x=150;x<=450;x+=300){//迴圈做出兩個
      ellipse(x,150,100,100);//大眼睛
   // ellipse(150+25,150,50,50);
     float dx=mouseX-x,dy=mouseY-150;
     float a=atan2(dy,dx);//算出角度
     ellipse(x+cos(a)*+25,150+sin(a)*25,50,50);
  }
}

 作業3

void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  //rotateY(radians(mouseX)); //上週的左右轉
  rotateX(radians(-mouseY)); //本週的上下轉
  box(200);
}

作業4



//week04-04-rotateZ
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  rotateZ(radians(mouseX)); 
  ellipse(0,0,100,150);
}
 作業5


//week04-5-robot-arm-pushMatrix-T-R-T-box-popMatrix
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(128);
  translate(width/2,height/2);
  pushMatrix();
    translate(0,100);
    box(50);//台座
  pushMatrix();
    translate(0,-25);
    rotateZ(radians(mouseX));
    translate(0,-50);
    box(10,100,10);
   popMatrix();
  popMatrix();
}
 

作業5a

//week04-05a-rotateZ-translate-box
void setup(){
  size(400,400,P3D);
}
void draw()
{
  background(128);
  translate(width/2,height/2); //移到畫面中心
  
    //以下2行 分別註解、排列組合觀察
    rotateZ(radians(frameCount)); //z軸旋轉
    translate(0,-50); //把下端 移到中心
    box(10,100,10); //可轉動的長條
  
}
 

作業5b


//week04-05b-translate-mouseX-mouseY-rotateZ-translate-box
void setup(){
  size(400,400,P3D);
}
void draw()
{
  background(128);
  //translate(width/2,height/2); //移到畫面中心
  
    translate(mouseX,mouseY); //加這行
    rotateZ(radians(frameCount)); //z軸旋轉
    translate(0,-50); //把下端 移到中心
    box(10,100,10); //可轉動的長條
  
}

作業6


//week04-06-push-translate-rotate-sphere-pop
void setup(){
  size(400,400,P3D);
}
void draw()
{
  background(128);
  pushMatrix();
    translate(mouseX,mouseY);
    rotateY(radians(frameCount));
    sphere(100);
   popMatrix();
}

作業7



//week04-07-sun-earth
void setup(){
  size(400,400,P3D);
}
void draw()
{
  background(128);
  translate(width/2,height/2);
  sphere(50);
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150,0);
    rotateY(radians(frameCount));
    sphere(30); //地球
   popMatrix();
}

作業8

//week04-08-sun-earth-moon
void setup(){
  size(400,400,P3D);
}
void draw()
{
  background(128);
  translate(width/2,height/2);
  sphere(50);//太陽
  rotateY(radians(frameCount));
  pushMatrix();
    translate(150,0);
    rotateY(radians(frameCount));
    sphere(30); //地球
   pushMatrix();
     translate(50,0);
     rotateY(radians(frameCount));
     sphere(10);//月球
    popMatrix();
   popMatrix();
}

作業9


//week04-09-earth-texture
//google:earth map texture 下載1張地球的圖片
//把圖檔拉到程式裏面
PImage img =loadImage("earth.jpg");
size(600,300);
image(img,0,0,600,300);

作業10


//week04-10-earth-createShape-setTexure-shape
//google:procssing sphere texture 可找到程式
size(400,400,P3D);
PShape earth=createShape(SPHERE,100);
PImage img =loadImage("earth.jpg");
earth.setTexture(img);
shape(earth)

作業11

//week04-11-earth-setTexture-translate-rotate
PShape earth;
void setup()
{
  size(400,400,P3D);
  earth=createShape(SPHERE,100);
  PImage img =loadImage("earth.jpg");
  earth.setTexture(img);
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(earth);
}
 作業12

//week04-12-moon-sexTexture-translate-rotate
PShape moon;
void setup()
{
  size(400,400,P3D);
  moon=createShape(SPHERE,100);
  PImage img =loadImage("moon.jpg");
  moon.setTexture(img);
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(moon);
}

作業13

//week04-13-sun-sexTexture-translate-rotate
PShape sun;
void setup()
{
  size(400,400,P3D);
  sun=createShape(SPHERE,100);
  PImage img =loadImage("sun.jpg");
  sun.setTexture(img);
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  shape(sun);
}
 作業14

//week04-14-sun-earth-moon-setTexture
PShape sun,earth,moon;
//樓下 剪貼自 week04-08 樓上是 week04-11,12,13
void setup(){
  size(400,400,P3D);
  moon=createShape(SPHERE,10);
  PImage img =loadImage("moon.jpg");
  moon.setTexture(img);
  
  earth=createShape(SPHERE,30);
  img =loadImage("earth.jpg");
  earth.setTexture(img);
  
  sun=createShape(SPHERE,50);
  img =loadImage("sun.jpg");
  sun.setTexture(img);
}
void draw()
{
  background(128);

  translate(width/2,height/2)







 


 











沒有留言:

張貼留言