FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   reusing classes
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: reusing classes  (Read 418 times)
kevinP

Email
reusing classes
« on: Feb 23rd, 2004, 7:57pm »

Hi,
 
I don't think that Processing offers any "Point objects", etc. Is it useful to use classes such as "Point"? If so, is there a way I can reuse such a class in various sketches?
 
Or is there a better way to handle such things? I'm trying, for example, to implement the Cohen_Sutherland clipping algorithm out of an openGL textbook and to do this I need to store my endpoints in a simple and practical way.
 
I suppose I could use an array, but then to display a point I have to write:
 
point(p1[0], p1[1]);
 
I think that "p1.display()" would be simpler.
 
Anyhow, back to original question - is there an easy way to reuse classes here?
 
Thanks in advance,
 
-K
 
 
« Last Edit: Feb 23rd, 2004, 7:58pm by kevinP »  

Kevin Pfeiffer
toxi

WWW
Re: reusing classes
« Reply #1 on: Feb 24th, 2004, 4:34pm »

k, at the moment you would have to copy & paste the source from one sketch into another. i do this all the time. or you write and compile classes outside the PDE and then chuck the files into the /code folder inside the sketch folder. i believe in future there'll be support for doing this all from within the PDE... but don't quote me on that!
 

http://toxi.co.uk/
amoeba

WWW
Re: reusing classes
« Reply #2 on: Feb 24th, 2004, 7:08pm »

Hi kevin,
 
I wrote the classes Vec2D and Vec3D to deal with 2d and 3d vectors, but they also excel at storing "points".  
 
From an OOP point of view, p1.display() is much nicer than point(p1[0],p1[1]), but the logic to do that should be in your classes anyway. Think about it, the whole point about making a class is to abstract a general concept. Specific issues like how to draw the points etc. belong in more specific classes that are descendants of the general one.
 
So if you wanted to do that with the Vec2D class above, simply do the following:
 
Code:
class Point2D extends Vec2D {
  void display() {
    // x and y are defined in Vec2D
    point(x,y);
  }
}

 
As for reuse, either copy'n'paste or make .class files as toxi says.
« Last Edit: Feb 24th, 2004, 7:08pm by amoeba »  

marius watz // amoeba
http://processing.unlekker.net/
kevinP

Email
Re: reusing classes
« Reply #3 on: Feb 24th, 2004, 10:30pm »

Hi,
 
Thanks to both for answers; I'll look at the Vec classes. Toxi wrote:
"or you write and compile classes outside the PDE and then chuck the files into the /code folder inside the sketch folder."
 
This means I write the class and compile it with javac oder? What I can then do which I think will work fine is place these in a sort of lib folder; thereafter I only need add a soft link inside the code folder for each sketch (I already do this with fonts).
 
Actually it might be nice if the properties config already did this for me (an automatic link in each data folder) when starting a new sketch.
 
 
 
 
 
 
 

Kevin Pfeiffer
toxi_
Guest
Email
Re: reusing classes
« Reply #4 on: Feb 24th, 2004, 11:29pm »

this folder exists and is called "code", inside your sketch folder. you'll not need any "link" or includes for classes in that folder.
 
kevinP

Email
Re: reusing classes
« Reply #5 on: Feb 26th, 2004, 12:31am »

on Feb 24th, 2004, 11:29pm, toxi_ wrote:
this folder exists and is called "code", inside your sketch folder. you'll not need any "link" or includes for classes in that folder.

 
No I was just thinking that I could keep one instance of a class in a general-purpose folder and would need only a symbolic link inside the code folder. That way avoid having twenty copies of the same class spread out in different sketch folders.
 

Kevin Pfeiffer
Pages: 1 

« Previous topic | Next topic »