I am quite new at using pygame. I wish to make a basic star tracker programme on my raspberry pi.
So far I have written a code using pygame that shows a webcam feed through my camera lens on the screen of the night sky and stars. I have created a moveable target sprite controlled by the mouse.
What I would like to know is how would I select a star (or perhaps just that area of screen where the star is)using the moveable target and then allow the programme to detect when movement of the star occurs of say 5 pixels.
I was thinking something along the lines of comparing two sections of the screen or something, is that possible. (By the way I created some dummy stars on the screen temporarily just for testing so that my camera doesn't have to always be pointing at the stars while I test.). Anyway thanks in advance of any help.cheers. I have included below my programme so far for you to have a look at.[python]
import pygame
import sys
from pygame.locals import *
pygame.init
import pygame.camera
pygame.font.init()
import time
import os
import RPi.GPIO as GPIO
import datetime
import time
from time import sleep
#setup GPIO pins
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(22,GPIO.OUT)
#set initial state of GPIO
GPIO.output(22,0)
# set simple names for colours instead of numbers
white=(255,255,255)
black=(0,0,0)
red=(255,0,0)
green=(0,255,0)
blue=(0,0,255)
yellow=(255,255,0)
cyan=(0,255,255)
purple=(255,0,255)
pygame.init()
pygame.camera.init()
screen = pygame.display.set_mode((640,480))
pygame.display.set_caption('WEB CAM STAR VIEWER')
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
mysprite=pygame.image.load('/home/pi/Desktop/adder_guider/target.png')
myspritex=10
myspritey=10
while True:
image = cam.get_image()
screen.blit(image,(0,0))
pygame.draw.circle(screen, white, (50,50),5,5) # circle (centre point), radius, width
pygame.draw.circle(screen, white, (90,150),5,5) # circle (centre point), radius, width
pygame.draw.circle(screen, white, (180,250),5,5) # circle (centre point), radius, width
pygame.draw.circle(screen, white, (250,350),5,5) # circle (centre point), radius, width
pygame.draw.circle(screen, white, (390,200),5,5) # circle (centre point), radius, width
pygame.draw.circle(screen, white, (450,209),5,5) # circle (centre point), radius, width
pygame.display.update()
Mouse_x, Mouse_y = pygame.mouse.get_pos()
screen.blit(mysprite,(Mouse_x-78,Mouse_y-78))
pygame.display.update()
colour=screen.get_at((Mouse_x,Mouse_y))
print "The colour is ", colour
#check for white
if colour ==(255,255,255,255): #check what colour a pixel is and do something
print "the colour is white"
GPIO.output(22,1)
time.sleep(.1)
GPIO.output(22,0)
for event in pygame.event.get():#check for quit
if event.type == pygame.QUIT:
sys.exit()