Hi everyone,
I’d like to program a game in processing (Java) in which the player draws a possibly curved line and next makes a dot on this line. I think, I would draw the line only with pixels, not lines oder bezier-curves and maybe store the drawn pixels in an ArrayList. But there are 2 problems I’m not sure how to solve fast:
a) The line must not cross itself or any other existing line. This would mean, I have to check during the drawing if the currently drawn pixel is already stored in the ArrayList.
b) The player must place a dot or small circle somewhere on its last drawn line and only on this one. So may be I should use additionaly an ArrayList for every drawn line? And every Line consist of an ArrayList of pixels?
Are there any classic approaches to doing it somehow efficiently? Are there any mathematical approaches?
Thanks in advance, Ingo
Any tips on a suitable data structure, mathematics or source code would be great.
Addition: I tried working with only the pixels, but I get only holes where the lines intersect:
void setup() {
size(600, 400);
background(0);
stroke(255);
strokeWeight(3);
}
void draw() {}
void mouseDragged() {
if (pmouseX!=0&&pmouseY!=0) {
loadPixels();
int i=(mouseY-1)*width+mouseX;
if (brightness(pixels[i])==0) {
line(pmouseX, pmouseY, mouseX, mouseY);
}
}
}