2024年9月30日 星期一

Week04 TAIWAN



今天第一個程式:
第一個:
size(500, 500);
PShape taiwan=loadShape("Taiwan-icon.svg");
PShape taiwan2=loadShape("tw.svg");
shape(taiwan);
shape(taiwan2);

第二個:
size(500, 500);
PShape taiwan=loadShape("Taiwan-icon.svg");
PShape taiwan2=loadShape("tw.svg");
pushMatrix();
  scale(10);
  shape(taiwan);
popMatrix();
pushMatrix();
  scale(0.5);
  shape(taiwan2);
popMatrix();
第三個(滑鼠滾輪可以放大縮小):
PShape taiwan,taiwan2;
void setup()
{
  size(500,500);
  taiwan=loadShape("Taiwan-icon.svg");
  taiwan2=loadShape("tw.svg");
}
float taiwanScale=1;
void draw()
{
  background(#92C2F5);
  pushMatrix();
    scale(10*taiwanScale);
    shape(taiwan);
  popMatrix();
  pushMatrix();
    scale(0.5*taiwanScale);
    shape(taiwan2);
  popMatrix();
}
void mouseWheel(MouseEvent e)
{
  float d=e.getCount();
  if(d>0)taiwanScale*=0.9;
  else taiwanScale*=1.1;
}

第四個(變成世界地圖,滑鼠滾輪可以放大縮小):
PShape world;
void setup()
{
  size(800,400);
  world=loadShape("world.svg");
}
float s=0.4;
void draw()
{
  background(#92C2F5);
  scale(s);
  shape(world);
}
void mouseWheel(MouseEvent e)
{
  if(e.getCount()>0)s*=0.9;
  else s*=1.1;
}

第五個(滑鼠可以拖曳地圖):
PShape world;
void setup()
{
  size(800, 400);
  world=loadShape("world.svg");
}
float s=0.4, x=0, y=0;
void draw()
{
  background(#92C2F5);
  translate(x, y);
  scale(s);
  shape(world);
}
void mouseDragged()
{
  x+=mouseX-pmouseX;
  y+=mouseY-pmouseY;
}
void mouseWheel(MouseEvent e)
{
  if (e.getCount()>0)s*=0.9;
  else s*=1.1;
}
第六個(滑鼠指到哪就會放大那邊):
PShape world;
void setup()
{
  size(800, 400);
  world=loadShape("world.svg");
}
float s=0.4, x=0, y=0;
float realX=0, realY=0;
void draw()
{
  background(#92C2F5);
  translate(x, y);
  scale(s);
  shape(world);
  ellipse(realX, realY, 10, 10);
}
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;
}

第七個:
size(600,500);
background(0);
stroke(255);
fill(0);
ellipse(50,50,100,100);
第八個(滑鼠按下去就畫圓):
void setup()
{
  size(600, 500);
  background(0);
  stroke(255);
  fill(0);
}
void draw() 
{
  //ellipse(mouseX, mouseY, 100, 100);
}
void mousePressed()
{
  ellipse(mouseX, mouseY, 100, 100);
}
第九個(滑鼠按左右鍵會放大縮小):
void setup()
{
  size(600, 500);
  background(0);
  stroke(255);
  fill(0);
}
void draw() 
{
  //ellipse(mouseX, mouseY, 100, 100);
}
float s=25;
void mousePressed()
{
  ellipse(mouseX, mouseY, s, s);
  if(mouseButton==LEFT)s*=1.1;
  if(mouseButton==RIGHT)s*=0.9;
}
第十個(設定一個變數,讓圓跟著走):
void setup()
{
  size(600, 500);
  background(0);
  stroke(255);
  fill(0);
}
void draw() 
{
  //ellipse(mouseX, mouseY, 100, 100);
}
float s=25,t=0;
void mousePressed()
{
  ellipse(300+200*cos(t), 250+200*sin(t), s, s);
  t+=0.06;
  if(mouseButton==LEFT)s*=1.1;
  if(mouseButton==RIGHT)s*=0.9;
}

快捷鍵:

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

沒有留言:

張貼留言