def main(): """Gathering input and making the computer do stuff.""" paul = Turtle(1024, 768) level = raw_input("Please enter a level for the fractals: ") distance = raw_input("Please enter a distance for your lines: ") gewd = False while not gewd: if not level.isalpha() and int(level) >= 0: if not distance.isalpha() and int(distance) >= 0: print "Thanks for the correct input, bro." gewd = True else: distance = raw_input( "Enter a NUMBER that is greater than or equal to zero(talking about distance here): " ) else: level = raw_input( "Enter a NUMBER that is greater than or equal to zero(talking about level here): " ) distance = float(distance) paul.setWidth(1) x = distance / 2.0 y = -1 * ((distance * (math.sin(60))) / (math.sin(90)) - distance / 1.9) / 2.0 fractal(paul, -1 * x, y, distance, 0, int(level)) fractal(paul, (-1 * x) + distance, y, distance, -120, int(level)) fractal(paul, 0, -1 * y, distance, 120, int(level)) raw_input("Press enter to exit!")
def main(): paul = Turtle(1024, 768) level = raw_input("Please enter a level for the fractals: ") gewd = False while not gewd: if not level.isalpha() and int(level) >= 0: print "Thanks for the correct input, bro." gewd = True else: level = raw_input( "Enter a NUMBER that is greater than or equal to zero: ") xy1 = raw_input( "Please enter an x and y coordinate with ONLY a space inbetween them: " ) xy2 = raw_input("Now do the same thing for another coordinate: ") gewd = False while not gewd: xy1L = xy1.split() xy2L = xy2.split() if len(xy1L) == 2 and len(xy2L) == 2: gewd = True else: xy1 = raw_input( "Please enter correct coordinates with a space inbetween: ") xy2 = raw_input("Now do the same thing for another coordinate: ") paul.setWidth(1) fractal(paul, int(xy1L[0]), int(xy1L[1]), int(xy2L[0]), int(xy2L[1]), int(level)) raw_input("Press enter to exit!")
def main(): finished = False while not finished: #Input loop (never trust a user!) gewd = False while not gewd: #Ask for the time time = raw_input("Enter the hour of day you wish to view (within interval [0,24)): ") #Error checking if time.isdigit() != True or int(time) >= 24 or int(time) < 0: print "Incorrect input" else: gewd = True #Initialize the turtle paul = Turtle(900,700) #Draw the scene for the corresponding time as specified by the user.. listOfSquares = drawBackgroundArt(paul, int(time)) #Shuffling and drawing all of the squares generated for the scene shuffle(listOfSquares) for (x, y, width, height, color) in listOfSquares: drawRect(paul, x, y, width, height, color) #Check if the user would like to quit entry = raw_input("Leave this entry field blank to quit!") if entry == "": finished = True
def main(): finished = False while not finished: paul = Turtle(600, 600) gewd = False """ while not gewd: x = raw_input("Enter an x value!") if x[0] == "-": x = x[1:] if x.isdigit(): x = -1 * int(x) gewd = True else: if x.isdigit(): x = int(x) gewd = True """ x = 0 y = -250 width = randint(8, 10) #The first element is not put into the list by the growTree function treeList = [(x, y, width, 0)] + growTree( paul, x, y, randint(70, 110), width, randint(20, 50), randint(200, 400), 0, random(), 0) raw_input("Press enter for next tree!")
def main(): width = 1024 height = 768 paul = Turtle(width, height) level = raw_input("Enter a level: ") fillSquare(paul, -512.0, 384.0, 1024.0, 768.0) pattern(paul, -512.0, 384.0, 1024.0, 768.0, level) raw_input("Press enter to exit: ")
def main(): #inputs radius1 = "alpha" centX1 = "alpha" centY1 = "alpha" #input error checking while radius1.isalpha() == True: radius1 = raw_input("Radius of the circle: ") if radius1.isdigit() == True: radius = int(radius1) elif radius1.isalpha() != True and radius1.isdigit != True: radius1 = "alpha" #catches the non-alpha, non-digit characters while centX1.isalpha() == True: centX1 = raw_input("X-coordinate of the center point.") if centX1.isdigit() == True: centX = int(centX1) elif centX1.isalpha() != True and centX1.isdigit != True: centX1 = "alpha" while centY1.isalpha() == True: centY1 = raw_input("Y-coordinate of the center point.") if centY1.isdigit() == True: centY = int(centY1) elif centY1.isalpha() != True and centY1.isdigit != True: centY1 = "alpha" #assign Turtle to t and set the the window to 500X600 t = Turtle(500, 600) t.setWidth(1) drawCircle(t, radius, centX, centY) # just to keep the window open raw_input("enter to continue")
def main(): turtle = Turtle() #turtle.setWidth(1) # Length of square length = 40 # Relative distances to corners from origin width = turtle.getWidth() / 2 height = turtle.getHeight() / 2 # Black turtle.setColor(0, 0, 0) # Upper left corner drawSquare(turtle, -width, height, length) # Gray turtle.setColor(127, 127, 127) # Lower left corner drawSquare(turtle, -width, length - height, length) # First random color turtle.setColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Upper right corner drawSquare(turtle, width - length, height, length) # Second random color turtle.setColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Lower right corner drawSquare(turtle, width - length, length - height, length)
def testCurves(): """Display first 7 curves and also level 10.""" for level in range(0, 7): turtle = Turtle() turtle.setColor(0, 0, 0) cCurve(turtle, 50, -50, 50, 50, level)
def main(): level = input("Enter the level (0 or greater): ") turtle = Turtle(400, 500) turtle.setWidth(1) cCurve(turtle, 50, -100, 50, 100, level)
def main(): turtle = Turtle(300, 350) turtle.setWidth(1) ccurve(turtle, 75, -75, 75, 75, 14)
""" File: randomwalk.py A turtle takes a random walk. """ from turtlegraphics import Turtle import random def randomWalk(turtle, turns, distance=20): turtle.setWidth(1) for x in xrange(turns): turtle.turn(random.randint(0, 360)) turtle.move(distance) randomWalk(Turtle(), 30)
def main(): turtle = Turtle() drawPolygon(turtle, [(20, 20), (-20, 20), (-20, -20)])
def main(): house = [ ] #A list containing all the primitives needed for drawing a house person = [ ] #A list containing all the primitives needed for drawing a person #Initialize the turtle paul = Turtle(900, 700) #Initializaing and appending objects that make up the house that we want to store into one list. #Initialize house1 and put into the according list house1 = Rectangle(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), -400, -200, 200, 200) #House frame house.append(house1) #Throw house1 into that list #Initialize house2 and put into the according list house2 = Rectangle(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), -350, -200, 40, 100) #Door house.append(house2) house3 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), -400, 0, -300, 50) #roof left diag house.append(house3) house4 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), -200, 0, -300, 50) #roof right diag house.append(house4) #We don't need the list of coords returned by this func #Draw all the trees!!!!!!!!!!!!!!!!!!!!!!!! growTree(paul, -150, -200, 90, 9, 30, 300, 0, 0.5, 0) growTree(paul, 50, -200, 90, 9, 30, 300, 0, 0.5, 0) growTree(paul, 150, -200, 90, 9, 30, 300, 0, 0.5, 0) growTree(paul, 250, -200, 90, 9, 30, 300, 0, 0.5, 0) growTree(paul, 350, -200, 90, 9, 30, 300, 0, 0.5, 0) paul.setWidth(5) #Iterate through the house list for primitive in house: #Draw the current primitive primitive.draw() pers1 = Circle(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), 100, -130, 10) #The head person.append(pers1) pers2 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), 100, -140, 100, -180) #The body line person.append(pers2) pers3 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), 80, -160, 100, -145) #larm person.append(pers3) pers4 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), 100, -145, 120, -160) #rarm person.append(pers4) pers5 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), 80, -200, 100, -180) #Left leg line person.append(pers5) pers6 = Line(paul, (randint(0, 255), randint(0, 255), randint(0, 255)), 120, -200, 100, -180) #Right leg line person.append(pers6) #Iterate through the person list for primitive in person: #Draw the current Primitive primitive.draw()