import traer.physics.*; ParticleSystem physics; Particle p; Particle anchor; Spring s; PFont f; int kolor1=20,kolor2=200,kolor3=180; int points=0; void setup() { size( 400, 400 ); smooth(); //fill( 60 ); frameRate( 24 ); colorMode(RGB, 255, 255, 255, 50); ellipseMode( CENTER ); physics = new ParticleSystem( 2.0, 0.10 ); p = physics.makeParticle( 1.0, width/2-100, height/2, 0 ); anchor = physics.makeParticle( 1.0, width/2, height/2, 0 ); anchor.makeFree(); //s = physics.makeSpring( p, anchor, 1.0, 0.1, 100 ); f = loadFont("CourierNew36.vlw"); textFont(f, 16); } void draw() { int pos_x,pos_y; pos_x=int(p.position().x()); pos_y=int(p.position().y()); int bad; bad=0; if ( !mousePressed ) physics.advanceTime( 0.5 ); else { p.moveTo( mouseX, mouseY, 0 ); p.setVelocity( (mouseX - pmouseX), (mouseY - pmouseY), 0 ); // this is so you can throw it... } // If we cross the line - back to start. if (mouseX > 300 ) { bad=1; } else { // If we hit the square if ((p.position().x() > 350 ) && (p.position().x() < 400) && (p.position().y() > 150 ) && (p.position().y() < 200 ) ) { bad=2; } else { // y axis outside window if (p.position().y() > height ) { bad=3; } } } background( 255 ); fill(120,100,50); rect(350,150,50,50); line(300,0,300,400); fill(0,0,0); text("Mass:"+p.mass(),5,20); text("Press Z/X to -/+ mass",96,20); text("Throw the ball to the square",10,390); text("Points: "+points,305,390); if (keyPressed){ // if ((p.mass()==-1) || (p.mass()==1 )) // { //p.setMass(1); //} if (key=='z') { if (p.mass()==1 ) { p.setMass(-2); } else { p.setMass(p.mass()-1); } } if (key=='x') { if (p.mass()==-1 ) { p.setMass(2); } else { p.setMass(p.mass()+1); } } } if ( bad == 0 ) { fill(kolor1,kolor2,kolor3); ellipse( p.position().x(), p.position().y(), 20, 20 ); } else { if ( bad == 1 ) { // cross the line pos_x=100; pos_y=200; fill(kolor1,kolor2,kolor3); text("DO NOT CROSS THE LINE",50,350); ellipse( pos_x, pos_y, 20, 20 ); p.moveTo( pos_x, pos_y, 0 ); p.setVelocity( 0, 0, 0 ); // stop velocity kolor1=int(random(1,250)); kolor2=int(random(1,250)); kolor3=int(random(1,250)); } else if ( bad == 2 ) { // ball hit in square pos_x=100; pos_y=200; fill(kolor1,kolor2,kolor3); ellipse( pos_x, pos_y, 20, 20 ); p.moveTo( pos_x, pos_y, 0 ); p.setVelocity( 0, 0, 0 ); // stop velocity kolor1=int(random(1,250)); kolor2=int(random(1,250)); kolor3=int(random(1,250)); points++; } else if ( bad == 3 ) { // Ball outside y axis pos_x=100; pos_y=200; fill(kolor1,kolor2,kolor3); ellipse( pos_x, pos_y, 20, 20 ); p.moveTo( pos_x, pos_y, 0 ); p.setVelocity( 0, 0, 0 ); // stop velocity kolor1=int(random(1,250)); kolor2=int(random(1,250)); kolor3=int(random(1,250)); } } { } //line( p.position().x(), p.position().y(), anchor.position().x(), anchor.position().y() ); // ellipse( anchor.position().x(), anchor.position().y(), 100, 1 ); } // www.pestka.org