#!/usr/bin/env python # -*- coding: utf-8 -*- import pygame from pygame.locals import * import sys import time import serial SCREEN_SIZE = (1000, 240) MAX_SPEED = 100 R = 15 Y = SCREEN_SIZE[1]/2 pygame.init() screen = pygame.display.set_mode(SCREEN_SIZE) pygame.display.set_caption(u"drawShapes") ser = serial.Serial(3) num = 0 x = SCREEN_SIZE[0]/2 v = 0 while True: num = int(ser.read(1)) screen.fill((0,0,0)) if num == 2 : v+=1 elif num == 1 : v-=1 if v <-MAX_SPEED: v = -MAX_SPEED elif v>MAX_SPEED: v = MAX_SPEED x+=v if x > SCREEN_SIZE[0] - R: v = -v elif x < 0 + R: v = -v # }Œ`‚ð•`‰æ #pygame.draw.rect(screen, (255,255,0), Rect(10,10,300,200)) # ‰©‚Ì‹éŒ` pygame.draw.circle(screen, (0,255,0), (x,Y), R) # Ԃ̉~ #pygame.draw.ellipse(screen, (255,0,255), (400,300,200,100)) # Ž‡‚̑ȉ~ #pygame.draw.line(screen, (255,255,255), (0,0), (640,480)) # ”’‚¢ü pygame.display.update() time.sleep(0.05)