processing.js - how to store an object in a variable in processing -
i'm coming jquery , js , go little bit processing. because has quite reference examples etc. 1 thing can't how can store objects variable.
example jquery:
var anydiv = $('#anydiv');
and have object stored.
in processing not seem simple because has different types. can store number pretty easy:
float anynumber = 10;
or string etc. how can e.g. store new point in var?
var anypoint = point(0, 0);
thanks in advance.
objects need have classes. processing comes predefined, "point" isn't 1 of them. write point class,
class point { float x, y; point(float _x, float y) { x = _x; y = _y; } string tostring() { return x + "/" + y; } }
and can store other typed object:
point p = new point(0,0); float xcoordinate = p.x; float ycoordinate = p.y; p.x += 200; p.y += 100; println(p);
and no, capital first letter not required, that's convention. stick (don't go defining classes "point", unless you're never going show people code or ask help. make sure syntax conventions right =)
Comments
Post a Comment