- 履歴一覧
- ソース を表示
- Processing/4.クラスの利用/4-2.Fisicaの図形の描き方 は削除されています。
4-2 Fisicaの図形の描き方†
import fisica.*;
FWorld world;
MyBall ball1, ball2;
class MyBall extends FCircle{
MyBall( float r ){
super( r );
}
public void draw(PGraphics applet) {
preDraw(applet);
if (m_image != null ) {
drawImage(applet);
} else {
applet.ellipse(0, 0, getSize(), getSize());
applet.fill( 0 );
applet.ellipse( getSize()/3, 0, 3, 3 );
}
postDraw(applet);
}
}
void setup(){
size(600,300);
Fisica.init(this);
world = new FWorld();
world.setEdges();
world.setEdgesFriction( 0 );
ball1=new MyBall(40);
ball1.setDamping( 0 );
ball1.setDensity( 2 );
ball1.setFriction( 0.1 );
ball1.setRestitution( 1 );
ball1.setPosition( 50, 274.5 );
ball1.setGrabbable( false );
ball1.setFill( 128, 255, 128 );
world.add( ball1 );
ball2=new MyBall(40);
ball2.setDamping( 0 );
ball2.setDensity( 4 );
ball2.setFriction( 0.1 );
ball2.setRestitution( 1 );
ball2.setPosition( 200, 274.5 );
ball2.setGrabbable( false );
ball2.setFill( 255, 128, 128 );
world.bottom.setFill(128);
world.top.setFill(128);
world.left.setFill(192);
world.right.setFill(192);
world.bottom.setStroke(128);
world.top.setStroke(128);
world.left.setStroke(192);
world.right.setStroke(192);
world.add( ball2 );
}
void mouseClicked(){
if( dist( mouseX, mouseY, ball1.getX(), ball1.getY()) < ball1.getSize() ){
ball1.addImpulse( ball1.getMass()*200, 0, mouseX-ball1.getX(), mouseY-ball1.getY() );
}
}
void draw(){
background(0);
world.step();
world.draw();
}