ハンドスピナー

float W = 200;float H = 200;float angle=0;float strength = 0;int status = 0;PVector mouseInitPosition;
void setup(){ size(600, 400);}
void draw(){ background(0); if(status == 1){ PVector mousePosition = new PVector(mouseX, mouseY); strength = mousePosition.sub(mouseInitPosition).mag() * 0.1; } strength *= 0.98; angle += strength; drawImage(width/2, height/2, W, H, angle);}
void mousePressed(){ boolean isDown = false; if(mouseX >= width/2 - W / 2 && mouseX <= width / 2 + W / 2){ if(mouseY >= height/2 - H / 2 && mouseY <= height / 2 + H / 2){ isDown = true; } } if(isDown){ if(status == 0){ mouseInitPosition = new PVector(mouseX, mouseY); status = 1; } }}
void mouseReleased(){ status = 0;}
void drawImage(float x, float y, float w, float h, float angle){ pushMatrix(); translate(x, y); rotate(radians(angle)); rectMode(CENTER); rect(0, 0, w, h); popMatrix();}課題1
ハンドスピナーの画像を適用しよう。
課題2
めっちゃよく回るようにしよう。