main.py

00001 # This file is Copyright 2010 Oscar Lindberg.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 import sys
00014 import list
00015 from ma import *
00016 
00017 
00018 # Print statements end up in the log
00019 print "MoPync - bringing the Guido goodness to the world of MoSync"
00020 
00021 LOGO_HANDLE = 1
00022 logo_width, logo_height = maGetImageSize(LOGO_HANDLE)
00023 
00024 screen_width, screen_height = maGetScrSize()
00025 background_color = 0x330055
00026 
00027 # Create some random rectangles
00028 rectangles = []
00029 for _ in xrange(10):
00030     list.append(rectangles, [rand() % screen_width, rand() % screen_height,
00031                              rand() % 40 + 20, rand() % 40 + 20,
00032                              (rand() % 0x40) * 0x10002 + 0x883388,
00033                              rand() % 7 - 3, rand() % 7 - 3])
00034 
00035 
00036 # Clear screen
00037 maSetColor(background_color)
00038 maFillRect(0, 0, screen_width, screen_height)
00039 
00040 keep_going = True
00041 while keep_going:
00042     sys.gc()
00043     # Wait for an event, or 20 ms
00044     maWait(1)
00045 
00046     # Handle all events from the event queue
00047     for event in maGetEvents():
00048         print event.__str__()
00049         if (event.type == EVENT_TYPE_CLOSE or
00050             event.type == EVENT_TYPE_KEY_PRESSED and event.key == MAK_FIRE):
00051             keep_going = False
00052 
00053     # Erase rectangles
00054     maSetColor(background_color)
00055     for rectangle in rectangles:
00056         x, y, w, h, c, xv, yv = rectangle
00057         maFillRect(x-w, y-h, w, h)
00058 
00059     # Erase logo
00060     maFillRect(screen_width-logo_width >> 1,
00061                screen_height-logo_height >> 1,
00062                logo_width, logo_height)
00063 
00064     # Update rectange position
00065     for rectangle in rectangles:
00066         x, y, w, h, c, xv, yv = rectangle
00067         rectangle[0] += xv + screen_width + w
00068         rectangle[0] %= screen_width + w
00069         rectangle[1] += yv + screen_height + h
00070         rectangle[1] %= screen_height + h
00071 
00072     # Draw pymite logo in center of screen
00073     maDrawImage(LOGO_HANDLE,
00074                 screen_width-logo_width >> 1,
00075                 screen_height-logo_height >> 1)
00076 
00077     # Draw rectangles
00078     for rectangle in rectangles:
00079         x, y, w, h, c, xv, yv = rectangle
00080         maSetColor(c)
00081         maFillRect(x-w, y-h, w, h)
00082 
00083     maUpdateScreen()
00084 

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9