mercredi 24 février 2016

How do I generate random dots inside my turtle circle and rectangle?

Inside turtle graphics, I drew a rectangle and a circle. How can I put 10 random dots in each of my shapes? This is the code I have:

import turtle
import math
import random 

# draw a rectangle at a specific location
def drawRectangle(x = -75, y = 0, width = 100, height = 100): 
    turtle.penup() # Pull the pen up
    turtle.goto(x + width / 2, y + height / 2)
    turtle.pendown() # Pull the pen down
    turtle.right(90)
    turtle.forward(height)
    turtle.right(90)
    turtle.forward(width)
    turtle.right(90)
    turtle.forward(height)
    turtle.right(90)
    turtle.forward(width)    


# Draw a circle at a specific location
def drawCircle(x = 50, y = 0, radius = 50): 
    turtle.penup() # Pull the pen up
    turtle.goto(x, -50)
    turtle.pendown() # Pull the pen down
    turtle.begin_fill() # Begin to fill color in a shape
    turtle.circle(radius) 




Aucun commentaire:

Enregistrer un commentaire