You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to make a gui where the plot changes as time goes on. The problem is the only way to do it is to continually draw plots on top of each other. This makes it so that the program has over a thousand identical plots and it cannot work anymore. There needs to be a way to close a plot and then redraw it so it doesn't take up all of memory.
I tested your program and it runs fine on my laptop, with no memory problems.
Note that each time you draw the plot inside the draw method you are not creating a new plot object,
so this should not add up to the memory. You are however adding a new point to the points
arrays inside the plot object, so this could have some effect on the memory, but it should be minimal.
My recommendation is that you could control the total number of points that are drawn, setting a
maximum number of points. For example, you can define a global variable:
int maxPoints = 5000;
and then add this if at the end of the draw method:
if (nPoints > maxPoints){
plot.removePoint(0);
nPoints--;
}
That will remove the oldest (first) point in the current array.
I'm trying to make a gui where the plot changes as time goes on. The problem is the only way to do it is to continually draw plots on top of each other. This makes it so that the program has over a thousand identical plots and it cannot work anymore. There needs to be a way to close a plot and then redraw it so it doesn't take up all of memory.
import controlP5.;
import grafica.;
ControlP5 cp5;
int nPoints = 0;
String textValue = "";
GPlot plot;
void setup() {
size(700, 900);
PFont font = createFont("arial", 20);
cp5 = new ControlP5(this);
cp5.addTextfield("drops")
.setPosition(150, 100)
.setSize(100, 40)
.setFont(font)
.setFocus(true)
.setAutoClear(false);
cp5.addTextfield("time in secs")
.setPosition(300, 100)
.setSize(100, 40)
.setFont(font)
.setAutoClear(false);
cp5.addBang("Deliver Water")
.setPosition(450, 100)
.setSize(100, 40)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER);
//textFont(font);
//intro();
plot = new GPlot(this);
plot.getXAxis().setAxisLabelText("x axis");
plot.getYAxis().setAxisLabelText("y axis");
plot.setPos(100, 400);
}
void draw () {
//plot.setPoints(points);
plot.beginDraw();
plot.drawBackground();
plot.drawBox();
plot.drawXAxis();
plot.drawYAxis();
plot.drawTopAxis();
plot.drawRightAxis();
plot.drawTitle();
plot.getMainLayer().drawPoints();
plot.endDraw();
plot.addPoint(float(nPoints),float(nPoints),"pt" + nPoints);
nPoints++;
//delay(500);
}
void generatePlot(){
}
void controlEvent(ControlEvent theEvent) {
println(theEvent.getName());
println(cp5.get(Textfield.class, "drops").getText());
println(cp5.get(Textfield.class, "time in secs").getText());
}
The text was updated successfully, but these errors were encountered: