Download presentation
Presentation is loading. Please wait.
Published byAmber Mills Modified over 6 years ago
1
Python Graphics N Amanquah Based on EPROM curriculum
2
Import graphics module
Redraw_callback method of canvas will do that! Greate a graphics.Image object Use double buffering to copy it from buffer to screen/canvas Call canvas.blit(grahicsObject) #eg image Both image and canvas have blit() fxn Handle_redraw takes one param –rect of size of area to redraw, pass None to redraw all
3
Primitives Draw_rectangle() Draw_point() Draw_text()
Also methods to draw polygon, ellipse, pieslice etc
4
Example import appuifw, e32, key_codes, graphics WHITE = (255,255,255)
RED = (255,0,0) BLUE = (0,0,255) YELLOW = (255,255,0) def quit(): app_lock.signal() img = None #other functions canvas = appuifw.Canvas(redraw_callback = handle_redraw, event_callback = handle_event) appuifw.app.body = canvas appuifw.app.screen = "full" appuifw.app.exit_key_handler = quit w, h = canvas.size img = graphics.Image.new((w, h)) img.clear(BLUE) app_lock = e32.Ao_lock() app_lock.wait()
5
The other functions def draw_rectangle():
img.rectangle((50,100,100,150), fill = YELLOW) def draw_point(): img.point((90,50), outline = RED, width = 30) def draw_text(): img.text((10,40), u"Hello", fill = WHITE) def handle_redraw(rect): if img: #to be sure image has been created b4 being copied to canvas canvas.blit(img) def handle_event(event): ev = event["keycode"] if event["type"] == appuifw.EEventKeyDown: #others r: keycode, scancode, modifiers and type! img.clear(BLUE) if ev == key_codes.EKeyUpArrow: draw_point() elif ev == key_codes.EKeyRightArrow: draw_text() elif ev == key_codes.EKeyDownArrow: draw_rectangle() elif ev == key_codes.EKeyLeftArrow: handle_redraw(None)
6
The Camera Program an application that lets you take a picture. The picture shall be stored on the c: drive. 1. from graphics import * and import camera 2. Use the SELECT key to take the picture. 3. Use the LeftSoftKey to to activate the camera mode again. Example: ex_camera_descr.py *Check out the python_api.pdf for more parameters! (exposure, white balance, ….) 6
7
camera.stop_finder() pic = camera.take_photo(size = (640,480)) w,h = canvas.size canvas.blit(pic,target=(0, 0, w, 0.75 * w), scale = 1) pic.save('e:\\Images\\picture1.jpg')
8
Image Handling Play with Nokia's Example Scripts: Image Rotation
Example script : image_rotation.py Image Viewing Example script : imageviewer.py 8
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.