2024年10月7日 星期一

WEEK05-翁逸豪

 WEEK05-1

PImage img = loadImage("TWI_IR1_CR_800-2024-10-02-08-00.jpg");
size(800,800);
background(img);
讀入一張圖檔

WEEK05-2

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() {
  background(imgs[frameCount%N]);
}
將所有圖片名字輸入到txt檔,讓程式碼去讀txt檔的圖片名字

WEEK05-3

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

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

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

void setup() {
  size(400, 600);
  c = new PVector(200, 100);//new 新物件c
  p = new PVector(200, 300);//new 新物件p
}
PVector c, p;
void draw() {
  background(255);
  ellipse(c.x, c.y, 10, 10);//使用物件c
  ellipse(p.x, p.y, 10, 10);//使用物件p
}
介紹PVector(向量)

WEEK05-7

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);//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();//調整向量的力的多寡
  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() {
  x = mouseX;
  y = mouseY;
}
把所有向量都畫出來

WEEK05-8

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);//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);//調整向量的力的多寡
  //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();//球的速度,一開始是0
void mouseDragged() {
  x = mouseX;
  y = mouseY;
}
雖然可以擺動但是會一直下墜


沒有留言:

張貼留言