2024年10月7日 星期一

week05

 week05


week05_1_cwa_typhoon_image




1.練習放入CWA圖

2.讀入圖檔

3.下一步嘗試用for讀全部




程式碼

///week05_1_cwa_typhoon_image


PImage img = loadImage("TWI_IR1_CR_800-2024-10-02-08-00.jpg");

size(800,800);

background(img);


week05_2_cwa_typhoon_array_loadStrings







1.練習放入CWA圖

2.讀入list.txt

3.連續圖檔讀入,變成影片




程式碼

///week05_2_cwa_typhoon_array_loadStrings

int N = 299;

PImage[] imgs = new PImage[299];

void setup(){

  size(800,800);

  String [] filenames = loadStrings("list.txt");

  for(int i=0;i<N;i++) {

    imgs[i] = loadImage(filenames[i]);

  }

}

void draw() {

  int i = frameCount % N;

  background(imgs[i]);

}


week05_3_cwa_typhoon_2750




1.練習放入CWA圖

2.讀入圖檔

3.結合week04_6,可以拖曳和縮放




程式碼

///week05_3_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 = (mouseY - 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_4_pendulum




1.練習做單擺

2.座出滑鼠,座標放入球和線



程式碼

///week05_4_pendulum

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_5_pendulum_cos_sin_draw_line




1.練習做單擺

2.座出滑鼠,座標放入球和線



程式碼

///week05_5_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();

  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;

}


week05_6_PVector_new_PVector_x_y






1.week05-5太難理解

2.PVector:PVector 是一個處理二維向量的類別,用於表示位置、速度、加速度等。它可以通過new PVector(x, y)來創建,其中 x 和 y 表示向量的座標值。

3.繪製圖形:使用ellipse()函數繪製橢圓形,接受四個參數,分別表示橢圓的中心座標和寬度、高度。



程式碼

///week05_6_PVector_new_PVector_x_y


void setup(){

  size(400,600);

  c = new PVector(200,100);

  p = new PVector(200,130);

}

PVector c,p;

void draw(){

  background(255);

  ellipse(c.x,c.y,10,10);

  ellipse(p.x,p.y,10,10);

}


week05_7_pendulum_PVector_normalize_dot_mult




1.多了一條藍線


程式碼

///week05_7_pendulum_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();

  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)));

  stroke(0,0,255);

  line(x,y,x+N.x,y+N.y);

  

}


void mouseDragged(){

  x = mouseX;

  y = mouseY;

}



week05_8_pendulum_not_ok_PVector_sub_velocity






1.加上物理學的東西,但尚未完成

程式碼

///week05_8_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();

  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(d2.mult(100),d);

  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;

}



沒有留言:

張貼留言