'''
Random Points

Summary
A program that draw a square and circle, with ten random points inside of each.
'''

import turtle
import UsefulTurtleFunctions
import random
win = turtle.Screen()

def is_point_in_square(x, y):
   if -125 <= x <= -25 and -50 <= y <= 50:
      return True
   else:
      return False

def is_point_in_circle(x, y):
   d = ((x - 50) ** 2 + y ** 2) ** 0.5
   if d <= 50:
      return True
   else:
      return False
   
def get_random_location():
   return random.randint(-125,100), random.randint(-50,50)
   
def draw_dots_in_circle():
   count = 0
   while count <10:
      x,y = get_random_location()
      if is_point_in_circle(x,y):
         UsefulTurtleFunctions.drawPoint(x,y)
         count += 1

def draw_dots_in_square():
   count = 0
   while count <10:
      x,y = get_random_location()
      if is_point_in_square(x,y):
         UsefulTurtleFunctions.drawPoint(x,y)
         count += 1   

def draw_square_with_random_dots():
   UsefulTurtleFunctions.drawRectangle(-75,0,100,100)
   draw_dots_in_square()

def draw_circle_with_random_dots(x,y):
   UsefulTurtleFunctions.drawCircle(50,0,50)
   draw_dots_in_circle()
   

def main():
   
   draw_circle_with_random_dots(50,0)
   draw_square_with_random_dots()  
   
main()

win.exitonclick()
Scroll to Top