import pygame
import sys
import math

import random

"""
Created by Shr4pnell 2008

feel free to use and improve it 
"""

pygame.init()

global screen,xm,ym,r,running,fsmin,fsmax

# screen width
sw          =800
# screen height
sh          =600
# background color
bgcolor     =255,255,255
# init surface and clock
screen      =pygame.display.set_mode((sw,sh));
clock       =pygame.time.Clock()
# run var
running     =1
# centre of screen width
xm          =sw/2
# centre of screen height
ym          =sh/2
# init position vars
y=x         =0
# init next step in function vars
ystep=xstep =0
# radius of circle
r           =50

# most fast
speedfast   =400
# slowest
speedslow   = speed  = 10

# min fontsize
fsmin       =25
# max fontsize
fsmax       =30
# fontcolor
fcolor      =(140,0,0)

# circle function x-direction
def circlex(step):
    return 2*math.cos(step);

# circle function y-direction
def circley(step):
    return math.sin(step);

# creates the text at specific point
def createtext(surface,text,size,color,xs,ys):
    schrift = pygame.font.Font(None,size)
    outtext = schrift.render(text,True,color)
    outtextrect = outtext.get_rect()
    outtextrect.centerx = xs;
    outtextrect.centery = ys;
    surface.blit(outtext, outtextrect)

def rotposX(var,radius):
    return xm+circlex(var)*radius

def rotposY(var,radius):
    return ym+circley(var)*radius

# generates the color of the font
def gencolor(pos,color):
    r,g,b=color
    npos=1.0-pos
    brightest=230
    r=r+(((brightest-r)*npos)/2)
    g=g+(((brightest-g)*npos)/2)
    b=b+(((brightest-b)*npos)/2)
    return (r,g,b)

# generates the size of the font
def genfsize(pos):
    npos=1.0+pos
    return round(fsmax+(((fsmax-fsmin)*npos)/2))

# generates the next position for the circle function
def dpos(degree):
    return (2*math.pi)*(degree/360.0)

ra1=random.randint(r,r*2);
ra2=random.randint(-50,50)

# run
while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        sys.exit();
    elif event.type == pygame.KEYDOWN:
        sys.exit();

    if event.type == pygame.MOUSEMOTION:
        mousex,mousey=event.pos
        # distance between mouseposition and x-centre of sreen
        dist=math.fabs(xm-mousex)
        # calculates the speed
        speed=round(speedslow-((dist*(speedslow-speedfast))/(sw/2)))

    # next step
    ystep+=0.02;
    xstep+=0.02;

    """
    # if you want to define the speed via steps and not via fps:
    # enable this and delete the two commands above
    ystep+=math.pi/speed;
    xstep+=math.pi/speed;
    """

    screen.fill(bgcolor)
    pygame.draw.line(screen,(240,240,240),(sw/2,0),(sw/2,sh))
    #pygame.draw.line(screen,(240,240,240),(0,sh/2),(sw,sh/2))

    # menu list
    menu = ["Text1","Text2","Text3","Text4","Text5","Text6","Text7","Text8"]

    # generates menu
    for i in range(0,len(menu)):
        deg=round(360.0*((1.0/len(menu))*i))
        createtext(screen,
                   menu[i],
                   genfsize(circley(ystep+dpos(deg))),
                   gencolor(circley(ystep+dpos(deg)),fcolor),
                   rotposX(xstep+dpos(deg),r),
                   rotposY(ystep+dpos(deg),r)
                   )

    # menu list
    menu2 = ["Text1","Text2","Text3","Text4","Text5","Text6"]
    
    # generates menu 2
    for i in range(0,len(menu2)):
        deg=round(360.0*((1.0/len(menu2))*i))
        createtext(screen,
                   menu2[i],
                   34,
                   gencolor(circley(ystep+dpos(deg)),(200,200,200)),
                   rotposX(xstep+dpos(deg),r-10),
                   rotposY(ystep+dpos(deg),r-10)-60
                   )

    # menu list
    menu3 = ["Text1","Text2","Text3","Text4"]
    
    # generates menu 2
    for i in range(0,len(menu3)):
        deg=round(360.0*((1.0/len(menu3))*i))
        createtext(
                   screen,
                   menu3[i],
                   30,
                   gencolor(circley(ystep+dpos(deg)),(200,100,0)),
                   rotposX(xstep+dpos(deg),100),
                   rotposY(ystep+dpos(deg),100)+50
                   )
    
    createtext(
                   screen,
                   "random",
                   30,
                   gencolor(circley(ystep+dpos(deg)),(200,100,0)),
                   rotposX(xstep+dpos(deg),ra1),
                   rotposY(ystep+dpos(deg),ra1)+ra2
                   )
    pygame.display.flip()
    
    # speed via fps
    clock.tick(speed)
    
    """
    # if you want to define the speed via steps and not via fps
    clock.tick(20)
    """
