Hi everyone, I have a source code which has moving planets on an orbit. I would like to draw lines between two of them (like draw lines between Earth and Jupiter). Here is an example I found on Youtube: https://www.youtube.com/watch?v=wvfza7r-EiU
Hi, I thought that you could save the positions of the lines with an ArrayList and then draw them with a for loop …
But I think that pulls a lot of power …
@Flolo yes, that approach would probably work, but there is actually a way to fix the efficiency issue you mentioned, which could really turn out to be quite problem.
You can create a PGraphics object onto which you draw all the lines, seperately from the planets. In code, this would look something like this:
PGraphics lines;
//other global variables
void setup() {
//size() and other setup stuff
lines = createGraphics(width, height);
lines.beginDraw();
lines.background(0);
lines.endDraw();
}
void draw() {
//move planets around
lines.beginDraw();
lines.stroke(255);
lines.strokeWeight(2);
lines.line(x1, y1, x2, y2); //drawing a line from (x1, y1) to (x2, y2)
lines.endDraw();
image(lines, 0, 0);
//draw planets
}