myCar1 = new Car ( color ( 192, 122, 0 ), 132, 60, 3 );
myCar2 = new Car ( color ( 0, 120, 192 ), 298, 200, 2 );
}
void draw ( ) {
background ( 100 );
stroke ( 34 );
strokeWeight ( 4 );
fill ( 34 );
rect ( 80, 0, 300, 550 );
stroke ( 255 );
strokeWeight ( 12 );
line ( 230, 10, 230, 45 );
line ( 230, 80, 230, 115 );
line ( 230, 150, 230, 185 );
line ( 230, 220, 230, 255 );
line ( 230, 290, 230, 325 );
line ( 230, 360, 230, 395 );
line ( 230, 430, 230, 465 );
line ( 230, 500, 230, 535 );
myCar1.drive ( );
myCar1.display ( );
myCar2.drive ( );
myCar2.display ( );
}
class Car {
color d;
float xpos;
float ypos;
float yspeed;
Car ( color tempD, float tempXpos, float tempYpos, float tempYspeed ) {
d = tempD;
xpos = tempXpos;
ypos = tempYpos;
yspeed = tempYspeed;
}
void display ( ) {
strokeWeight ( 3 );
stroke ( 255 );
fill ( d );
rectMode ( CORNER );
rect ( xpos, ypos, 30, 50 );
}
void drive ( ) {
ypos = ypos + yspeed;
if ( ypos > width ) {
ypos = 0;
}
}
}
Hey fellow nerds, I'm still very new to processing but i've been getting my hands dirty with a few cool sketches. In the screenshot below is an animated sketch of two rectangles ( cars ) moving on a highway in the same direction, Lol, it took me a day to pull this off, but I guess it was worth it at the end of the day, so here's my question, how do i get either of the cars to move in an opposite direction? I'll really appreciate if I could get help with getting it done soon as i'm really getting the hangover of computer programming quite well and its been interesting I must say. Thank you.
hello geeks, i'm still very new to computer programming, and I decided to get creative so i came up with the sketch in the screenshot below in Processing, LOL, it might look very basic as its just a static sketch but it took me close to 3hrs to come up with it as i'm still an amateur, so here's my question, how do I make the cars on the highway move back and forth, as in "Perpetual Motion" . I hope to get a reply from you guys as soon as possible. Thanks!
Hello, i'm still very new to computer programming, and i intend taking every single code i type in processing very important, lol, i'm sure my question might seem too basic, but hey, Rome wasn't built in a day. So my question goes thus, the line ( ) function has a bunch of number coordinates in it, how do I use them effectively? At the moment, i have no idea how to interpret the numbers in the function to give me my desired output. I understand that they've got something to do with (x1, y1, x2, y2); but I don't know how to apply the coordinates to give me a particular direction i want a line to go. I hope i get a reply as soon as possible, thanks.