2016年3月24日 星期四

Week5 LeapMotion會轉動的眼睛

今天我們要做的是會轉動的眼睛和螺旋動畫,

首先,我們要做的是會自動轉動的眼睛,


完整程式碼:
void setup(){ size(120,100); } void draw(){ float t = frameCount/180.0*PI; background(0); fill(255); ellipse(40,50, 33,33); ellipse(120-40,50, 33,33); fill(0); ellipse(40+15*cos(t),50+15*sin(t), 5,5); ellipse(120-40+15*cos(t),50+15*sin(t), 5,5); }


第二個要做的是用滑鼠控制的眼睛,滑鼠動到哪眼睛就看向哪,


完整程式碼:
void setup(){ size(320,300); } void draw(){ //float t = frameCount/180.0*PI; background(0); fill(255); ellipse(40,50, 33,33); ellipse(120-40,50, 33,33); fill(0); float t=atan2(mouseY-50,mouseX-45); ellipse(40+15*cos(t),50+15*sin(t), 5,5); t=atan2(mouseY-50,mouseX-(120-40)); ellipse(120-40+15*cos(t),50+15*sin(t), 5,5); }


再來我們要做的是一個對向的螺旋動畫,


完整程式碼:
void setup(){ size(600, 600); } void draw(){ //float t = frameCount/180.0*PI; background(255); float t=frameCount/100.0; for (float f=0; f<PI; f+=0.1) { rect(200+150*cos(f+t), f*100, 30, 30); rect(200+150*cos(f+t+PI), f*100, 30, 30); } }

沒有留言:

張貼留言