Fail to make moving worms with cos() and axial vector>

Hey I tried to make a worm that stretches and moves across the canvas. But so far I can only make it moving in the same location although I tried to increment the positionX. Could someone help me find out what is going wrong.

var offset = 150;
var angle1 = 300;
var scalar = 40;
var speed1 = 0.2;
var speed2 = 0.2;


function setup() {
  createCanvas(1000,600);
}

function draw() {
  background(255);
  fill(0);

  for(var i=0; i< 30 ;i ++){
    push();
    var y1= offset - sin(angle1) *scalar;
    x1 = 20+i*5;
    ellipse(x1,y1,10,10);

    angle1 += speed1;
    x1 += speed2;
  }  
}
Tagged:

Answers

Sign In or Register to comment.