Created
November 13, 2013 13:05
-
-
Save dimkir/7448787 to your computer and use it in GitHub Desktop.
Created using Sketch2Tweet tool
This file contains hidden or 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
Liquid liquid; | |
Surface srf; | |
int C_BALL_COUNT = 10; | |
int C_LIQUID_WIDTH = 300; | |
int C_LIQUID_HEIGHT = 50; | |
Ball[] balls = new Ball[C_BALL_COUNT]; | |
PVector forceDownward = new PVector(0.0, 0.03); // just going down | |
void setup(){ | |
size(displayWidth/2, displayHeight/2); | |
liquid = new Liquid(width/2, height/2, C_LIQUID_WIDTH, C_LIQUID_HEIGHT, 0.1); | |
srf = new Surface(); | |
initBalls(balls); | |
} | |
void draw(){ | |
background(128); | |
balls_update(liquid); | |
liquid.display(); | |
balls_display(); | |
} | |
void initBalls(Ball[] balls){ | |
for(int i = 0 ; i < balls.length ; i++){ | |
balls[i] = new Ball(random(width), random(height/4), random(5,10) ,random(10,30)); | |
} | |
} | |
void balls_update(Liquid l){ | |
for(Ball b: balls){ | |
b.applyForce(forceDownward); // this should be gravity force applied. But how do we calculate this force? For simplicity I can just apply simple constant force (alike to the wind). | |
//b.applyDrag(l); | |
if ( liquid.intersectsWith(b) ){ | |
//println(b + " intersects with liquid"); | |
b.applyFriction(srf); | |
} | |
b.update(); | |
} | |
} | |
void balls_display(){ | |
for(Ball b : balls){ | |
b.display(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is comment with sketch screenshot url: