/* autogenerated by Processing revision 1286 on 2026-03-10 */
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class MapBrush extends PApplet {

//JFD 2026

//=====================================

float[] x = new float[1];
float[] y = new float[1];
int[] c = new int[1];
PVector[] p = new PVector[1];

int[] stepCounter = new int[1];
int[] nextMarker = new int[1];

ArrayList historyGlobal;
ArrayList markers;   // alle Ortsmarken

 public void setup() {
  /* size commented out by preprocessor */;
  colorMode(HSB, 360, 100, 100);
  background(0);

  x[0] = random(width/2);
  y[0] = random(height/2);
  c[0] = color(random(30, 330), random(30, 330), random(30, 330));
  p[0] = new PVector(random(0, 1), random(-1, 1));

  stepCounter[0] = 0;
  nextMarker[0] = PApplet.parseInt(random(300, 1000));

  historyGlobal = new ArrayList();
  historyGlobal.add(new ArrayList());

  markers = new ArrayList();
}

 public void draw() {

  // zuerst nur Linien und Wege zeichnen
  for (int i = 0; i < x.length; i++) {

    // Bewegung
    p[i].x += random(-0.2f, 0.2f);
    p[i].y += random(-0.2f, 0.2f);

    p[i].x = constrain(p[i].x, -1, 1);
    p[i].y = constrain(p[i].y, -1, 1);

    x[i] += p[i].x;
    y[i] += p[i].y;

    x[i] = constrain(x[i], 0, width);
    y[i] = constrain(y[i], 0, height);

    strokeWeight(1);
    stroke(c[i], random(20, 70));

    ArrayList history = (ArrayList) historyGlobal.get(i);

    for (int ii = 0; ii < history.size(); ii++) {
      PVector histP = (PVector) history.get(ii);

      if (dist(x[i], y[i], histP.x, histP.y) < 15) {
        line(x[i], y[i], histP.x, histP.y);
      }
    }

    history.add(new PVector(x[i], y[i]));

    // Schritte zählen
    stepCounter[i]++;

    // neuen Marker nur speichern, nicht direkt zeichnen
    if (stepCounter[i] >= nextMarker[i]) {
      markers.add(new PVector(x[i], y[i]));
      nextMarker[i] += PApplet.parseInt(random(300, 1000));
    }
  }

  // danach alle Ortsmarken OBEN drüber zeichnen
  stroke(0);
  strokeWeight(1);
  fill(0, 100, 100);   // rot in HSB

  for (int i = 0; i < markers.size(); i++) {
    PVector m = (PVector) markers.get(i);
    ellipse(m.x, m.y, 10, 10);
  }
}

 public void mousePressed() {
  x = append(x, mouseX);
  y = append(y, mouseY);
  c = append(c, color(random(30, 330), random(30, 330), random(30, 330)));

  PVector newP = new PVector(random(0, 1), random(-1, 1));
  p = (PVector[]) append(p, newP);

  stepCounter = append(stepCounter, 0);
  nextMarker = append(nextMarker, PApplet.parseInt(random(300, 1000)));

  historyGlobal.add(new ArrayList());
}


  public void settings() { size(800, 450); }

  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "--full-screen", "--bgcolor=#050505", "--hide-stop", "MapBrush" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
