2023年10月12日 星期四

學校滑鼠有夠爛 - Week05 - 互動技術🦆

 

Week05


void setup(){
  size(400,400,P3D);//Processing的3D功能
}
void draw(){
  background(#FFFFF2);
  pushMatrix();
    translate(mouseX,mouseY);
    box(100);//3D的盒子、方塊
  popMatrix();
}




-1
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);//Processing的3D功能
}
void draw(){
  background(#FFFFF2);
  pushMatrix();
    translate(mouseX,mouseY);
    rotateY(radians(mouseX));//對Y軸轉
    fill(0,255,0);//面填成綠色
    box(100);//3D的盒子、方塊
    
    noFill();//面不要填
    scale(2);//放大2倍
    box(100);//雖然是100的盒子,但上面有放大,他就放大了
  popMatrix();
}



-2




size(400,400,P3D);
beginShape();
vertex(200,0);
vertex(0,400);
vertex(400,400);
endShape();




size(410,410,P3D);
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(CLOSE);




-3



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;//大的資料結構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);
  }
  beginShape();
  for(PVector p:pt){
    vertex(p.x,p.y);
  }
  endShape();
}
void mousePressed(){
  pt.add(new PVector(mouseX,mouseY));
}//大的資料結構裡,加入小的PVector物件


可以點左鍵或右鍵



-4





ArrayList<PVector>pt;//大的資料結構ArrayList
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);
    }
    endShape();
  popMatrix();
}
void mousePressed(){
  if(mouseButton==LEFT){
    pt.add(new PVector(mouseX,mouseY));
  }
}//大的資料結構裡,加入小的PVector物件


一直按著右鍵會以一定速度作旋轉



-5




void setup(){
  size(400,400,P3D);//Processing的3D功能
}
void draw(){
  background(255);
  if(mousePressed && mouseButton==LEFT) background(255,0,0);
  if(mousePressed && mouseButton==CENTER) background(0,255,0);
  if(mousePressed && mouseButton==RIGHT) background(0,0,255);
}

點擊"左鍵"、"滾輪"、"右鍵"



-6



ArrayList<PVector>pt;//大的資料結構ArrayList
void setup(){
 size(400,400,P3D); 
  pt=new ArrayList<PVector>();
  for(int i=0; i<20; i++){
    pt.add(new PVector(i*20,20));
  }
}
void draw(){
  background(255);
  for(PVector p:pt){
    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;
    }
  }
}
20個頂點



-8


ArrayList<PVector>pt;//大的資料結構ArrayList
void setup(){
 size(400,400,P3D); 
  pt=new ArrayList<PVector>();
  for(int i=0; i<20; i++){
    pt.add(new PVector(i*20,20));
  }
}
void draw(){
  background(255);
  for(PVector p:pt){
    ellipse(p.x,p.y,10,10);
  }
  if(ans!=null) ellipse(ans.x,ans.y,15,15);
}
PVector ans = null;
void mouseDragged(){
  if(mouseButton==CENTER && ans!=null){
    ans.x = mouseX;
    ans.x = 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;
      }
    }
  }
}




-9




ArrayList<PVector>pt;//大的資料結構ArrayList
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)));
  }
}
void draw(){
  background(255);
  for(PVector p:pt){
    ellipse(p.x,p.y,10,10);
  }
  if(ans!=null) ellipse(ans.x,ans.y,15,15);
}
PVector ans = null;
void mouseDragged(){
  if(mouseButton==CENTER && ans!=null){
    ans.x = mouseX;
    ans.x = 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;
      }
    }
  }else if(mouseButton==RIGHT){//右鍵要刪掉
    for(int i=0; i<pt.size(); i++){
      PVector p = pt.get(i);
      if(dist(p.x,p.y,mouseX,mouseY)<5){//找到夠近的點
        pt.remove(i);//把第i個點刪掉。(刪的時候,會把大資料結構右邊的都左移動一格)
      }
    }
  }
}



右鍵刪除後的模樣


沒有留言:

張貼留言