import sms.*; import traer.physics.*; ParticleSystem physics; Particle[] particles; int NumOfParticles = 80; PFont font; float x, y, vx, vy; int smsx, smsy= 0; String msg ="かたむけてみて!"; float bdLeft,bdRight,bdTop,bdBottom; void setup(){ smooth(); size( 600, 400 ); /*** * Load font ***/ font = loadFont( "AxisStd-Light-18.vlw" ); textFont( font ); textAlign( CENTER ); /*** * maximum and minimum value of paticle position ***/ bdLeft = textWidth( msg )/2; bdRight = width - textWidth( msg )/2; bdTop = 14; bdBottom = height; /*** * Setup Particle System ***/ physics = new ParticleSystem( 5.0, 0.05 ); particles = new Particle[ NumOfParticles ]; for ( int i = 0; i < particles.length; i++ ){ particles[i] = physics.makeParticle( 1.0, random( bdLeft, bdRight ), random( bdTop, bdBottom ), 0 ); particles[i].setMass( random( 0.3, 12.0 ) ); } } void draw(){ background( 255 ); fill( 0, 88, 20,99 ); physics.advanceTime( 1.2 ); /*** * Get SMSX and SMSY. Set Gravity ***/ smsx = -Unimotion.getSMSX(); smsy = Unimotion.getSMSY(); if(abs(smsx) < 15) smsx = 0; if(abs(smsy) < 15) smsy = 0; physics.setGravity( smsx*0.006, smsy*0.006, 0.0 ); /*** * Get poisitions. Write msgs; ***/ for ( int i = 0; i < particles.length; i++ ){ x = particles[i].position().x(); y = particles[i].position().y(); vx = particles[i].velocity().x(); vy = particles[i].velocity().y(); handleBoundaryCollisions( particles[i] ); text( msg, x, y ); } } void handleBoundaryCollisions( Particle p ){ if( x > bdRight || x < bdLeft) p.setVelocity( -0.99*vx, vy, 0.0 ); if( y > bdBottom || y < bdTop) p.setVelocity( vx, -0.99*vy, 0.0 ); p.moveTo( constrain( p.position().x(), bdLeft, bdRight ), constrain( p.position().y(), bdTop, bdBottom ), 0 ); }