I’m using processing, and I’m curious how to access the properties of a primitive. The reference gives parameters for constructing these primitives, but no info on properties. For example (I’m trying to do something more complicated than this, but this will work for simplicity), if I create a line with a changing length, is there a way to print that line’s length:
int lineLength = 0;
void draw(){
line(random(0,50),random(0,50),lineLength,lineLength);
lineLength++;
printLn(line.length);
}
I’m not sure what you mean by “primitive”. If you mean the drawing functions (e.g.
point(),line(),triangle(),rect(),ellipse(),beginShape(),endShape(),vertex(),etc.), then these are simply functions that deal with rendering a shape on screen once with the passed arguments/parameters. After you call the function, the parameters are lost, unless they’re stored in variables somewhere.For example, a line is defined by two points, so you could store/modify those at will and simply render when needed:
Just because there isn’t a Line class defined in Processing already doesn’t mean you can’t whip out your own version to do exactly what you need it to do:
You can also use libraries that offer this sort of functionality of course, like toxiclibs for example.
HTH