newbie with OOP have a problem: the sketch overlap the object at every loop, not just change it.
in
Programming Questions
•
1 year ago
Hi all, I'm very new in processing, coming from arduino let's say, and I'm trying to learn the OOP.
So, i did a little object, a kind of bargraph that actually take the inputs from the mouseY, when pressed.
It work, but not properly: i can't understand why it redraw the new shape in the old one, and don't just redefines it.
Thank you all for the help.
Here the code:
- Graph myGraph;
- void setup()
- {
- size(600, 600);
- myGraph = new Graph(120, 100, 300, 200, 100);
- }
- void draw() {
- myGraph.display();
- }
- void mousePressed() {
- myGraph.mouse();
- }
- class Graph {
- color c;
- float x;
- float y;
- float base;
- float alt;
- float in1, in2, in3, in4, in5, in6;
- Graph (color col, float posx, float posy, float base1, float alt1) {
- c= col;
- x =posx;
- y = posy;
- base = base1;
- alt= alt1;
- }
- void display() {
- fill (c);
- beginShape();
- vertex(x, y+alt);
- //
- vertex(x, in6);
- vertex(x+base/5*1, in5);
- vertex(x+base/5*2, in4);
- vertex(x+base/5*3, in3);
- vertex(x+base/5*4, in2);
- vertex(x+base/5*5, in1);
- //
- vertex(x+base, y+alt);
- endShape(CLOSE);
- }
- void mouse()
- {
- in6=in5;
- in5=in4;
- in4=in3;
- in3=in2;
- in2=in1;
- in1=map (mouseY,0,height,y, y+alt);
- }
- }
1