line breaking up becuase of rotate(), how to keep them connected?
in
Programming Questions
•
2 years ago
Hi
If you play the sketch, you will see that the lines are breaking up when you draw. What need to be done that they stay connected?
thanks!
If you play the sketch, you will see that the lines are breaking up when you draw. What need to be done that they stay connected?
- int num = 0;
- Dot[] d = new Dot [10000000];
- boolean drag = false;
- void setup(){
- size(600,600);
- smooth();
- }
- void draw(){
- background(255);
- for(int i = 0; i < num; i++){
- d[i].Line();
- //d[i].breakUp();
- }
- if(drag){
- num++;
- d[num-1] = new Dot(mouseX-width/2, mouseY-height/2,
- pmouseX-width/2,pmouseY-height/2);
- }
- }
- class Dot{
- int x,y,X,Y;
- float r;
- Dot(int x, int y, int X, int Y){
- this.x = x; this.y = y;
- this.X = X; this.Y = Y;
- }
- void breakUp(){
- x += random(-1,2); y += random(-1,2);
- X += random(-1,2); Y += random(-1,2);
- }
- void Line(){
- pushMatrix();
- translate(width/2, height/2);
- rotate(r);
- stroke(0);
- strokeWeight(1);
- beginShape();
- vertex(x,y);
- vertex(X,Y);
- endShape();
- popMatrix();
- r += 0.05;
- }
- }
- void mousePressed(){ drag = true; }
- void mouseReleased(){ drag = false; }
thanks!
1