import sys, os, pygame, itertools
from math import sin,cos,pi, radians
from pygame.locals import *
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (50,50) #Set window position
pygame.init()
clock = pygame.time.Clock()
FPS = 1000
SCREENW = 800 Â #screen width
SCREENH = 740 Â #screen height
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
ORANGE = (128, 100, 30)
FONT1= "Cookie-Regular.ttf"
SCREEN = pygame.display.set_mode((SCREENW, SCREENH), 0, 32) #display screen
clock = pygame.time.Clock()
#-------------------------------------------------------------------------------
def maketext(msg,fontsize, colour = ORANGE, font = FONT1):
  mafont = pygame.font.Font(font, fontsize)
  matext = mafont.render(msg, True, colour)
  matext = matext.convert_alpha()
  return matext
#-------------------------------------------------------------------------------
def print_info():
  """"""
  textcos = maketext(str(round(obj.rect.x, 2)) + "  " + str(round(obj.rect.y, 2)), 30)
  SCREEN.blit(textcos, (obj.rect.x, obj.rect.y + 30))
#-------------------------------------------------------------------------------
class object_factory(pygame.sprite.Sprite):
  def __init__(self, imagelist, xpos, ypos):
    """Constructor"""
    pygame.sprite.Sprite.__init__(self)
    self.frame = 0
    self.imagelist = imagelist
    self.image = imagelist[self.frame]
    self.mask = pygame.mask.from_surface(self.image) # pixelmask
    self.rect = self.image.get_rect()
    self.rect.x = xpos
    self.rect.y = ypos
    self.timer = 0
    self.timerlimit = 10
    #----------------------------------------------------------------------
  #def move(self): Â# wallsprites, Herosprite, looptime
    #self.rect.x += self.speedx
    #self.rect.y += self.speedy
  #----------------------------------------------------------------------
  def update(self):
    """"""
    self.image = self.imagelist[self.frame]
    if self.timer >= self.timerlimit:
      self.frame += 1
      if self.frame >= len(self.imagelist):
        self.frame = 0
      self.timer = 0
    self.timer += 1
plat = pygame.image.load("plt0.png").convert_alpha()
star = pygame.image.load("gemp0.png").convert_alpha()
## declare the sprite group
platforms = pygame.sprite.Group()
boxes = pygame.sprite.Group()
rotcenx = SCREENW/2
rotceny = SCREENH/2
radius = 200
angle = radians(90) Â#pi/4 # starting angle 45 degrees
omega = radians(5) #Angular velocity
m = rotcenx + radius * cos(angle) #Starting position x
n = rotceny - radius * sin(angle) #Starting position y
for _ in itertools.repeat(None, 1):
  midx = SCREENW/2
  midy = SCREENH/2
  radius1 = 200
  angle1 = radians(180) Â#pi/4 # starting angle 45 degrees
  angular_v = radians(5) #Angular velocity
  a = midx + (radius1 * cos(angle1)) #Starting position x
  b = midy - (radius1 * sin(angle1)) #Startinh position y
  plat = object_factory([plat], a, b)
  plat.radius = radius1
  plat.angle = angle1
  plat.angular_vel = angular_v
  platforms.add(plat)
while True:
  ms = clock.tick(FPS) Â# milliseconds passed since last frame
  SCREEN.fill((BLACK))
  ## THIS CODE WORKS MOVES THE OBJECT IN A CIRCLE
 ÂÂ
  SCREEN.blit(star, (m, n)) # Draw current x,y
  angle = angle + omega # New angle, we add angular velocity
  m = m + radius * omega * cos(angle + pi / 2) # New x
  n = n - radius * omega * sin(angle + pi / 2) # New y
  ##---------------------------------------------------------------
  # show object anchored to center of rotation
  pygame.draw.line(SCREEN, ORANGE, (rotcenx, rotceny), (m, n))
  text = maketext(str(radius), 30)
  SCREEN.blit(text, (m, n - 40))
  text = maketext((str(round(m, 2)) + " Â" + str(round(n, 2))), 30)
  SCREEN.blit(text, (m, n + 40)) # Draw current x,y
  ## THIS CODE DOES NOT MOVE THE OBJECT IN A CIRCLE
  for plat in platforms:
    plat.angle = plat.angle + plat.angular_vel
    plat.rect.x = plat.rect.x + plat.radius * plat.angular_vel * cos(plat.angle + pi / 2)
    plat.rect.y = plat.rect.y - plat.radius * plat.angular_vel * sin(plat.angle + pi / 2)
  ##------------------------------------------------------------------------
  pygame.draw.line(SCREEN, ORANGE, (midx, midy), (plat.rect.x, plat.rect.y))
  pygame.draw.circle(SCREEN, BLUE, (rotcenx, rotceny), radius1, 2)
  platforms.update()
  platforms.draw(SCREEN)
  pygame.event.pump()
  keys = pygame.key.get_pressed()
  for event in pygame.event.get():
    if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
      pygame.quit()
      sys.exit()
  pygame.display.update()
  pygame.time.wait(100)