I'm making a program that you can draw in and when there are more than 38000 _points it starts to lag.
here's the code:
public class _point {
float x = 0;
float y = 0;
boolean active = true;
color c = color(255, 255, 255);
public void _point() {
}
public void change_pos(float x1, float y1, color c1)
{
x = x1;
y = y1;
c = c1;
}
public void u_line(float px, float py)
{
if (dist(x, y, px, py) < 15)
{
stroke(c);
strokeWeight(5);
line(x, y, px, py);
}
}
public void remove_beans()
{
if (eraser) {
if (dist(x, y, mouseX, mouseY)<main_tool.radius/2) {
active = false;
}
}
}
public void a_line()
{
for (int i = 0; i < _points.size(); ++i) {
_point part = _points.get(i);
if (dist(x, y, part.x, part.y) < 15)
{
line(x, y, part.x, part.y);
}
}
}
}
and where its drawn:
ArrayList<_point> _points = new ArrayList<_point>();
void draw_beans() {
for (int i = 0; i < _points.size(); ++i) {
_point part = _points.get(i);
if (part.active == false) {
_points.remove(i);
}
if (i != 0 && i != _points.size()-1 && i != _points.size()) {
OPTIMIZE(_points.get(i+1), part, _points.get(i-1));
}
if (i != 0) {
_point past = _points.get(i-1);
part.u_line(past.x, past.y);//past.x,past.y
}
}
}
this is were the points are added to the array:
void add_beans() {
if (!eraser && !IIIINNZ()) {
_points.add(new _point());
_point part = _points.get(_points.size()-1);
part.change_pos(mouseX-transX, mouseY-transY, color(int(color_text0.texts), int(color_text1.texts), int(color_text2.texts)));
}
for (int i = 0; i < _points.size(); ++i) {
if (eraser && !IIIINNZ()) {
_point part = _points.get(i);
part.remove_beans();
}
}
}
and an optimization:
void OPTIMIZE(_point next, _point thiss, _point prev) {
if (dist(thiss.x, thiss.y, next.x, next.y)+dist(thiss.x, thiss.y, prev.x, prev.y)<14) {
thiss.active = false;
}
}
setup:
void setup() {
size(512, 512);
noCursor();
}
draw:
void draw() {
background(#222833);//27,27,33
textFont(font);
pushMatrix();
translate(transX, transY);
draw_beans();
popMatrix();
show_options();
main_tool.update();
println(_points.size());
}
I have tried to multithread it but the thread doesn't align with the animation thread so there are missing points.
I am using the Processing 3 java library and vscode.