A3x - Optional Extension
Nested loops are loops within loops, and can be used to do some interesting things.
Paste the following code into a blank Python file and see what it does. Try to understand why it works, and experiment with it a bit. I'll also spend a bit of time going through it in class.
import op_arcade as oa
import op_arcade.constants_classes as cc
class Level_1(oa.View):
def on_create(self):
x = 100
while x < 1000:
y = 100
while y < 700:
coin = oa.Sprite(x, y, cc.Images.Items.COIN_GOLD)
# ALSO SEE WHAT HAPPENS WHEN YOU UNCOMMENT THESE LINES
# coin.color = (200, x/5, y/5)
# coin.scale = x/700
y += 100
x += 100
def on_step(self):
self.clear()
self.scene.draw()
self.draw_grid()
oa.run(Level_1)
What sorts of effects or patterns could you get using this approach? Try to get creative. You're not limited to one sprite type!