2024年10月7日 星期一

Week05 阿米諾斯~哈基米

1.第一節課程式碼

//week05_01_cwa_typhoon_images
//存檔後,ctrl-k開檔案總管,看data目錄裡,一堆圖檔
PImage img = loadImage("TWI_IR1_CR_800-2024-10-02-08-00.jpg");
size(800,800);
background(img);//若圖的大小,與size()相同,可直接把圖片當背景

將老師的圖片拉近processing裡面後將他生成出來






//week05_02_cwa_typhoon_array_loadStrings
//老師準備了list.txt裡面有299行
int N=299;
PImage []imgs=new PImage[299];
void setup(){
  size(800,800);
  String [] filenames = loadStrings("list.txt");//把list.txt的299行,放入filenames裡
  for(int i =0;i<N;i++){//把每一張圖片,都讀近來
    imgs[i] = loadImage(filenames[i]);
  }
}
void draw(){
  int i = frameCount%N;
  background(imgs[i]);
}

根據list裡面的圖片利用framecount來依照時間來顯示圖片

2.第二節課程式碼



//week05_03_cwa_typhoon_2750
//整合上週&今天的程式
PImage img;
void setup(){
  size(500,500);
  img = loadImage("LCC_VIS_TRGB_2750-2024-10-02-07-40.jpg");
}
float s = 1.0,x=0,y=0;
float realX=0,realY=0;
void draw(){
  background(255);
  translate(x,y);
  scale(s);
  image(img,0,0);
}
void mouseDragged(){
    x+=mouseX- pmouseX;
    y+=mouseY- pmouseY;
}
void mouseWheel(MouseEvent e){
  realX = (mouseX-x)/s;
  realY = (mouseX-y)/s;
  float oldS=s;
  if(e.getCount()<0)s*=1.1;
  else s*=0.9;
  x= x+realX*oldS-realX*s;
  y= y+realY*oldS-realY*s;
}

結合上週的縮放拖曳來將天氣圖片做移動


//week05_04_pendulum_mouseDragged_x_y
void setup(){
  size(400,600);
}
float x = 200,y=300;
void draw(){
  background(255);
  line(200,100,x,y);
  ellipse(x,y,30,30);
}
void mouseDragged(){
  x=mouseX;
  y=mouseY;
}
利用滑鼠來拖曳圓圈和線條


//week05_05_pendulum_cos_sin_draw_line
void setup(){
  size(400,600);
}
float x = 200,y=300;
void draw(){
  background(255);
  stroke(0);
  line(200,100,x,y);
  ellipse(x,y,30,30);
  stroke(255,0,0);
  line(x,y,x,y+100);
  PVector d =new PVector(x-200,y-100).normalize();//長度1
  PVector d2 = new PVector(0,1);
  float g = PVector.dot(d,d2);
  d.mult(100*g);
  stroke(0,255,0);
  line(x,y,x+d.x,y+d.y);
}
void mouseDragged(){
  x=mouseX;
  y=mouseY;
}

3.第三節上課程式碼
//week05_06_PVector_new_PVector_x_y
void setup(){
  size(400,600);
  c = new PVector(200,100);//new 出新的物件
  p = new PVector(200,130);//new 出新的物件
}
PVector c,p;
void draw(){
  background(255);
  ellipse(c.x,c.y,10,10);//使用物件的c.x
  ellipse(p.x,p.y,10,10);//使用物件的p.x
}


//week05_07_PVector_normalize_dot_mult
void setup(){
  size(400,600);
}
float x = 200,y=300;
void draw(){
  background(255);
  stroke(0);
  line(200,100,x,y);
  ellipse(x,y,30,30);
  
  stroke(255,0,0);
  line(x,y,x,y+100);
  
  PVector d =new PVector(x-200,y-100).normalize();//長度1
  PVector d2 = new PVector(0,1);
  float g = PVector.dot(d,d2);
  d.mult(100*g);
  stroke(0,255,0);
  line(x,y,x+d.x,y+d.y);

  PVector N = new PVector(d.y,-d.x).normalize();
  N.mult(100*sin(acos(g)));//g是cos(a)
  stroke(0,0,255);
  line(x,y,x+N.x,y+N.y);
}
void mouseDragged(){
  x=mouseX;
  y=mouseY;
}
將三個方位來顯現出來

未完成
//week05_08_pendulum_not_OK_PVector_sub_velocity
void setup(){
  size(400,600);
}
float x = 200,y=300;
void draw(){
  background(255);
  stroke(0);
  line(200,100,x,y);
  ellipse(x,y,30,30);
  
  stroke(255,0,0);
  line(x,y,x,y+100);
  
  PVector d =new PVector(x-200,y-100).normalize();//長度1
  PVector d2 = new PVector(0,1);
  float g = PVector.dot(d,d2);
  d.mult(100*g);
  stroke(0,255,0);
  line(x,y,x+d.x,y+d.y);

  PVector N =PVector.sub(d,d2)//PVector N = new PVector(d.y,-d.x).normalize();
  N.mult(100*sin(acos(g)));//g是cos(a)
  stroke(0,0,255);
  line(x,y,x+N.x,y+N.y);
  
  
  v.x+=N.x/1000;
  v.y+=N.y/1000;
  //x+=v.x;
  //y+=v.y;
}
PVector v = new PVector();
void mouseDragged(){
  x=mouseX;
  y=mouseY;
}

4.上傳github




沒有留言:

張貼留言