import drawSvg as draw
import math
from random import uniform

# Eye class
class Eye:
    def __init__(self, x, y, rad, color='blue'):
        # eye position and size
        self.x = x
        self.y = y
        self.rad = rad
        
        # eye gaze direction
        self.direction = 0 # not passed in

        # eye color
        self.color = color
        
    def lookat(self, lx, ly):
        self.direction = math.atan2(ly-self.y, lx-self.x) # move eye to look at (lx,ly)

    def drawEye(self):
        # draw outer circle
        D.append(draw.Circle(self.x, self.y, self.rad, fill='white', stroke='black'))
        
        # draw inner circle
        ix = 0.4 * self.rad * math.cos(self.direction) + self.x
        iy = 0.4 * self.rad * math.sin(self.direction) + self.y
        D.append(draw.Circle(ix, iy, 0.5*self.rad, fill=self.color, stroke='black'))


# Face class
class Face:
    def __init__(self, x, y, size):
        # face position and size
        self.x = x
        self.y = y
        self.size = size
        
        # create eyes
        self.lefteye = Eye( x-40, y+50, 30 )
        self.righteye = Eye( x+40, y+50, 30 )
        
    def lookat(self, lx, ly):
        self.lefteye.lookat( lx, ly )
        self.righteye.lookat( lx, ly )
       
    def drawFace(self):
        # draw face
        D.append(draw.Circle(self.x, self.y, self.size, fill='white', stroke='black'))

        # draw eyes
        self.lefteye.drawEye()
        self.righteye.drawEye()
        
        # draw nose
        p = draw.Path(stroke='black', fill='white')
        p.M(self.x+0,self.y+30)   # Start path 
        p.l(30,-30) # Draw line to next point
        p.l(-30,0)  # Draw line to next point
        D.append(p)

        # draw mouth
        D.append(draw.Arc(self.x+0,self.y-30,40,180,0, stroke='black', fill='white'))


# Crowd class 
class Crowd:
    def __init__(self, N):
        self.N = N
        
        self.the_crowd = []
        for i in range( 0, N ):
            self.the_crowd.append( Face(uniform(-300,300), uniform(-300,300), 100) )
            
        self.lookat()
        
    def lookat(self):
        for i in range( 0, self.N ):
            self.the_crowd[i].lookat( uniform(-5000,5000), uniform(-5000,5000) )

    def draw(self):
        for i in range( 0, self.N ):
            self.the_crowd[i].drawFace()

# draw crowd    
D = draw.Drawing(800, 800, origin='center') # define drawing canvas
C = Crowd(25)
C.draw()   
D
