import turtle import math #turtle object t = turtle.Turtle() #dictionary to hold angle positions giveAngle = {'top': 90, 'bottom': 270, 'right': 0, 'left': 180, 'topright': 45, 'topleft': 135, 'bottomright': 225,'bottomleft': 315} # draws a circle at the given radius with x and y as the center def DrawCircle(x,y,radius): t.penup() t.goto(x, y - radius) t.pendown() t.circle(radius) #draws a planet with a ring around it #x and y are the center of the planet #radius includes the outside of the ring def DrawPlanet(x,y,radius): DrawCircle(x, y, radius) DrawCircle(x, y, radius * (9/10)) DrawCircle(x, y, radius * (6/10)) #gives a new radius for a circle based on based on the percentage of the area of a circle def CalculateNewRadius(radius, sizeDecrease): area = math.pi * (radius ** 2) newArea = area * (100 - sizeDecrease) / 100 newRadius = math.sqrt(newArea/math.pi) return newRadius #calculates how far away from the center of the parent planet a new planet is to be drawn def CalculatePlanetDistance(radius, sizeDecrease): area = math.pi * (radius ** 2) oldArea = area / ((100 - sizeDecrease) / 100) oldRadius = math.sqrt(oldArea/math.pi) distance = oldRadius * (1/3) return distance #returns an x and y based on an angle and the distance from parent planet def CalculateXAndY(angle, distance): fraction = distance / math.sin(math.radians(90)) y = fraction * math.sin(math.radians(angle)) x = fraction * math.sin(math.radians(180 - 90 - angle)) return x, y #Fractal art Parameters go by the following list #1)x (int) - the x location mid-point of the plantets being drawn #2)y (int) - the y location mid-point of the plantets being drawn #3)radius (int) - the length of the radius of the planet #4)drawAmount (int) - the amount of planets that will be drawn (if a number <= 0 is entered the program will stop) #5)drawIncrease (int) - how many planets to increase the draw count by (can be negative) #6)firstLocation (string) - the position relative to the mid-point where the first planet will be drawn #6 cont.) - parameter options: top, bottom, left, right, topleft, topright, bottomleft, bottomright #7)sizeDecrease (int)- tells how much smaller planets drawn inside the planet will be (percentage between 1-99) #8)repeatCount (int)- how many times the program will recursively draw before it stops def FractalArt(x, y, radius, drawAmount, drawIncrease, firstLocation, sizeDecrease, repeatCount): #if the repeatCount or drawAmount are less than 0 the function will not run if(repeatCount >= 0 and drawAmount > 0): #stores how many child planets have been drawn amountDrawn = 0 #stores were the first planet will be drawn angle = giveAngle[firstLocation] #if the draw amount is 1, then place its drawing position at the center of the sent radius if drawAmount == 1: distance = radius #if not then calculate the child's distance from the parent planet else: distance = CalculatePlanetDistance(radius, sizeDecrease) #tells how much the angle should change by for each planet drawn angleIncrease = 360 / drawAmount #keep drawing planets until the amount needed has been hit while(amountDrawn < drawAmount): #if the amount of children to draw is 1, then don't create an offest if drawAmount == 1: xLocation, yLocation = 0,0 #else find the offset from the parent planets center else: xLocation, yLocation = CalculateXAndY(angle, distance) #draws the planet DrawPlanet(x + xLocation, y + yLocation, radius) #draws the planets other planets that are to be inside of the planet FractalArt(x + xLocation, y + yLocation, CalculateNewRadius(radius,sizeDecrease), drawAmount + drawIncrease, drawIncrease, firstLocation,sizeDecrease, repeatCount - 1) #shifts the angle the planets are being being drawn at angle += angleIncrease #increases the amount of planets drawn amountDrawn += 1 #sets the drawing speed to fast t.speed('fastest') turtle.tracer(0, 0) #edit code in between the stars #***********************************************************************************************************************# #1)x (int) - the x location mid-point of the plantets being drawn x = 0 #2)y (int) - the y location mid-point of the plantets being drawn y = -50 #3)radius (int) - the length of the radius of the planet radius = 275 #4)drawAmount (int) - the amount of planets that will be drawn (if a number <= 0 is entered the program will stop) drawAmount = 3 #5)drawIncrease (int) - how many planets to increase the draw count by (can be positive or negative) drawIncrease = 1 #6)firstLocation (string) - the position relative to the mid-point where the first planet will be drawn #6 cont.) - parameter options: top, bottom, left, right, topleft, topright, bottomleft, bottomright firstLocation = 'top' #7)sizeDecrease (int)- tells how much smaller planets drawn inside the planet will be (percentage between 1-99) sizeDecrease = 77 #8)repeatCount (int)- how many times the program will recursively draw before it stops repeatCount = 2 #************************************************************************************************************************# FractalArt(x,y,radius,drawAmount, drawIncrease,firstLocation, sizeDecrease,repeatCount) turtle.update() #allows the turtle window to be clicked turtle.exitonclick()