We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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!
Answers
Perhaps you mean something similar to this 1:? :-/
http://studio.ProcessingTogether.com/sp/pad/export/ro.9yLN5A4NXl0YH
Your
if ()
conditionals seem very wrong to me. Why is that;
doing there? :-??And
x = +s
doesn't make much sense to me either!Before diving in even to the simplest programming endeavors we gotta leanr the basics.
Which are variables, arrays, branching conditional & loops, basic arithmetic, functions.
They're in Java, but here are some reference/tutorial links:
Ah! Khan Academy would be gr8 for ya: :-bd
https://www.KhanAcademy.org/computing/computer-programming
if ()
lesson: :bzhttps://www.KhanAcademy.org/computing/computer-programming/programming/logic-if-statements/p/if-statements#
Cheers for the help Loop, Like I said, I was trying to combine two conditions for an IF statement, so I put a ; there hahaha. I know it doesn't work, should have cleaned up my code before posting here, was just clutching at straws. If you run the script you can see it half works. I'll look at the reference material tonight and give it another stab, thanks!
I think this Khan video will hold the answer [-O<
These are the 3 logical operators:
Thanks man got it working, took a while to get my head round it, the && statement is what I was looking for. If you know a way to improve the code let me know. Probably didnt need to compound the x y variables!
EDIT= you get a pretty cool effect if you set the step speed to 100