2023年10月12日 星期四

week05 咻消失

 week05


void setup(){
  size(400,400,P3D);//Processing的3D功能
}
void draw(){
  background(#FFFFF2);
  pushMatrix();//備份矩陣
    translate(mouseX,mouseY);//移動
    rotateY(radians(mouseX));//對Y軸轉動
    box(100);//3D的盒子、方塊
  popMatrix();//還原矩陣
}
void setup(){
  size(400,400,P3D);
}
void draw(){
  background(#FFFFF2);
  pushMatrix();
    translate(mouseX,mouseY);
    rotateY(radians(mouseX));
    fill(0,255,0);//面填成綠色
    box(100);
    noFill();//面不要填
    scale(2);//放大2倍
    box(100);//雖然是100的盒子,但上面有放大,它就放大了
  popMatrix();
}
size(410,410,P3D);
noFill();
beginShape();
fill(255,0,0); vertex(200,0);
fill(0,255,0); vertex(0,400);
fill(0,0,255); vertex(400,400);
endShape();
size(410,410,P3D);
noFill();
beginShape();
vertex(200,0);
vertex(0,400);
vertex(400,400);
endShape();三角形沒有封閉
endShape(CLOSE);
ArrayList<PVector> pt;//大的資料結構ArrayList
void setup(){
  size(400,400,P3D);
  pt = new ArrayList<PVector>();
//初始化,把大的資料結構準備好(裡面放小資料結構)
}
void draw(){
  background(#FFFFF2);
  for(PVector p:pt){
    ellipse(p.x,p.y,10,10);
  }
}
void mousePressed(){
  pt.add(new PVector(mouseX,mouseY));
}//大的資料結構裡,加入小的PVector的物件ArrayList<PVector> pt;
void setup(){
  size(400,400,P3D);
  pt = new ArrayList<PVector>();
}
void draw(){
  background(#FFFFF2);
  for(PVector p:pt){
    ellipse(p.x,p.y,10,10);
  }
  beginShape();
  for(PVector p:pt){
    vertex(p.x,p.y,10,10);
  }
  endShape();
}
void mousePressed(){
  pt.add(new PVector(mouseX,mouseY));
}
ArrayList<PVector> pt;
void setup(){
  size(400,400,P3D);
  pt = new ArrayList<PVector>();
}
void draw(){
  background(#FFFFF2);
  pushMatrix();
  if(mousePressed && mouseButton==RIGHT){
    translate(200,200);
    rotateY(radians(frameCount));
    translate(-200,-200);
  }
  for(PVector p:pt){
    ellipse(p.x,p.y,10,10);
  }
  beginShape();
  for(PVector p:pt){
    vertex(p.x,p.y,10,10);
  }
  endShape();
  popMatrix();
}
void mousePressed(){
  if(mouseButton==LEFT){
    pt.add(new PVector(mouseX,mouseY));
  }
}
ArrayList<PVector> pt;
void setup(){
  size(400,400,P3D);
  pt = new ArrayList<PVector>();
  for(int i=0;i<20;i++){
    pt.add(new PVector(i*20,20));
  }//假設畫面中,點好了20個頂點
}
void draw(){
  background(255);
  for(PVector p:pt){//畫出20個頂點
    ellipse(p.x,p.y,10,10);
  }
  if(ans!=null) ellipse(ans.x,ans.y,15,15);
}
PVector ans = null;
void mousePressed(){
  for(PVector p:pt){
    if(dist(p.x,p.y,mouseX,mouseY)<5){
      ans = p;
    }
  }
}
ArrayList<PVector> pt;
void setup(){
  size(400,400,P3D);
  pt = new ArrayList<PVector>();
  for(int i=0;i<37;i++){
    pt.add(new PVector(random(400),random(400)));
  }//假設畫面中,點好了37個頂點
}
void draw(){
  background(255);
  for(PVector p:pt){//畫出37個頂點
    ellipse(p.x,p.y,10,10);
  }
  if(ans!=null) ellipse(ans.x,ans.y,15,15);
}
PVector ans = null;
void mouseDragged(){//mouseDragged
  if(mouseButton==CENTER && ans!=null){
    ans.x = mouseX;
    ans.y = mouseY;
  }
}
void mousePressed(){//
  if(mouseButton==LEFT) pt.add(new PVector(mouseX,mouseY));
  else if(mouseButton==CENTER){可以用中鍵拖動
    for(PVector p:pt){
      if(dist(p.x,p.y,mouseX,mouseY)<5){
        ans = p;
      }
    }
  }
}
ArrayList<PVector> pt;
void setup(){
  size(400,400,P3D);
  pt = new ArrayList<PVector>();
  for(int i=0;i<37;i++){
    pt.add(new PVector(random(400),random(400)));
  }//假設畫面中,點好了37個頂點
}
void draw(){
  background(255);
  for(PVector p:pt){//畫出37個頂點
    ellipse(p.x,p.y,10,10);
  }
  if(ans!=null) ellipse(ans.x,ans.y,15,15);
}
PVector ans = null;
void mouseDragged(){//mouseDragged
  if(mouseButton==CENTER && ans!=null){
    ans.x = mouseX;
    ans.y = mouseY;
  }
}
void mousePressed(){
  if(mouseButton==LEFT) pt.add(new PVector(mouseX,mouseY));
  else if(mouseButton==CENTER){
    for(PVector p:pt){//厲害的for迴圈(不能增刪裡面的東西)
      if(dist(p.x,p.y,mouseX,mouseY)<5){
        ans = p;
      }
    }
  }else if(mouseButton==RIGHT){//右鍵,要刪掉。要用傳統for迴圈
      for(int i=0;i<pt.size();i++){//要寫2行,才等於厲害的1行
        PVector p = pt.get(i);
        if(dist(p.x,p.y,mouseX,mouseY)<5){//找到夠近的點
          pt.remove(i);//就把第i個點刪掉。(刪的時候,會把大資料結構右邊的都左移動一格)
        }
      }
  }
}












沒有留言:

張貼留言