Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

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

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 app instead sends commands to a little python web socket server I built that uses tornado...

Essentially what I would ideally need is a way to:

Display a window Every 17ms, clear the window, read a global variable with x and y and draw a point or circle at x and y.

Is there a convenient way to do this so I can visually see what's going on?

If I can get something to draw a circle in a window every X ms, I can handle the rest.

What needs to be added:

-create a window
-create a timer
on timer callback: clear screen and draw a circle in the window.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...