Draw a spiral with noise added to line

edited April 2014 in How To...

Hello, I am trying to create a sketch that spirals outwards but the line being drawn has noise added to it - the result being a random (wiggly) line that vaguely follows a spiral path. If anyone can point me in the right direction that would be great! Thanks.

Here is the code I am using to draw a spiral:

float r = 0;
float theta = 0;

void setup() {
  size(800, 800);
  background(255);
  frameRate(100);
  smooth();
}

void draw() {
  float x = r * cos(theta);
  float y = r * sin(theta);
  noStroke();
  fill(0);
  ellipse(x + width/2, y + height/2, 20, 20); 

  theta += 0.01;

  r=r+0.09;
}

Answers

  • Answer ✓
    float r = 0;
    float theta = 0;
    
    void setup() {
      size(800, 800);
      background(255);
      //frameRate(100);
      smooth();
    }
    
    float offset = .5;
    
    void draw() {
      for(int t=0; t<100; t++){
      float x = (r + offset) * cos(theta);
      float y = (r + offset) * sin(theta);
      noStroke();
      fill(0);
      ellipse(x + width/2, y + height/2, 20, 20); 
    
      theta += 0.01;
    
      offset+=random(-1,1);
    
      r=r+0.09;}
    }
    
Sign In or Register to comment.