2025年5月22日 星期四

week14_12750316

week14_1_PFont_createFont_textSize_text 


size(300,300);

textSize(50);

text("Hello",10,50);

PFont font = createFont("Time New Roman",50);

textFont(font);

text("Hello",10,100);

//print(PFont.list());

for(String name : PFont.list()) println(name); //Java


week14_2_PFont_chinese_font1_font2_font3_chinese_font_textFnt_cursor

PFont font1,font2,font3;Add commentMore actions
void setup(){
  size(300,300);
  font1 = createFont("Times New Roman Bold Italic",50);
  font2 = createFont("微軟正黑體 Bold",50);
  font3 = createFont("elffont-rock.otf",50);
}
void draw(){
  background(0);
  cursor(CROSS);
  fill(255);
  textFont(font1);
  text("Hello 中文", mouseX+20, mouseY-20);
  fill(#FF8E8E);
  textFont(font2);
  text("Hello 中文", mouseX+20, mouseY+50);
  textFont(font3);Add commentMore actions
  text("ㄅㄆㄇ", mouseX+20, mouseY+100);
}


week14_3_inverse_kinematics_part1

void setup(){
  size(400,400);
}
float [] angle = new float[5];
void draw(){
  background(255);
  translate(200,350);
  ellipse(0,0,12,12);
  
  pushMatrix();
    rotate(radians(angle[0]));
    rect(0,-5,50,10);
  popMatrix();
}
void mouseDragged(){
  angle[0] += mouseX - pmouseX;
}


week14_4_inverse_kinematics_part2

void setup(){
  size(400,400);Add commentMore actions
}
float [] angle = new float[5];
void draw(){
  background(255);
  translate(200,350);
  ellipse(0,0,12,12);
  
  pushMatrix();
    rotate(radians(angle[0]));
    rect(0,-5,50,10);
    pushMatrix();
      translate(50,0);
      rotate(radians(angle[1]));
      rect(0,-5,50,10);
    popMatrix();
  popMatrix();
}
void mouseDragged(){
  angle[ID] += mouseX - pmouseX;
}
int ID=0;
void keyPressed(){
  if(key=='0') ID=0;
  if(key=='1') ID=1;
}

week14_5_ik_inverse_kinematics_part3

void setup(){
  size(400,400);
  for(int i=0; i<6; i++){
    p[i] = new PVector(200, 350-50*i);
  }
}
PVector [] p = new PVector[6];
void draw(){
  background(255);
  for(int i=0;i<2;i++){
    if(i>0) line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
    fill(255,0,0);
    ellipse(p[i].x,p[i].y,8,8);
    fill(0);
    text("p:"+i, p[i].x+10, p[i].y);
  }
  ellipse(mouseX,mouseY,6,6);
  line(p[0].x, p[0].y, mouseX, mouseY);
}

week14_6_ik_inverse_kinematics_part4


void setup(){Add commentMore actions
  size(400,400);
  for(int i=0; i<2; i++){
    p[i] = new PVector(200, 350-50*i);
  }
}
PVector [] p = new PVector[6];
void draw(){
  background(255);
  for(int i=0;i<2;i++){
    if(i>0) line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
    fill(255,0,0);
    ellipse(p[i].x,p[i].y,8,8);
    fill(0);
    text("p:"+i, p[i].x+10, p[i].y);
  }
  PVector now = new PVector(mouseX, mouseY);
  PVector v = PVector.sub(now,p[0]).normalize().mult(50);
  p[1].x = p[0].x + v.x;
  p[1].y = p[0].y + v.y;
  ellipse(mouseX,mouseY,6,6);
  line(p[0].x, p[0].y, mouseX, mouseY);
}


week14_7_ik_inverse_kinematics_part5

void setup(){
  size(400,400);
  for(int i=0; i<6; i++){
    p[i] = new PVector(200, 350-50*i);
  }
}
PVector [] p = new PVector[6];
void draw(){
  background(255);
  for(int i=0;i<6;i++){
    if(i>0) line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
    fill(255,0,0);
    ellipse(p[i].x,p[i].y,8,8);
    fill(0);
    text("p:"+i, p[i].x+10, p[i].y);
  }
  PVector now = new PVector(mouseX, mouseY);
  PVector v = PVector.sub(now,p[4]).normalize().mult(50);
  p[5].x = p[4].x + v.x;
  p[5].y = p[4].y + v.y;
  ellipse(mouseX,mouseY,6,6);
  line(p[4].x, p[4].y, mouseX, mouseY);
}

week14_8_ik_inverse_kinematics_part6

void setup(){Add commentMore actions
  size(400,400);
  for(int i=0; i<6; i++){
    p[i] = new PVector(200, 350-50*i);
  }
}
PVector [] p = new PVector[6];
void draw(){
  background(255);
  for(int i=0;i<6;i++){
    if(i>0) line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
    fill(255,0,0);
    ellipse(p[i].x,p[i].y,8,8);
    fill(0);
    text("p:"+i, p[i].x+10, p[i].y);
  }
  PVector now = new PVector(mouseX, mouseY);
  for(int i=5;i>0;i--){
    PVector v = PVector.sub(now,p[i]).normalize().mult(50);
    p[i].x = now.x - v.x;
    p[i].y = now.y - v.y;
    now=p[i];
  }
  ellipse(mouseX,mouseY,6,6);
  //line(p[4].x, p[4].y, mouseX, mouseY);
}


week14_9_ik_inverse_kinematics_part7

void setup(){Add commentMore actions
  size(400,400);
  for(int i=0; i<6; i++){
    p[i] = new PVector(200, 350-50*i);
  }
}
PVector [] p = new PVector[6];
void draw(){
  background(255);
  for(int i=0;i<6;i++){
    if(i>0) line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
    fill(255,0,0);
    ellipse(p[i].x,p[i].y,8,8);
    fill(0);
    text("p:"+i, p[i].x+10, p[i].y);
  }
  PVector now = new PVector(mouseX, mouseY);
  p[5].x=now.x;Add commentMore actions
  p[5].y=now.y;
  for(int i=4;i>0;i--){
    PVector v = PVector.sub(p[i+1],p[i]).normalize().mult(50);
    p[i].x = p[i+1].x - v.x;
    p[i].y = p[i+1].y - v.y;
  }
  for(int i=1;i<=5;i++){
    PVector v = PVector.sub(p[i],p[i-1]).normalize().mult(50);
    p[i].x = p[i-1].x + v.x;
    p[i].y = p[i-1].y + v.y;
  }
  ellipse(mouseX,mouseY,6,6);
}


week14_9b_ik_inverse_kinematics_part8

void setup(){Add commentMore actions
  size(400,400);
  for(int i=0; i<N; i++){
    p[i] = new PVector(200, 350-L*i);
  }
}
int N=20, L=300/N;
PVector [] p = new PVector[N];
void draw(){
  background(255);
  for(int i=0;i<N;i++){
    if(i>0) line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
    fill(255,0,0);
    ellipse(p[i].x,p[i].y,8,8);
    fill(0);
    text("p:"+i, p[i].x+10, p[i].y);
  }
  p[N-1].x=mouseX;
  p[N-1].y=mouseY;
  for(int i=N-2;i>0;i--){
    PVector v = PVector.sub(p[i+1],p[i]).normalize().mult(L);
    p[i].x = p[i+1].x - v.x;
    p[i].y = p[i+1].y - v.y;
  }
  for(int i=1;i<N;i++){
    PVector v = PVector.sub(p[i],p[i-1]).normalize().mult(L);
    p[i].x = p[i-1].x + v.x;
    p[i].y = p[i-1].y + v.y;
  }
  ellipse(mouseX,mouseY,6,6);
}




沒有留言:

張貼留言