Skip to content

Instantly share code, notes, and snippets.

@dimkir
Created November 13, 2013 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimkir/7448787 to your computer and use it in GitHub Desktop.
Save dimkir/7448787 to your computer and use it in GitHub Desktop.
Created using Sketch2Tweet tool
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();
}
}
@dimkir
Copy link
Author

dimkir commented Nov 13, 2013

This is comment with sketch screenshot url: imge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment