//week05_01_cwa_typhoon_images
//把老師的github圖檔放入 hithub.com/jsyeh/cwa
//存檔後ctrl + K開啟檔案總管
PImage img = loadImage("TWI_IR1_CR_800-2024-10-02-08-00.jpg");
size(800,800);
background(img);
//week05_02_cwa_typhoon_array_loadStrings
//把老師的list.txt匯入(裡面有299張圖片的檔名)
int N=299;
PImage [] imgs = new PImage[299];//準備好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;//照時間輪 %N取餘數,以免超過陣列大小
background(imgs[frameCount%N]);//現在顯示第i張圖
}
把299張圖片連貫起來
//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 = (mouseY-y)/s; float oldS=s; if (e.getCount()>0)s *=0.9; else s *=1.1; x=x+realX*oldS-realX*s; y=y+realY*oldS-realY*s; } 放入一張高解析度的圖片,並拖曳、放大縮小
//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,50,50);
stroke(255,0,0);
line(x,y,x,y+100);
PVector d=new PVector(x-200,y-100).normalize();
PVector d2=new PVector(0,2);
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_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); ellipse(p.x,p.y,10,10); }//week05_07_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,50,50); stroke(255,0,0); line(x,y,x,y+100); PVector d=new PVector(x-200,y-100).normalize(); PVector d2=new PVector(0,2); float g =PVector.dot(d,d2);//cos(a) 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();//長度1 N.mult(100*sin(acos(g)));//g是cos(a),acos(g)就是角度a stroke(0,0,255);//藍色線往右下 line(x,y,x+N.x,y+N.y); } void mouseDragged(){//void mouseDragged() x = mouseX; y = mouseY; }//week05_08_pendulum_not_ok_PVecttor_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,50,50); stroke(255,0,0);//紅色往下的線 line(x,y,x,y+100); PVector d=new PVector(x-200,y-100).normalize(); PVector d2=new PVector(0,2); float g =PVector.dot(d,d2);//cos(a) 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);//PVector N = new PVector(d.y,-d.x).normalize();//長度1 //N.mult(100*sin(acos(g)));//g是cos(a),acos(g)就是角度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(){//void mouseDragged() x = mouseX; y = mouseY; }
沒有留言:
張貼留言