drawing a point on the screen every 17ms in Python?

后端 未结 3 603
旧时难觅i
旧时难觅i 2020-12-04 01:01

I managed to string together a script that receives commands from an iOS app setting velocity and a direction.

The thing is I do not have the actual device, so my ap

3条回答
  •  再見小時候
    2020-12-04 01:30

    You should try using pygame for graphics work. First download pygame

    Here is a sample code

    import pygame,sys
    from pygame import *
    
    WIDTH = 480
    HEIGHT = 480
    WHITE = (255,255,255) #RGB
    BLACK = (0,0,0) #RGB
    
    pygame.init()
    screen = display.set_mode((WIDTH,HEIGHT),0,32)
    display.set_caption("Name of Application")
    screen.fill(WHITE)
    timer = pygame.time.Clock()
    pos_on_screen, radius = (50, 50), 20    
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
        timer.tick(60) #60 times per second you can do the math for 17 ms
        draw.circle(screen, BLACK, pos_on_screen, radius)
        display.update()
    

    HOPE THAT HELPS. Remember you need to download pygame first. You should also read up on pygame. It is really helpful.

提交回复
热议问题