Excercise: Graphics drawing on full canvas
• Program an application that lets you move a colour point on the full sized canvas,
1. Use e.g. the script from the "extended use of keys" exercise and add few things:
from graphics import * since we want to use the graphics functionalities
We need to define the size and starting position of the colour point:
img.point((location_x + blobsize/2,location_y + blobsize/2),0xff0000,width=blobsize)
The application needs to constantly redraw the whole canvas in order to update the new position of the colour point. For this we create a functioin call handle_redraw and use canvas.blit(...):
In the Canvas function we add the handle_redraw function as the redraw_callback:
In the "running" loop we need to add:
img.clear(0x0000ff) so that the entire canvas it redrawn (resets the entire surface of the drawable to a given colour)
note: also you need to change keyboard.pressed(...) to keyboard.is_down(...) in the "running" loop, so that not only a single hit of a key gets recognized but the continous pressing of the key.
Example file: ex_graphics_drawing.py
If you are bored:
Add in the current exercise script some limitations to the movements of the point, so it can not go outside the visible canvas.
You can also check out Nokia's ball.py example and modify it.