We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I just copied and pasted a code, my professor had on his lecture slide, on to my processing (which is in python mode).
planet_x = [] # list of planet centre x- coordinates
planet_y = [] # list of planet centre y- coordinates
planet_diameter = 50 # planet diameter in pixels
def setup ():
# create 500 x500 canvas with black backdrop
size (500 ,500)
background (0 ,0 ,0)
global planet_x
global planet_y
# initialize the sun & two other planets
planet_x = [250 ,100 ,400]
planet_y = [250 ,400 ,100]
def draw ():
global planet_x
global planet_y
global planet_diameter
background (0 ,0 ,0)
# draw the sun
fill (255 ,255 ,0)
ellipse ( planet_x [0] , planet_y [0] , planet_diameter , planet_diameter )
# all other planets
for i in range (1 , len ( planet_x )):
fill (0 ,0 ,255)
ellipse ( planet_x [ i ] , planet_y [ i ] , planet_diameter , planet_diameter )
def mouseClicked():
global planet_x
global planet_y
# add mouse click coords as new planet to draw
planet_x.append ( mouseX )
planet_y.append ( mouseY )
def keyPressed ():
global planet_x
global planet_y
# remove last drawn planet (do not remove the sun )
if key == ’r’:
planet_x.pop()
planet_y.pop()
but it's giving me an error saying "Cannot create PyString with non-byte value". The error seems to pop up when I include mouseClicked and keyPressed
Answers
@ Line #36,
if key == ’r’:
, change’
to'
:if key == 'r':
L-)lol oops xD thank you