Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle, Screen
- from random import randint
- import math #Explore specific import ?
- def randomColor():
- return (randint(20,255), randint(20,255), randint(20,255))
- def draw_dot(name,radius, color,x,y):
- name.penup()
- name.setx(x)
- name.sety(y)
- name.pendown()
- name.color(color)
- name.dot(radius * 2)
- def drawPolygon (ttl, xpos, ypos, num_side, radius, fill):
- sideLen = 2 * radius * math.sin (math.pi / num_side)
- angle = 360 / num_side
- ttl.penup()
- ttl.goto (xpos, ypos)
- # if fill == 1:
- # ttl.fillcolor(ttl.pencolor())
- # ttl.begin_fill()
- ttl.pendown()
- for iter in range (num_side):
- ttl.forward (sideLen)
- ttl.left (angle)
- # if fill == 1:
- # ttl.end_fill()
- tina = Turtle()
- #draw_dot(tina,50,"blue",0,0);
- #tina.position()
- # create a turtle object
- scr = Screen()
- #Needed to include the following to get the turtle
- #pencolor function to accept an R,G,B tuple
- #see https://docs.python.org/3/library/turtle.html#turtle.colormode
- scr.colormode(255)
- scr.bgcolor("black")
- tina.speed(0)
- #Not sure how to get the screen size. Just using these values
- #as they work on my screen
- x = -450
- y = +300
- delta = +105
- seg_size = +40
- #draw polygons with number of sides from 3 to 10
- for ii in range(3,11):
- tina.pencolor((randomColor()))
- drawPolygon (tina, x, y, ii, seg_size, False)
- x = x + delta
- x = -450
- y = 150
- #random number of sides
- for _ in range(4,12):
- tina.pencolor((randomColor()))
- drawPolygon (tina, x, y, randint(3,11), seg_size,False)
- x = x + delta
- x = -450
- y = 0
- for jj in range(4,12):
- tina.pencolor((randomColor()))
- drawPolygon (tina, x, y, jj, seg_size,True)
- x = x + delta
- x = -450
- y = -150
- #more circle like?
- for kk in range(10,18):
- tina.pencolor((randomColor()))
- drawPolygon (tina, x, y, kk, seg_size,True)
- x = x + delta
- # persist drawing
- ttl.penup()
- ttl.goto(0,0)
- ttl.hideturtle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement