2024年10月7日 星期一

Week05 Typhoon

 

今天第一個程式:

第一個:
PImage img=loadImage("TWI_IR1_CR_800-2024-10-02-08-00.jpg");
size(800,800);
background(img);

第二個:
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]);
}
第三個(加入上禮拜的縮放程式):
PImage img;
void setup()
{
  size(500, 500);
  img=loadImage("LCC_VIS_TRGB_2750-2024-10-02-07-40.jpg");
}
float s=0.4, x=0, y=0;
float realX=0, realY=0;
void draw()
{
  background(#92C2F5);
  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;
}

第四個(滑鼠可以按著拉球):
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;
}

第五個:
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;
}

第六個(認識PVector):
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);
}

第七個(利用PVector算出藍色的線):
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;
}

第八個(因為程式還沒寫好,所以球會一直掉下去):
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);//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);
  v.x+=N.x/1000;//x+=N.x/100;
  v.y+=N.y/1000;//y+=N.y/100;
  x+=v.x;
  y+=v.y;
}
PVector v=new PVector();
void mouseDragged()
{
  x=mouseX;
  y=mouseY;
}


快捷鍵:

ctrl+R 執行

ctrl+T 自動排版

ctrl+N 新檔案


Git 指令

cd desktop

git clone https://github.com/mickey1132/2024-Interaction

cd 2024-Interaction

git status

git add .

git status

git config --global user.email mickylin1132@gmail.com

git config --global user.name mickey1132

git commit -m WeekXX

git push

沒有留言:

張貼留言