If Else Statements.

Hi everyone pretty new to processing, just experimenting with the very little knowledge I have, but I've run into a problem.

function setup() {
  createCanvas(600,600);
  background(0);
}

//speed variable
s=5

//edge location setup
x=0
y=0

function draw() {
  stroke(255);

//line object
  line (x,y,mouseX,mouseY);

//animating line origin

if (x<width; y<1) {x=+s};
if (x>width; y<height) {x=width; y=y+s};
if (x>width; y>height) {x=-s};

}

The idea for the sketch is to have a line's origin move along the edge of the canvas each frame and end point at the mouse position. I have successfully accomplished this with the first two edges, but Ive run into trouble with getting the variables to contradict themselves and go the opposite way.

My problems are with IF statements. I know the syntax is wrong here because i'm trying to combine IF conditions but I'm not sure how else to do this.

It's something very easy im sure, just need someone to show me haha.

As you can probably tell this is programmed in p5.js

Cheers!

Tagged:

Answers

Sign In or Register to comment.