|
Author |
Topic: simple question (beginner) (Read 324 times) |
|
r_gaberz
|
simple question (beginner)
« on: Dec 30th, 2003, 1:55pm » |
|
I am trying to figure out Processing, but sadly I have no experience with Java, Javascript or Actionscript. I hope somebody can explain this simple snippet of code to me -------------------------------- void loop() { background(0); y = y - 1; if (y < 0) { y = height; } line(0, y, width, y); } -------------------------------- I guess if (y < 0) { y = height; } means that if y is smaller than 0 y is assigned with the value of the document hight. now what I want to know is, what exactly happens in the first loop! Since y has no value assigned to it (except y-1) how can y be given the docu. hight... since y-1 can't theor.become less than zero since it has no numerical value assigned to it in the first place. thank you for your patience
|
« Last Edit: Dec 30th, 2003, 1:56pm by r_gaberz » |
|
.
|
|
|
toxi
|
Re: simple question (beginner)
« Reply #1 on: Dec 30th, 2003, 2:15pm » |
|
hello & welcome to the club! whenever you declare numeric variables, they'll default automatically to 0 (though, it's always best practise to set initial values in anyway). so in your case, the first time the loop is executed, "y" indeed becomes -1 and the condition of the "if" statement in the next line will be "true". hth!
|
http://toxi.co.uk/
|
|
|
r_gaberz
|
Re: simple question (beginner)
« Reply #2 on: Dec 30th, 2003, 4:14pm » |
|
Thanks Toxi!
|
.
|
|
|
elout
|
Re: simple question (beginner)
« Reply #3 on: Dec 30th, 2003, 4:36pm » |
|
for learning experience you can also add a line like println(" y is now: " + y); so you can follow what`s going on..
|
|
|
|
r_gaberz
|
Re: simple question (beginner)
« Reply #4 on: Jan 2nd, 2004, 4:31pm » |
|
next question I tried to rotate a rect with this snipped of code. ---------------------------------------------- void setup() { size(500, 250); background(#000000); } float a; float rad=PI/4; float deg=degrees(rad); void loop(){ if (deg<3000) {deg=deg+0.5;} translate(width/2, height/2); rotate(deg); smooth(); rect(-50,-50,100,100); } ------------------------------------------- Unfortunatly I end up with a white circle because the rects seem to overlay.... Is there a way to make processing delete the last rect ...? hope you can understand what I mean
|
« Last Edit: Jan 2nd, 2004, 4:45pm by r_gaberz » |
|
.
|
|
|
Koenie
|
Re: simple question (beginner)
« Reply #5 on: Jan 2nd, 2004, 5:03pm » |
|
Like you have in the previous example, there is no call to background() at the beginning of loop(). This means everytime the loop runs through the code inside it, it draws over the last thing you drawed and again and again and again. Try this code: Code:void setup() { size(500, 250); background(#000000); } float a; float rad=PI/4; float deg=degrees(rad); void loop(){ background(0); if (deg<3000) {deg=deg+0.5;} translate(width/2, height/2); rotate(deg); smooth(); rect(-50,-50,100,100); } |
| Hope this helps! Koenie
|
http://koeniedesign.com
|
|
|
r_gaberz
|
Re: simple question (beginner)
« Reply #6 on: Jan 2nd, 2004, 8:51pm » |
|
thanks again here is my first pretty trivial processing piece *lol* I still need to improve the color picker a bit to make it more smooth... ---------------------------------------------------- void setup() { size(500,500); background(#000000); framerate(2400); } float angle = 1; float xcor=20000; float a; float b=255; float x2cor; float angle2 = 10; float t=mouseX-500; float z=mouseY-500; float c=mouseY+mouseX/2; void loop(){ if (angle<100000000) {angle=angle+1;} if (xcor<550){xcor=mouseX*-1;} if (xcor>250) {xcor=mouseX*-1;} if (xcor<=0) {xcor=xcor+250;} if (a<255) {a=a+0.05;} if (t<5000000) {t=mouseX;} if (z<5000000) {z=mouseY;} if (c<5000) {c=(mouseY+mouseX)/6;} translate(width/2,height/2); rotate(angle); smooth(); noStroke() ; fill(z,0,t); rectMode(CORNER); rect(xcor-(xcor/2),xcor-(xcor/2),xcor,xcor); } -----------------------------------------
|
.
|
|
|
Koenie
|
Re: simple question (beginner)
« Reply #7 on: Jan 3rd, 2004, 2:27pm » |
|
That's very nice for a first piece. Am I correct by thinking it adds blue by moving your mouse on the x-axis, and adds red by moving your mouse on the y-axis? You could try some other color combinations. Koenie
|
http://koeniedesign.com
|
|
|
|