1-1
做出畫筆並可以再放開滑鼠的時候清除筆跡
void setup(){ size(400,400); background(255); } void draw(){ if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); } void mouseReleased(){ background(255); }
1-2
新加了鬼的座標,並可以靠近角色
void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void draw(){ ellipse(200,200,15,15); ellipse(ghostX,ghostY,15,15); if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ background(255); }
1-3
用ArrayList 去執行,讓殘影消失,但筆跡還沒消除
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ ellipse(200,200,15,15); background(255); //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size();i++){ PVector p=pt.get(i); ellipse(p.x,p.y,3,3); } ellipse(ghostX,ghostY,15,15); float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ background(255); }
1-4
新增remove,mouseReleased,用倒過來的for迴圈,把畫筆改成直線
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ ellipse(200,200,15,15); background(255); //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } ellipse(ghostX,ghostY,15,15); float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
2-1
畫橫的會改成紅色,直的變黑色
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); ellipse(200,200,15,15); ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); } if(dpx>100 && dpy<40) stroke(255,0,0); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
2-2
修改直線的時候變成藍線,設定範圍
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); strokeWeight(1); stroke(0);ellipse(200,200,15,15); stroke(0);ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); } if(dpx>100 && dpy<40) stroke(255,0,0); else if(dpx<40 && dpy>100)stroke(0,0,255); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
2-3
嘗試畫綠色線,因為綠線要畫斜的,所以設立一個rightdown,只要達到條件線就能變綠色,缺點畫太快變不了色
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); strokeWeight(1); stroke(0);ellipse(200,200,15,15); stroke(0);ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 int rightdown=0; //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); if(p2.x-p.x>0 && p2.y-p.y>0)rightdown++; } if(dpx>100 && dpy<40) stroke(255,0,0); else if(dpx<40 && dpy>100)stroke(0,0,255); else if(rightdown>30)stroke(0,255,0); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
2-4
改善上一個的缺點,rightdown從整數改成浮點數更精準,rightdown++改成rightdown+=sqrt(dpx*dpx+dpy*dpy);
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); strokeWeight(1); stroke(0);ellipse(200,200,15,15); stroke(0);ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 float rightdown=0; //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); if(p2.x-p.x>0 && p2.y-p.y>0)rightdown+=sqrt(dpx*dpx+dpy*dpy); } if(dpx>100 && dpy<40) stroke(255,0,0); else if(dpx<40 && dpy>100)stroke(0,0,255); else if(rightdown>150)stroke(0,255,0); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
3-1
讓綠線做打勾的動作才能通關,用green_part1、green_ok去做,可是現在倒鉤和正鉤都能成功
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); strokeWeight(1); stroke(0);ellipse(200,200,15,15); stroke(0);ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 float rightdown=0,rightup=0; boolean green_part1=false,green_ok=false; //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); if(p2.x-p.x>0 && p2.y-p.y>0)rightdown+=sqrt(dpx*dpx+dpy*dpy); if(p2.x-p.x>0 && p2.y-p.y<0)rightup+=sqrt(dpx*dpx+dpy*dpy); ellipse(p.x,p.y,10,10); if(green_part1==false && rightdown>150)green_part1=true; else if(green_part1==true && rightup>150)green_ok=true; } if(dpx>100 && dpy<40) stroke(255,0,0); else if(dpx<40 && dpy>100)stroke(0,0,255); else if(rightdown>150)stroke(0,255,0); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
3-2
為了只讓正鉤能畫出來,green_part1,和green_rightup,green_ok,讓倒鉤一開始是黑色,正鉤一開始是深綠後來畫完變淺綠正確
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); strokeWeight(1); stroke(0);ellipse(200,200,15,15); stroke(0);ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 float rightdown=0,green_rightup=0; boolean green_part1=false,green_ok=false; //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); if(p2.x-p.x>0 && p2.y-p.y>0)rightdown+=sqrt(dpx*dpx+dpy*dpy); if(green_part1 && p2.y-p.y<0)green_rightup+=sqrt(dpx*dpx+dpy*dpy); ellipse(p.x,p.y,10,10); if(green_part1==false && rightdown>150)green_part1=true; else if(green_part1==true && green_rightup>150)green_ok=true; } if(dpx>100 && dpy<40) stroke(255,0,0); else if(dpx<40 && dpy>100)stroke(0,0,255); else if(green_ok)stroke(0,255,0); else if(green_part1)stroke(0,128,0); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
3-3
新增黃線
ArrayList<PVector>pt=new ArrayList<PVector>(); void setup(){ size(400,400); background(255); } float ghostX=400,ghostY=20; void mouseDragged(){ pt.add(new PVector(mouseX,mouseY)); } void draw(){ background(255); strokeWeight(1); stroke(0);ellipse(200,200,15,15); stroke(0);ellipse(ghostX,ghostY,15,15); strokeWeight(4); float dpx=0,dpy=0;//看p.x,2.y,p2.x,p2.y的差距 float rightdown=0,green_rightup=0; float rightup=0,yellow_rightdown=0; boolean green_part1=false,green_ok=false; boolean yellow_part1=false,yellow_ok=false; //if(mousePressed)line(mouseX,mouseY,pmouseX,pmouseY); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); dpx+=abs(p2.x-p.x); dpy+=abs(p2.y-p.y); if(p2.x-p.x>0 && p2.y-p.y>0)rightdown+=sqrt(dpx*dpx+dpy*dpy); if(green_part1 && p2.y-p.y<0)green_rightup+=sqrt(dpx*dpx+dpy*dpy); if(p2.x-p.x>0 && p2.y-p.y>0)rightup+=sqrt(dpx*dpx+dpy*dpy); if(yellow_part1 && p2.x-p.x>0 && p2.y-p.y>0)yellow_rightdown+=sqrt(dpx*dpx+dpy*dpy); //ellipse(p.x,p.y,10,10); if(green_part1==false && rightdown>150)green_part1=true; else if(green_part1==true && green_rightup>150)green_ok=true; if(yellow_part1==false && rightup>150)yellow_part1=true; else if(yellow_part1==true && yellow_rightdown>150)yellow_ok=true; } if(dpx>100 && dpy<40) stroke(255,0,0); else if(dpx<40 && dpy>100)stroke(0,0,255); else if(green_ok)stroke(0,255,0); //else if(green_part1)stroke(0,128,0); else if(yellow_ok)stroke(255,255,0); else stroke(0); for(int i=0;i<pt.size()-1;i++){ PVector p=pt.get(i),p2=pt.get(i+1); line(p.x,p.y,p2.x,p2.y); } float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy); ghostX+=dx/len/3; ghostY+=dy/len/3; } void mouseReleased(){ for(int i=pt.size()-1;i>=0;i--){ pt.remove(i); } }
沒有留言:
張貼留言