rakesh ranjan
rakesh ranjan

Reputation: 11

Moving points across a screen using PIL

I wrote a sample code to draw a set of points in a black background. What i would like to do is to take one point and move it along specific set of coordinates. I would also like to calculate the time taken for one point to move from one coordinate to another. I am really stuck with the implementation. Any suggestion will be appreciated?

from PIL import Image, ImageDraw, ImageFont, ImageChops
from random import randrange
import time
class ImageHandler(object):                  #
    reso_width = 100
    reso_height = 100
    radius = 5

    def __init__(self,width,height,spot_lightradius = 5):
        self.reso_width = width                                         
        self.reso_height = height
        self.radius = spot_lightradius

    def get_image_spotlight(self,set_points):
        image,draw = self.get_black_image()
        for (x,y) in set_points:
            draw.ellipse((x-self.radius,y-self.radius,x+self.radius,y+self.radius),fill = 'white')
        image.show("new_image")
        return image

    def get_black_image(self):
        image = Image.new('RGBA',(self.reso_width,self.reso_height),"black")
        draw = ImageDraw.Draw((image))
        return image,draw


counter = 1
hi =  ImageHandler(1000,1000)
points = [(52,700)]
img = hi.get_image_spotlight(points)
time.sleep(500)

Upvotes: 0

Views: 377

Answers (1)

Michiel Overtoom
Michiel Overtoom

Reputation: 1619

PIL is used to create or manipulate static images. It looks like you want to do some animation. For this, other libraries are more useful, such as PyGame. (if you want to use Python) or the JavaScript Canvas in a browser, if you are OK with JavaScript.

Also, your wish to 'calculate the time taken for one point to move from one coordinate to another' is a bit vague. As the programmer, you can determine yourself how fast a point should move across the screen ;-)

Upvotes: 1

Related Questions