/* ---------------------------------------------------------------- Copyright (C) 2005 Ricard Marxer Pi??n email (at) ricardmarxer.com http://www.ricardmarxer.com/ ---------------------------------------------------------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ---------------------------------------------------------------- Built with Processing (Beta) v098 uses Geomerative (Alpha) v004 ---------------------------------------------------------------- Created 24 February 2006 ---------------------------------------------------------------- stringdrils ---------------------------------------------------------------- */ import traer.physics.*; import java.util.Vector; import geomerative.*; RGroup grupo; RFont f; Vector tendrils; ParticleSystem physics; Particle mouse; //------------------------ Runtime properties ---------------------------------- // Save each frame boolean SAVEVIDEO = false; boolean SAVEFRAME = false; //------------------------------------------------------------------------------ //------------------------ Drawing properties ---------------------------------- // Text to be drawn String STRNG = "Stringdrils"; // Font to be used String FONT = "LidoSTF.ttf"; // Margin from the borders float MARGIN = 7; //------------------------------------------------------------------------------ String newString = ""; void setup(){ size(640,480); framerate(25); try{ smooth(); } catch(Exception e){ } stroke( 0 ); background(255); cursor( CROSS ); initialize(); } void draw(){ background( 255 ); translate(width/2, height/2); if(mousePressed){ mouse.moveTo( mouseX-width/2, mouseY-height/2, 0 ); for ( int i = 0; i < tendrils.size(); ++i ) { T3ndril t = (T3ndril)tendrils.get( i ); t.firstspring.turnOn(); } }else{ for ( int i = 0; i < tendrils.size(); ++i ) { T3ndril t = (T3ndril)tendrils.get( i ); t.firstspring.turnOff(); } } physics.advanceTime( 1.0f ); stroke(0); for ( int i = 0; i < tendrils.size(); ++i ) { T3ndril t = (T3ndril)tendrils.get( i ); drawElastic( t ); } if(SAVEVIDEO) saveFrame(STRNG+"video-####.tga"); } void drawElastic( T3ndril t ) { float lastStretch = 1; for ( int i = 0; i < t.particles.size()-1; ++i ) { Vector3D firstPoint = ((Particle)t.particles.get( i )).position(); Vector3D firstAnchor = i < 1 ? firstPoint : ((Particle)t.particles.get( i-1 )).position(); Vector3D secondPoint = i+1 < t.particles.size() ? ((Particle)t.particles.get( i+1 )).position() : firstPoint; Vector3D secondAnchor = i+2 < t.particles.size() ? ((Particle)t.particles.get( i+2 )).position() : secondPoint; //float springStretch = 2.5f/((Spring)t.springs.get( i )).stretch(); Spring s = (Spring)t.springs.get( i ); float springStretch = 2.5*s.restLength()/s.currentLength(); strokeWeight( (float)((springStretch + lastStretch)/2.0f) ); // smooth out the changes in stroke width with filter lastStretch = springStretch; curve( firstAnchor.x(), firstAnchor.y(), firstPoint.x(), firstPoint.y(), secondPoint.x(), secondPoint.y(), secondAnchor.x(), secondAnchor.y() ); } } void keyReleased(){ initialize(); //exit(); //saveFrame(STRNG+"-###.tga"); } void initialize(){ if(tendrils!=null){ tendrils.clear(); } if(physics!=null){ physics.clear(); } f = new RFont(this,FONT,372,RFont.CENTER); grupo = f.toGroup(STRNG); RCommand.setSegmentator(RCommand.UNIFORMLENGTH); RCommand.setSegmentLength(20); grupo = grupo.toPolygonGroup(); grupo.centerIn(g, MARGIN, 1, 1); physics = new ParticleSystem( 0.0f, 0.05f ); mouse = physics.makeParticle(); mouse.makeFixed(); tendrils = new Vector(); if(grupo!=null){ for(int k=0;k