Simulate mouseX and mouseY
in
Programming Questions
•
2 years ago
Hey,
I just have this code and to draw all the lines I use mouseX and mouseY.
Now I just want to start the programm and see how the lines grow without using the mouse. Do you have any experience how to simulate mouseX and mouseY? I tried to use random, but this does not give a nice effect at all.
- ArrayList history = new ArrayList();
- float distthresh = 60;
- float factor = 2;
- void setup() {
- size(800,500);
- background(255);
- smooth();
- }
- void draw() {
- stroke(0,random(100,200));
- strokeWeight (random(0.2,0.8));
- strokeCap (SQUARE);
- strokeJoin(MITER);
- animate();
- }
- void animate() {
- PVector d = new PVector(mouseX,mouseY,0);
- history.add(0,d);
- for (int p=0; p<history.size(); p++) {
- PVector v = (PVector) history.get(p);
- float joinchance = p/history.size() + d.dist(v)/distthresh;
- if (joinchance < random(0.5,factor)) line(d.x,d.y,v.x,v.y);
- }
- }
- void keyPressed() {
- if (key == 'c') {
- background(255);
- history.clear();
- }
- }
1