-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
The first full script in this tutorial https://py.processing.org/tutorials/objects/ (the one with two cars going different speeds) will fail to run if copied and pasted into the Processing IDE. Some lines are not indented properly.
This works:
class Car(object):
# The Constructor is defined with arguments.
def __init__(self, c, xpos, ypos, xspeed):
self.c = c
self.xpos = xpos
self.ypos = ypos
self.xspeed = xspeed
def display(self):
stroke(0)
fill(self.c)
rectMode(CENTER)
rect(self.xpos, self.ypos, 20, 10);
def drive(self):
self.xpos = self.xpos + self.xspeed;
if self.xpos > width:
self.xpos = 0
myCar1 = Car(color(255, 0, 0), 0, 100, 2)
myCar2 = Car(color(0, 255, 255), 0, 10, 1)
def setup():
size(200,200)
def draw():
background(255)
myCar1.drive()
myCar1.display()
myCar2.drive()
myCar2.display()
Metadata
Metadata
Assignees
Labels
No labels