Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bouncing_sq_with_gc.py ### seems to work fast as the threading demo version
- from appuifw import *
- import e32
- import gc
- from graphics import *
- running = 1
- def quit():
- global running
- running = 0
- app.exit_key_handler = quit
- def draw(rect):
- if img:
- canvas.blit(img)
- img = None
- app.screen = 'large'
- app.orientation = 'portrait'
- app.directional_pad = False
- app.body = canvas = Canvas(redraw_callback=draw)
- img = Image.new(canvas.size)
- res_x, res_y = canvas.size
- dy = 1
- dx = 1
- x1 = 0
- y1 = 0
- x2 = 0
- y2 = 0
- from threading import Thread
- def plot():
- global x1,y1,dx,dy,x2,y2
- x1 = x1 + dx
- y1 = y1 + dy
- x2 = x1 + 100
- y2 = y1 + 100
- if (x1 < -50):
- dx = -1 * dx
- elif (x1 > res_x - 50):
- dx = -1 * dx
- if (y1 < -50):
- dy = -1 * dy
- elif (y1 > res_y - 50):
- dy = -1 * dy
- while running:
- gc.collect()
- plot()
- img.clear(0x000000)
- img.rectangle((x1, y1, x2, y2), fill=0xff0000)
- draw(())
- e32.ao_yield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement