-
-
Save jkwok91/4bdae13beebf35e02efc to your computer and use it in GitHub Desktop.
misha's windmill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
rotation-- misha's windmill | |
april 10th, 2014 | |
*/ | |
Windmill windmill; | |
String windStr = ""; | |
float wind = 0; | |
color grass = color(50, 100, 0); | |
void setup() { | |
size(300, 300); | |
updateWindString(); | |
windmill = new Windmill(width/2, height/3, 4); | |
} | |
void draw() { | |
background(0); | |
fill(255); | |
updateWindString(); | |
text(windStr,0,height); | |
strokeWeight(10); | |
stroke(grass); | |
noFill(); | |
curve(0, height, 0, 3*height/4, width, 3*height/4, width, height); | |
windmill.display(); | |
} | |
void mousePressed() { | |
int direction = (windmill.loc.x == mouseX) ? 0 : ((windmill.loc.x > mouseX) ? 1 : -1); | |
float windStrength = (width/2 - abs(windmill.loc.x - mouseX)); | |
wind = (windStrength/width)*direction; | |
windmill.applyForce(wind); | |
} | |
void updateWindString() { | |
windStr = "wind at "+wind+" strength!"; | |
} | |
void mouseReleased() { | |
wind = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Windmill { | |
int arms; | |
PVector loc; | |
float theta; | |
float aVel; | |
float aAcc; | |
float mass; | |
float armW, armH; | |
float baseW, baseH; | |
Windmill(float x, float y, int numArms) { | |
arms = numArms; | |
mass = numArms*10; //idk i just made up something | |
loc = new PVector(x, y); | |
armW = 50; | |
armH = 15; | |
baseW = 30; | |
baseH = 125; | |
theta = 0; | |
aVel = 0; | |
aAcc = 0; | |
} | |
void display() { | |
strokeWeight(2); | |
stroke(0); | |
fill(255); | |
displayBody(); | |
displayArms(); | |
} | |
void displayBody() { | |
//building | |
rect(loc.x-baseW/2, loc.y, baseW, baseH); | |
fill(255,255,0); | |
//window1 | |
rect(loc.x-baseW/4, loc.y+5*baseH/16, baseW/2, baseH/8); | |
line(loc.x, loc.y+5*baseH/16, loc.x, loc.y+7*baseH/16); | |
line(loc.x-baseW/4, loc.y+3*baseH/8, loc.x+baseW/4, loc.y+3*baseH/8); | |
//window2 | |
rect(loc.x-baseW/4, loc.y+baseH/2, baseW/2, baseH/8); | |
line(loc.x, loc.y+baseH/2, loc.x, loc.y+5*baseH/8); | |
line(loc.x-baseW/4, loc.y+9*baseH/16, loc.x+baseW/4, loc.y+9*baseH/16); | |
//door | |
rect(loc.x-baseW/4, loc.y+3*baseH/4, baseW/2, baseH/4); | |
} | |
void displayArms() { | |
fill(200,0,0); | |
pushMatrix(); | |
translate(loc.x, loc.y); | |
for (int i = 0; i < arms; i++) { | |
pushMatrix(); | |
rotate(theta+(TWO_PI/arms)*i); | |
rect(0, 0, armW, armH); | |
popMatrix(); | |
} | |
popMatrix(); | |
aVel += aAcc; | |
aVel = (abs(aVel*0.999) < 0.002) ? 0 : aVel*0.999; | |
theta += aVel; | |
aAcc = 0; | |
} | |
void applyForce(float f) { | |
float acceleration = f/mass; | |
aAcc += acceleration; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment