We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Classes, objects, and Traer
Page Index Toggle Pages: 1
Classes, objects, and Traer (Read 466 times)
Classes, objects, and Traer
Oct 6th, 2009, 10:17pm
 
Hello,
Having mucho problem with my "next step" in learning about classes and particle systems.
Here is my code so far (Giving me an error).
My hope was to take this thingy http://openprocessing.org/visuals/?visualID=5032 (haven't used openProcessing in a while), and make it broader in order to learn more about particle systems and classes.  i.e. extend from multiple points across screen and be drawn towards mouse/wrap it up.
But yeah, I think I've either seriously misunderstood a key concept or b) approached the solution using the wrong tools.  Please help!

Tendril_try3
Code:

import traer.physics.*;

tenSys tens;
Tendril[] ten;




void setup(){  
 size(640,480);
 background(#6CA5D6);
 smooth();
 colorMode(HSB);
 
 ten = new Tendril[20];
 
 for(int i = 0; i < ten.length; i++){
   ten[i].setTendril(i*30, 0, 0);
 }  
}

void draw(){
  physics.tick( 1.0 );
  tens.updateMouse();
  stroke(#000000);

 for(int i = 0; i < ten.length; i++) {
  line( ten[i].ten1.position().x(), ten[i].ten1.position().y(),
        ten[i].ten2.position().x(), ten[i].ten2.position().y());
       }
 
}

void mouseClicked(){
  saveFrame("p" + month() + day() + hour() + minute() + second() + ".png");
}


TenSys
Code:
Super Class tenSys{
  ParticleSystem physics;
  Particle mouse;
 
 tenSys(){
 physics = new ParticleSystem( 0, 0.1);
 mouse = physics.makeParticle();
 mouse.makeFixed();
 }

 void updateMouse(){
    mouse.position().set( mouseX, mouseY, 0);
 }  
 
}


Tendril
Code:
class Tendril extends tenSys{
 
 Particle ten1;
 Particle ten2;
 
 Spring spring;
 
 Tendril(){
 ten1 = physics.makeParticle(1.0, 0, 0, 0);
 ten2 = physics.makeParticle(1.0, 0, 0, 0);
 mouse.makeFixed();

 physics.makeSpring( ten1, ten2, 0.01, 0.02, 100.0 );
 physics.makeAttraction( ten1, ten2, -10000, 2.0 );
 physics.makeAttraction( ten1, mouse, 1000, 50 );
 physics.makeAttraction( ten2, mouse, 1000, 50 );
 }
 
 void drawTendril(){
  stroke(#000000);
  line( ten1.position().x(), ten1.position().y(), ten2.position().x(), ten2.position().y());
   
 }
 
 void setTendril(float x, float y, float z){
  ten1.position().set( x, y, z );    
  ten2.position().set( x, y, z );    
 }
 
 
}
Re: Classes, objects, and Traer
Reply #1 - Oct 6th, 2009, 10:48pm
 
You've got some instance creation issues.  When you create an object of any class type, it needs to be created individually:

 for(int i = 0; i < ten.length; i++){
   ten[i]=new Tendril();
   ten[i].setTendril(i*30, 0, 0);
 }

And the tenSys "tens" hasn't been created at all, so that needs to happen:

 tens = new tenSys();

Super Class tenSys ==> "class tenSys" like any other...and it shouldn't own the ParticleSystem; that should probably be global, before setup():

  ParticleSystem physics;
  Particle mouse;

Whether this will now do what you want, I don't know, but it should run... -- Ben
Page Index Toggle Pages: 1