Drawing brownian lines from multiple points
in
Programming Questions
•
1 month ago
Hello,
I have recently been working on a small Processing-project, but I've got to a point where I'm pretty stuck...
The idea is that I have a group of points (extracted from an .svg file with the Geomerative library - the problem has nothing to do with the library, and therefore I posted it in this forum), from which I all want to draw brownian lines simultaneously.
I got to the point where I can draw a brownian line from any one point, but not from all at the same time. I think there's a small problem with the way I used the double for-loop, but I'm not sure...
I hope that someone could help me out. I will add my code below.
Thank you in advance.
- import geomerative.*;
- import java.util.Calendar;
- import processing.pdf.*;
- //boolean doSave = false;
- RShape grp;
- RPoint[] pt;
- int num = 2000;
- int range = 6;
- float[] ax = new float[num];
- float[] ay = new float[num];
- void setup(){
- size(1280,960);
- frameRate(30);
- smooth();
- RG.init(this);
- grp = RG.loadShape("test_v1.svg");
- RG.setPolygonizer(RG.ADAPTATIVE);
- //grp.draw();
- RG.setPolygonizer(RG.UNIFORMLENGTH);
- RG.setPolygonizerLength(10);
- pt = grp.getPoints();
- //println(points.length);
- for(int j = 0; j < pt.length; j++) {
- for(int i = 0; i < num; i++) {
- ax[i] = pt[j].x;
- ay[i] = pt[j].y;
- }
- }
- }
- void draw(){
- background(51);
- if(pt != null){
- fill(255);
- for(int i=0; i<pt.length; i++){
- ellipse(pt[i].x, pt[i].y,1,1);
- }
- }
- for(int i=1; i < num; i++) {
- ax[i-1] = ax[i];
- ay[i-1] = ay[i];
- }
- ax[num-1] += random(-range,range);
- ay[num-1] += random(-range,range);
- ax[num-1] = constrain(ax[num-1],0,width);
- ay[num-1] = constrain(ay[num-1],0,height);
- for(int i=1; i<num; i++) {
- float val = float(i)/num * 204.0 + 51;
- stroke(val);
- line(ax[i-1],ay[i-1],ax[i],ay[i]);
- }
- }
1