-
-
Save EllaY44/82ea05aeb18cc78d142b35419d218942 to your computer and use it in GitHub Desktop.
global circleX, direction | |
circleX = 500 | |
direction = 8 | |
global circletwoX, directiontwo | |
circletwoX = 450 | |
directiontwo = 3 | |
global circlethreeX, directionthree | |
circlethreeX = 550 | |
directionthree = 6 | |
def setup(): | |
size (600, 600) | |
noStroke | |
def draw(): | |
global circleX, direction | |
background(255, 255, 255) | |
img = loadImage("cat-raster-image.png") | |
image(img, 0, 0, 600, 600) | |
fill(165, 131, 98) | |
ellipse(circleX, 500, 50, 50) | |
circleX = circleX + direction | |
if circleX > 500: | |
direction = -15 | |
if circleX < 120: | |
direction = 15 | |
global circletwoX, directiontwo | |
fill(252, 222, 240) | |
ellipse(circletwoX, 450, 60, 60) | |
circletwoX = circletwoX + directiontwo | |
if circletwoX > 520: | |
directiontwo = -10 | |
if circletwoX < 150: | |
directiontwo = 10 | |
fill(236, 214, 255) | |
circle(335, 350, 35) | |
if mousePressed: | |
global circlethreeX, directionthree | |
fill(176, 211, 252) | |
ellipse(circlethreeX, 550, 40, 40) | |
circlethreeX = circlethreeX + directionthree | |
if circlethreeX > 600: | |
directionthree = -10 | |
if circlethreeX < 0: | |
directionthree = 10 |
Nice work so far. Remember what I was saying in class about using loadImage()
in Processing's "active" mode?
You should move line 21 into def setup()
, make img
global in both setup()
and draw()
. I think that will probably fix your problem but if not we can debug it further from there.
If you want to see some code snippets illustrating what I mean have a look at the "Review" section in the Week 4 class notes.
Also, probably unrelated but line 43 needs to be indented by 4 spaces to align with the preceding lines. I'm actually surprised that this doesn't give an error.
Good luck and let me know if this works.
Also line 16 is missing the parenthesis ()
. It should look like this:
noStroke()
I'm also surprised this did not generate an error.
Hello,
All those corrections worked; thank you! @rors
@rors Hello,
The code above is what I've been working on for homework. I ran it multiple times and everything was working completely fine and smoothly; until when I tried to run it the last time - I got an error message saying OutOfMemoryError: Java Heap Space. How might I fix this?