def draw_demo(turtle): width = turtle.window_width() height = turtle.window_height() cell_size = min(width/8.5, height/7) turtle.up() turtle.back(width*.475) turtle.left(90) turtle.forward(height*0.4) turtle.right(90) turtle.down() state1 = """\ 3|6 2|0 2 - 5 3 1|2 3 - - 3 1 4|3 6 - 5|5 6|6 1 """ draw_diagram(turtle, state1, cell_size, solution=True) turtle.right(90) turtle.forward(cell_size*7) turtle.left(90)
def B(distance): ''' This function defines a function B(distance) that moves the turtle backwards "distance" Inputs: Distance Distance: can be any float ''' turtle.back(distance)
def newSnow(size,n): x=size/2 y=.4 if n<=0 or size<10: return else: for i in range(2): if n%2==0: turtle.color("#0099CC") elif n%3==0: turtle.color("#B2DFEE") else: turtle.color("#00B2EE") turtle.forward(y*size/2) turtle.left(60) newSnow(x,n-1) turtle.right(120) newSnow(x,n-1) turtle.left(60) x/=2 y+=.2 if n%2==0: turtle.color("#0099CC") elif n%3==0: turtle.color("#B2DFEE") else: turtle.color("#00B2EE") turtle.forward(.4*size/2) turtle.up() turtle.back(1.4*size/2) turtle.down() return
def sig(x,y): ''' This function adds my signiture to the turtle drawing in a location x,y pre-conditions: the turtle is somwhere on the board post-conditions: the turtle is at the base fo my signiture ''' turtle.up() turtle.goto(x,y) turtle.down() turtle.setheading(0) turtle.left(90) turtle.forward(20) turtle.left(90) turtle.left(60) turtle.forward(23) turtle.left(180) turtle.forward(23) turtle.right(60) turtle.right(90) turtle.left(45) turtle.forward(27) turtle.left(135) turtle.forward(20) turtle.up() turtle.right(90) turtle.forward(15) turtle.down() turtle.right(90) turtle.forward(20) turtle.forward(-10) turtle.right(90) turtle.back(5) turtle.forward(60)
def treeSimpleVerbose(length, angle, minlength=10, level=0): recursionPrint("level: {} | length: {} | angle: {}".format(level, length, angle), level) if length < minlength: recursionPrint("length < {}, returning\n".format(minlength), level) return recursionPrint("forward({})".format(length), level) t.forward(length) recursionPrint("left({})".format(angle), level) t.left(angle) recursionPrint("calling first tree({}, {}, {})\n".format(length * 0.75, angle, level+1), level) treeSimpleVerbose(length * 0.75, angle, minlength=minlength, level=level+1) recursionPrint("right({})".format(2 * angle), level) t.right(2 * angle) recursionPrint("calling second tree({}, {}, {})\n".format(length * 0.75, angle, level+1), level) treeSimpleVerbose(length * 0.75, angle, minlength=minlength, level=level+1) recursionPrint("left({})".format(angle), level) t.left(angle) recursionPrint("back({})".format(length), level) t.back(length)
def drawA(length): """ Draw A. :pre: (relative) pos (0,0), heading (east), up :post: (relative) pos (length,0), heading (east), up :return: None """ turtle.down() turtle.left(90) turtle.forward(length) turtle.right(90) turtle.forward(length) turtle.right(90) turtle.forward(length) turtle.up() turtle.back(length/2) turtle.right(90) turtle.down() turtle.forward(length) turtle.up() turtle.back(length) turtle.left(90) turtle.forward(length/2) turtle.left(90)
def draw_arrow(turtle, cell_size, rotation=0): pos = turtle.pos() turtle.left(rotation) turtle.back(cell_size*.2) turtle.down() turtle.left(90) turtle.begin_fill() turtle.forward(cell_size*.05) turtle.right(90) turtle.forward(cell_size*.3) turtle.left(90) turtle.forward(cell_size*.1) turtle.right(120) turtle.forward(cell_size*.3) turtle.right(120) turtle.forward(cell_size*.3) turtle.right(120) turtle.forward(cell_size*.1) turtle.left(90) turtle.forward(cell_size*.3) turtle.right(90) turtle.forward(cell_size*.05) turtle.right(90) turtle.forward(cell_size*.2) turtle.end_fill() turtle.up() turtle.setpos(pos) turtle.right(rotation)
def joonista_puu(tyve_pikkus, min_haru_pikkus): """ Joonistab puu. Puu on fraktaalne/rekursiivne kujund, mille tüve küljes on kaks lühema tüvega alampuud: puu haru. Kui tyve_pikkus < min_haru_pikkus, siis puu koosneb ainult tüvest. Funktsioon taastab kilpkonna algse oleku. """ # Joonista tüvi turtle.forward(tyve_pikkus) # Kui tyve_pikkus > min_haru pikkus if tyve_pikkus > min_haru_pikkus: # Keera kilpkonna 45 kraadi vasakule turtle.left(45) # Joonista esimene alampuu 0.6*tyve_pikkus joonista_puu(0.6*tyve_pikkus, min_haru_pikkus) # Keera kilpkonna 90 kraadi paremale turtle.right(90) # Joonista teine alampuu joonista_puu(0.6*tyve_pikkus, min_haru_pikkus) # Taasta algne suund turtle.left(45) # Taasta algne olek turtle.back(tyve_pikkus)
def draw_tree(n, b, l, size): if n < 0: #base-case return elif n == 0: #Draw Leaves turtle.color("green") #Color of leaves turtle.width(1) numberOfLeaves = random.randint(5, 15) #Random number of leaves ranging from 5 to 15 angle = int(270 / numberOfLeaves) #Angle Range between leaves determined by number of leaves for i in range(numberOfLeaves): if (randomB(l)): angle2 = random.randint(0 + (i * angle), 0 + ((i + 1) * angle)) #Angle between different leaves can be different given the Angle Range angle2-=135 turtle.right(angle2) turtle.forward(5) turtle.back(5) turtle.left(angle2) return else: #Draw Tree turtle.color("brown") #Color of Tree turtle.forward(size) b1 = math.floor(5 * b) #Using Bushiness to calculate number of branches: Max branchess are 5 angle = int(270 / b1); #Angle Range between branches determined by Number of Branches for i in range(b1): if randomB(b1): angle2 = random.randint(0 + (i * angle), 0 + ((i + 1) * angle)) #Angle between different branches can be different given the Angle Range angle2-=135 turtle.right(angle2) draw_tree(n - 1, b, l, size * random.uniform(0.4, 0.7)) #Recursion step: size of sub-tree is random turtle.left(angle2) turtle.color("brown") turtle.back(size) return
def nextSlice(): """ Moves the turtle to the next slice. """ turtle.back(100) turtle.right(90) turtle.forward(1) turtle.left(90)
def draw_pips(turtle, pips, cell_size): PIP_PATTERNS = """\ ---+ | | | ---+ | O | | ---+ O | | O| ---+ O | O | O| ---+ O O| | O O| ---+ O O| O | O O| ---+ OOO| | OOO| ---+ """ pip_pattern = PIP_PATTERNS.splitlines()[pips*4+1:pips*4+4] pip_radius = cell_size*0.09 turtle.up() pos = turtle.pos() turtle.back(pip_radius*5) turtle.left(90) turtle.forward(pip_radius*5) turtle.right(90) for i in range(3): turtle.forward(pip_radius*2) turtle.right(90) turtle.forward(pip_radius) turtle.left(90) for j in range(3): if pip_pattern[i][j] == 'O': turtle.down() turtle.begin_fill() turtle.circle(-pip_radius) turtle.end_fill() turtle.up() turtle.forward(pip_radius*3) turtle.back(pip_radius*11) turtle.right(90) turtle.forward(pip_radius*2) turtle.left(90) turtle.setpos(pos)
def radar_chart(data): # Some "typical" test data #print "Hello" length=len(data) # stores the length of the data provided turtle.home() # Sets the turtle to position (0,0) division=360/length #what angle is needed for invidual lines poslist=[] #list to store current position valpos=[] #list to store position j=0 turtle.hideturtle() #hides the arrow #Draw the foundation of the Radar Chart for i in range(length): # Loop until all the given data is plotted turtle.forward(200) #move turtle forward turtle.dot(10,"black") # Draw the black dot at the end of each data nowpos=turtle.pos() # store the current position poslist.append(nowpos) #append the current position to list #turtle.hideturtle() turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data turtle.write(data[i], True, align="center") # Write the label of data turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position turtle.back(200) #return home turtle.left(division) # rotate by the specific angle turtle.home() # return to turtle home #Connect the ends points of the radar chart for i in poslist: # turtle.setpos(i[0],i[1]) #turtle.setpos(i[j],i[j+1]) #turtle.forward(100) #turtle.home() #turtle.degree(division) #turtle.heading() #turtle.forward(100) turtle.setpos(poslist[0][0],poslist[0][1]) turtle.home() #Draw green Dots for i in range(length): incval=data[i] turtle.forward(incval*2) turtle.dot(15,"green") nowpos=turtle.pos() valpos.append(nowpos) turtle.back(incval*2) turtle.left(division) turtle.begin_poly() turtle.fill(True) #Fill the green Dots for i in valpos: turtle.setpos(int(i[0]),int(i[1])) turtle.setpos(valpos[0][0],valpos[0][1]) turtle.end_poly() p = turtle.get_poly() turtle.register_shape("jpt", p) turtle.color("Green", "Green") turtle.begin_fill() #turtle.p(80) turtle.end_fill() turtle.fill(False)
def draw_whole_tree(x,y): size = 10 draw_tree(x,y) draw_star(size,x,y) for i in coords: turtle.goto(i) #draw_bauble() turtle.back(100) draw_pot()
def drawTree(n,size): if(n>0): turtle.forward(size) turtle.left(45) drawTree(n-1,size/2) turtle.right(90) drawTree(n-1,size/2) turtle.left(45) turtle.back(size)
def draw_wall(x, y): goto(x, y) turtle.color("red") if y % 2 == 0: turtle.seth(0) else: turtle.seth(90) turtle.forward(5) turtle.back(10)
def draw_tree(size, angle, min_size, scale_factor): if size > min_size: turtle.forward(size) turtle.right(angle) draw_tree(size * scale_factor, angle, min_size, scale_factor) turtle.left(angle*2) draw_tree(size * scale_factor, angle, min_size, scale_factor) turtle.right(angle) turtle.back(size)
def draw_star(xcor, ycor): turtle.up() turtle.setposition(xcor, ycor + 40) turtle.down() for x in range(0, 8): turtle.forward(30) turtle.back(30) turtle.left(45) turtle.up()
def draw_star(ycor): turtle.up() turtle.left(90) turtle.forward(ycor+40) turtle.down() for x in range(0, 8): turtle.forward(30) turtle.back(30) turtle.left(45) turtle.up()
def render(self): turtle.up() w=turtle.window_width() self.dist=w/len(self.string) turtle.back(w/2) turtle.shape("turtle") for c in self.string: self.draw(c) turtle.hideturtle() turtle.exitonclick()
def main(): """ :pre:(relative) pos (0,0), heading (east), up :post:(relative) pos (X,0), heading (east), up :return: none """ numberOfTree=int(raw_input("How many trees in your forest ?")) treeHome=["Mapel","Pine","bodhiTree"] dummy_house=raw_input("Is there a house in the forest (y/n)?") highestHeight=50 treeHomeRandom=[treeHome[r.randint(0,2)] for n in range(numberOfTree) ] if dummy_house in ['Y','y']: if numberOfTree>2: treeHomeRandom.insert(r.randint(1,numberOfTree-2),"House") elif numberOfTree<=2: treeHomeRandom.insert(1,"House") if numberOfTree <= 11: if dummy_house in ['Y','y']: init(-(numberOfTree+1)*100/2,-100) else: init(-(numberOfTree)*100/2,-100) else: init(-600,-100) #print(treeHomeRandom) totalWood=0 for myTree in treeHomeRandom: (length,totalWood)=treeAndHouse(myTree,totalWood) if length>highestHeight: highestHeight=length t.up() t.forward(100) t.down() t.up() t.back(100) star2(highestHeight+10) raw_input("Night is done Press Enter for day") t.reset() print("We have " + str(totalWood) +" units of lumber for building." ) print ("We will build a house with walls " + str((totalWood)/(2+math.sqrt(2)))+ " tall.") init(0,-300) house((totalWood)/(2+math.sqrt(2))) t.left(90) t.forward(3*abs((totalWood)/(2+math.sqrt(2)))/2+30) t.right(90) maple_shape(30) t.right(90) t.up() t.back(3*abs((totalWood)/(2+math.sqrt(2)))/2+30) t.right(90) raw_input("Day is done, house is build, Press enter to quit")
def drawStar(length): """ Draws a star during the night 10 pixels above the tallest tree :param length: length of one stroke of the star """ t.right(90) for _ in range(8): t.down() t.forward(length) t.up() t.back(length) t.left(45)
def drawK(): t.down() t.forward(50) t.back(25) t.right(60) t.forward(50) t.back(50) t.right(60) t.forward(50) t.up() t.left(30) t.forward(10)
def drawH(): t.down() t.left(90) t.forward(50) t.back(25) t.right(90) t.forward(50) t.left(90) t.forward(25) t.back(50) t.right(90) t.up() t.forward(10)
def c_uc(scale = 1): """ Draw a upper case c. """ turtle.down() turtle.forward(20*scale) turtle.back(20*scale) turtle.lt(90) turtle.forward(20*scale) turtle.rt(90) turtle.forward(20*scale) turtle.up() turtle.rt(90) turtle.forward(20*scale) turtle.lt(90)
def drawHouse(wallSize): turtle.pendown() turtle.left(90) turtle.forward(wallSize) turtle.right(45) turtle.forward(50*(2**.5)) turtle.right(90) turtle.forward(50*(2**.5)) turtle.right(45) turtle.forward(wallSize) turtle.left(90) turtle.back(wallSize) turtle.forward(wallSize) return 2 * (wallSize + wallSize / math.sqrt(2))
def c_lc(scale = 1): """ Draw a lower case c. """ turtle.down() turtle.forward(10*scale) turtle.back(10*scale) turtle.lt(90) turtle.forward(10*scale) turtle.rt(90) turtle.forward(10*scale) turtle.up() turtle.rt(90) turtle.forward(10*scale) turtle.lt(90)
def drawO(): t.left(90) t.down() t.forward(50) t.right(90) t.forward(50) t.right(90) t.forward(50) t.right(90) t.forward(50) t.back(50) t.left(180) t.up() t.forward(10)
def drawTongue(): """ Draw the tongue. :pre: (relative) pos (0,0), heading (east), up :post: (relative) pos (0,0), heading (east), up :return: None """ turtle.color('red') turtle.forward(25) turtle.left(90) turtle.forward(60) turtle.down() turtle.forward(25) turtle.left(45) turtle.forward(10) turtle.back(10) turtle.right(90) turtle.forward(10) turtle.back(10) turtle.left(45) turtle.up() turtle.back(85) turtle.right(90) turtle.back(25) turtle.color('black')
def draw_domino(turtle, domino, cell_size=50.0): turtle.up() turtle.back(cell_size*0.45) turtle.left(90) turtle.forward(cell_size*0.45) turtle.right(90) turtle.down() for _ in range(2): turtle.forward(cell_size*1.9) turtle.right(90) turtle.forward(cell_size*.9) turtle.right(90) turtle.up() turtle.forward(cell_size*.95) turtle.right(90) turtle.forward(cell_size*.1) turtle.down() turtle.forward(cell_size*.7) turtle.up() turtle.back(cell_size*.35) turtle.left(90) turtle.back(cell_size*.5) draw_pips(turtle, domino.head.pips, cell_size) turtle.forward(cell_size) draw_pips(turtle, domino.tail.pips, cell_size) turtle.back(cell_size)
def drawBase(size,n,widthh): turtle.width(widthh) widthh+=.5 if n<0: return else: turtle.forward(size) turtle.left(120) for i in range(6): turtle.forward(size) turtle.left(60) turtle.right(120) turtle.back(size) drawBase(.8*size,n-1,widthh) return
import turtle def minkowski_curve(rank: int, length: float) -> None: if rank > 0: turtle.right(30) minkowski_curve(rank - 1, length / 2) turtle.left(90) minkowski_curve(rank - 1, length / 2) turtle.right(90) minkowski_curve(rank - 1, length / 2) turtle.left(30) else: turtle.forward(length) def minkowski_sausage(rank: int, length: float) -> None: for i in range(0, 4): minkowski_curve(rank, length) turtle.right(90) turtle.speed(0) turtle.penup() turtle.back(150) turtle.pendown() minkowski_sausage(3, 100) turtle.done()
import turtle import random import time passo = 15 gradi = 90 turtle.color("red", "blue") turtle.speed(1) while (True): print("inserisci un comando (f/b/l/r) oppure q per uscire: ") com = input() if (com == "f"): turtle.forward(passo) elif (com == "b"): turtle.back(passo) elif (com == "l"): turtle.left(gradi) elif (com == "r"): turtle.right(gradi) elif (com == "q"): break else: print("comando inesistente") #turtle.done() #toggle comment for the permanent turtle screen after exit with 'q' time.sleep(2) turtle.Screen.bye() #close the turtle screen after exit
vzdalenost = randrange( 80, 150, 10) #nahodná vdálenost z intervalu pro vykresleni dalšího obličeje pensize(2) pencolor("black") fillcolor("yellow") begin_fill() circle(50) #oblicej end_fill() up() circle(50, 180) right(45) down() for n in range(4): #vlasy forward(30) back(30) right(30) up() right(105) #otočení želvy směrem od vrcholu hlavy k obličeji forward(30) # posun na leve oko right(90) forward(20) def oko(): down() fillcolor('black') begin_fill() circle(6) #vykresleni leveho oka end_fill() up()
#Casale Alex 13-03-2019 import turtle as t #alias passo = 50 angolo = 90 comandi = input("Inserisci la stringa: ") for k in comandi: if (k == 'f'): t.forward(passo) elif (k == 'l'): t.left(angolo) elif (k == 'r'): t.right(angolo) elif (k == 'b'): t.back(passo) else: print("Comando inesistente [commands: f, b, r, l]") t.done()
def draw(spot, mark, board): turtle.up() turtle.back(10) if (spot == 1 or spot == 4 or spot == 7): if (spot == 4): turtle.right(90) turtle.forward(100) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() elif (spot == 7): turtle.right(90) turtle.forward(200) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() else: if (mark == "X"): drawX() else: drawO() elif (spot == 2 or spot == 5 or spot == 8): turtle.forward(100) if (spot == 5): turtle.right(90) turtle.forward(100) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() elif (spot == 8): turtle.right(90) turtle.forward(200) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() else: if (mark == "X"): drawX() else: drawO() else: turtle.forward(200) if (spot == 6): turtle.right(90) turtle.forward(100) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() elif (spot == 9): turtle.right(90) turtle.forward(200) turtle.left(90) turtle.down() if (mark == "X"): drawX() else: drawO() else: if (mark == "X"): drawX() else: drawO()
t.setup(wnWidth, wnHeight, 0, 0) # window size, turtle initial position # set window coordinates of bottom-left corner to 0,0 t.setworldcoordinates(0, 0, wnWidth, wnHeight) # pen properties (turtle starts out pointed horizontally to the right) t.speed(turtleSpeeds[4]) # initial pen position t.penup() # don't draw while positioning t.setpos(penX, penY) # set pen position setup(windowTitle, windowWidth, windowHeight, windowWidth / 2, windowHeight * 0.5, bgColor) # set up shape t.color(lineColor) # set pen color t.width(16) # set pen width starPoints = 5 lineLgth = 200 t.pendown() t.left(90) for i in range(1, starPoints + 1): t.forward(lineLgth) t.back(lineLgth) t.right(360 / starPoints) t.dot(256, dotColor) t.exitonclick() # keep window open until mouse click
#drawing a cross import turtle turtle.back(100) turtle.forward(200) turtle.back(100) turtle.rt(90) turtle.forward(100) turtle.back(200) turtle.forward(100)
import turtle turtle.left(90) turtle.forward(20) turtle.left(90) turtle.left(60) turtle.forward(23) turtle.left(180) turtle.forward(23) turtle.right(60) turtle.right(90) turtle.left(45) turtle.forward(27) turtle.left(135) turtle.forward(20) turtle.up() turtle.right(90) turtle.forward(15) turtle.down() turtle.right(90) turtle.forward(20) turtle.forward(-10) turtle.right(90) turtle.back(5) turtle.forward(60) input('enter to con')
turtle.pendown() a = 0 turtle.seth(c) while a < resolution: turtle.left(360/resolution) a += 1 turtle.forward(100*scale) turtle.penup() turtle.forward(10*scale) if text: turtle.write(getH(),align="center",font=('Arial',textSize,'normal')) if turtle.heading() == 270 and (90/(360/resolution)).is_integer(): turtle.back(110*scale) turtle.pendown() continue turtle.back(10*scale) turtle.pendown() b = turtle.ycor() turtle.color("red") turtle.sety(10*scale+yOffset) turtle.penup() turtle.sety(0*scale+yOffset) turtle.color("black") turtle.pendown() turtle.sety(-10*scale+yOffset) turtle.penup() turtle.sety(-20*scale+yOffset) if text:
import turtle turtle.penup() turtle.goto(-600, 200) turtle.pendown() turtle.forward(200) turtle.right(135) turtle.forward(280) turtle.back(120) turtle.left(90) turtle.forward(150) turtle.left(45) turtle.penup() turtle.goto(-350, 100) turtle.pendown() turtle.forward(100) turtle.left(90) turtle.forward(170) turtle.back(340) turtle.penup() turtle.goto(-500, -150) turtle.pendown() turtle.left(180) turtle.circle(100) turtle.penup() turtle.goto(-180, 250) turtle.pendown() turtle.left(90) turtle.forward(250) turtle.back(250)
def Jumper(): t.pensize(2) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.forward(60) t.down() t.begin_fill() t.left(90) t.circle(60) t.end_fill() t.up() t.circle(60, 160) t.pencolor('#00c3f3') t.fillcolor('#00c3f3') t.left(25) t.down() t.begin_fill() t.circle(80, 90) t.pencolor('#0171b9') t.left(25) t.circle(60, -135) t.end_fill() t.up() t.left(45) t.forward(38) t.right(80) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.circle(5, -180) t.right(10) t.circle(-25, -40) t.left(50) t.back(10) t.left(80) t.circle(-20, 80) t.right(25) t.circle(-15, 60) t.circle(-40, 35) t.end_fill() t.up() t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.begin_fill() t.right(170) t.down() t.circle(30, 50) t.circle(7, 120) t.circle(15, 25) t.left(95) t.pencolor('#0171b9') t.back(6) t.left(80) t.circle(-20, 80) t.right(25) t.circle(-15, 60) t.circle(-40, 35) t.end_fill() t.up() t.right(90) t.forward(35) t.right(80) t.down() t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.begin_fill() t.circle(35, 50) t.circle(5, 100) t.circle(60, 38) t.circle(5, 90) t.circle(40, 25) t.left(20) t.circle(30, 30) t.end_fill() t.up() t.left(150) t.forward(20) t.right(70) t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.down() t.begin_fill() t.circle(-16, 60) t.forward(13) t.right(28) t.pencolor('#0171b9') t.circle(-60, -23) t.circle(-5, -100) t.back(5) t.end_fill() t.up() t.left(70) t.forward(20) t.right(115) t.down() t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.begin_fill() t.circle(30, 20) t.circle(7, 80) t.circle(65, 30) t.circle(5, 120) t.circle(60, 22) t.left(45) t.circle(-30, 30) t.end_fill() t.up() t.left(100) t.forward(2) t.down() t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.begin_fill() t.circle(15, 50) t.circle(30, 35) t.pencolor('#0171b9') t.left(16) t.circle(60, -25) t.right(20) t.circle(10, -120) t.end_fill() t.left(190) t.forward(5) t.up() t.right(7) t.forward(60) t.right(92) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.circle(-40, 20) t.circle(-9, 95) t.circle(-40, 20) t.right(130) t.circle(60, 30) t.end_fill() t.up() t.left(75) t.forward(117) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.left(10) t.circle(-65, 80) t.circle(-20, 185) t.right(180) t.circle(-65, -54) t.left(80) t.circle(60, 6) t.right(65) t.end_fill() t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.begin_fill() t.circle(-75, 65) t.circle(-30, 30) t.right(35) t.pencolor('#0171b9') t.circle(-20, -64) t.circle(-75, -65) t.end_fill() t.up() t.right(115) t.forward(25) t.left(95) t.pencolor('#0171b9') t.fillcolor('#84d4f7') t.down() t.begin_fill() t.circle(-40, 30) t.circle(-35, 170) t.circle(-13, 120) t.circle(-50, 40) t.circle(-50, -8) t.right(90) t.circle(-30, -60) t.end_fill() t.left(90) t.circle(60, 10) t.right(100) t.pencolor('#02c2f4') t.fillcolor('#02c2f4') t.down() t.begin_fill() t.circle(-60, 50) t.circle(-8, 40) t.circle(-40, 75) t.right(60) t.forward(5) t.right(40) t.circle(-45, 55) t.pencolor('#0171b9') t.right(20) t.circle(-40, -55) t.left(30) t.circle(-18, -60) t.left(15) t.circle(-30, -28) t.circle(-40, -70) t.left(15) t.circle(-40, -80) t.end_fill() t.up() t.right(40) t.back(17) t.pensize(4) t.down() t.circle(-10, 70) t.up() t.circle(-60, 20) t.right(20) t.down() t.circle(10, 70) t.up() t.pensize(2) t.fillcolor('white') t.right(150) t.forward(30) t.right(120) t.down() t.begin_fill() t.circle(30, 30) t.circle(15, 170) t.circle(30, 30) t.circle(13, 160) t.end_fill() t.begin_fill() t.right(70) t.circle(-30, 10) t.circle(-13, 110) t.circle(-30, 40) t.circle(-10, 150) t.left(30) t.circle(-20, 35) t.right(10) t.circle(40, 20) t.end_fill() t.back(20) t.pencolor('black') t.fillcolor('black') t.begin_fill() t.circle(-5, 490) t.end_fill() t.pencolor('white') t.fillcolor('white') t.begin_fill() t.circle(-2) t.end_fill() t.up() t.left(20) t.back(30) t.left(80) t.down() t.pencolor('black') t.fillcolor('black') t.begin_fill() t.circle(-5, 490) t.end_fill() t.pencolor('white') t.fillcolor('white') t.begin_fill() t.circle(-2) t.end_fill() t.up() t.pencolor('#f37694') t.fillcolor('#f37694') t.right(17) t.forward(23) t.down() t.begin_fill() t.circle(4) t.end_fill() t.up() t.pencolor('#0171b9') t.fillcolor('#ef4d40') t.left(10) t.forward(7) t.right(30) t.down() t.circle(-20, 25) t.up() t.right(65) t.back(25) t.down() t.begin_fill() t.left(27) t.circle(-40, 90) t.back(8) t.left(155) t.circle(30, 70) t.circle(6, 90) t.circle(-20, 40) t.up() t.right(90) t.forward(5) t.left(90) t.down() t.end_fill() t.up() t.left(120) t.forward(12) t.left(120) t.down() t.fillcolor('white') t.begin_fill() t.circle(-10, 150) t.right(40) t.circle(-20, 15) t.circle(-10, 25) t.end_fill() t.right(60) t.forward(20) t.back(10) t.right(80) t.circle(-10, 60) t.up() t.home()
draw_turtle("right", 115, 100) # --- Боковая сторона коробки --- draw_turtle("right", 65, 100) draw_turtle("left", 115, 100) draw_turtle("left", 65, 100) turtle.width(2) draw_turtle("left", 115, 100) turtle.width(1) # --- Крышка коробки --- # Начинаем окрашивать крышку коробки turtle.fillcolor("#d2935f") turtle.begin_fill() draw_turtle("left", 100, 30) draw_turtle("left", 80, 100) draw_turtle("left", 100, 30) # Заканчиваем окрашивать крышку коробки turtle.end_fill() # --- Внутренняя задняя стенка коробки --- draw_turtle("left", 30, 100) draw_turtle("left", 115, 85) # --- Внутренняя левая стенка коробки --- turtle.back(85) draw_turtle("right", 65, 100) turtle.done()
# oppgåve 1e) import turtle vinkel = int(input("Velg vinkel: ")) ganger = int(360 / vinkel) for tall in range(1, ganger + 1): turtle.forward(50) turtle.back(50) turtle.left(vinkel) turtle.done()
turtle.goto(100, -110) # 裤子端 turtle.down() turtle.goto(150, -50) # 肩膀端 turtle.begin_fill() turtle.fd(15) turtle.goto(90, -100) turtle.goto(100, -110) turtle.end_fill() turtle.up() turtle.begin_fill() turtle.goto(-90, -100) turtle.down() turtle.goto(-150, -35) turtle.back(15) turtle.goto(-100, -113) turtle.goto(-90, -100) turtle.end_fill() #画裤兜 turtle.width(4) turtle.up() turtle.goto(-50, -150) turtle.down() turtle.goto(50, -150) turtle.back(30) turtle.up() turtle.goto(-50, -150) turtle.down() turtle.back(30)
import turtle turtle.shape('turtle') legs = 12 length = 100 for i in range(legs): turtle.forward(length) turtle.stamp() turtle.back(length) turtle.right(360 / legs)
def main(): t.up() t.back(200) t.down() drawfiveSquare(SIDELEN)
turtle.goto(-300,-300) turtle.setheading(0) turtle.pendown() #-----------------------Ground--------------------- turtle.begin_fill() turtle.color("yellow") turtle.forward(90) turtle.left(90) turtle.forward(15) turtle.left(90) turtle.forward(90) turtle.left(90) turtle.forward(15) turtle.back(15) turtle.left(90) turtle.end_fill() turtle.forward(15) turtle.begin_fill() turtle.left(90) turtle.forward(15) turtle.right(90) turtle.forward(60) turtle.right(90) turtle.forward(15) turtle.end_fill() turtle.back(15) turtle.right(90)
turtle.right(165) turtle.forward(400) turtle.left(145) turtle.forward(400) turtle.right(160) turtle.forward(400) turtle.penup() turtle.left(90) turtle.forward(100) turtle.left(90) turtle.pendown() turtle.forward(400) turtle.right(90) turtle.forward(200) turtle.penup() turtle.back(200) turtle.right(90) turtle.forward(200) turtle.left(90) turtle.pendown() turtle.forward(200) turtle.back(200) turtle.right(90) turtle.forward(200) turtle.left(90) turtle.forward(200) turtle.penup() turtle.forward(100) turtle.left(90) turtle.pendown() turtle.forward(400)
def main(argv): # First we attempt to get the options from the command line try: options, args = getopt.getopt(argv, "s:a:m:f:d:h") except getopt.GetoptError: print("""Call via `python fractal_tree.py`\n Use `python fractal_tree.py -h` for help""") # exit status 2 for command line error sys.exit(2) # Preset options to default values starting_size = 100 angle = 50 minimum_size = 10 scale_factor = 2.0 / 3.0 draw_speed = 8 # Check if there are any option changes for option, argument in options: if option == "-h": print("The following flags are available:") print(" -s Size: Length of initial branch") print(" Default: 100") print(" -a Angle: Deviation to each side of the branch (degrees)") print(" Default: 50") print(" -m Min: Smallest branch size") print(" Default: 10") print(" -f Scale Factor: How much each branch should shrink by") print(" !!!!! MUST BE LESS THAN 1 !!!!!") print(" Default: 2/3") print(" -d Draw speed: How fast the pen will move.") print(" Values of 0 to 10 are accepted. 0 means no animation.") print(" Default: 5") sys.exit(0) elif option == "-s": if float(argument) > 0: starting_size = float(argument) else: raise RuntimeError( "The starting size was less than or equal to 0") elif option == "-a": angle = float(argument) elif option == "-m": if float(minimum_size) > 0: minimum_size = float(argument) else: raise RuntimeError("Minimum size must be greater than 0") elif option == "-f": if float(argument) < 1 and float(argument) > 0: scale_factor = float(argument) else: raise RuntimeError( "The scale factor passed in was not less than 1") elif option == "-d": # No checking is needed because the turtle.speed() takes care of the range draw_speed = float(argument) # Begin by prepositioning the turtle # We can begin drawing by simply calling turtle's methods # Set the drawing speed turtle.speed(draw_speed) # Turn left 90 degrees so the tree draws right way up turtle.left(90) # Lift the pen so it doesn't draw right away turtle.penup() # Move back from the middle to create room for the tree # Height of the tree = starting size / (1 - scale factor) # This is just the sum of a geometric series # We center on half the height turtle.back(.5 * (starting_size / (1 - scale_factor))) # Place the pen back down turtle.pendown() # Now we just draw the tree draw_tree(starting_size, angle, minimum_size, scale_factor) input("Press Enter to close the window")
# -*- coding: utf-8 -*- """ Created on Mon Dec 23 18:54:41 2019 @author: Roy """ import imghdr import turtle import random imgtyp = imghdr.what('JPSean.jpeg') print(imgtyp) turtle.color('red', 'yellow') for i in range(1, 5): for turns in range(1, 24): turtle.forward(25) turtle.right(15) turtle.forward(25) turtle.back(25) print('done')
print("import command packages") print("import turtle command drawing package, there are many pakages") import turtle print("# allows us to use turtle") wn = turtle.Screen() print("#Creates a playground for turtle. Not must?") tut = turtle.Turtle() print("# Creates aturtle, assign to tut") tut = turtle.pen() print("Above, Not must necessary") tut = turtle.forward(200) tut = turtle.back(120) tut = turtle.left(200) tut = turtle.back(120) tut = turtle.forward(20) tut = turtle.left(20) tut = turtle.forward(120) tut = turtle.back(120) tut = turtle.right(20) tut = turtle.forward(120) tut = turtle.left(20) tut = turtle.forward(120) tut = turtle.right(20) tut = turtle.forward(120) tut = turtle.right(20) tut = turtle.back(120) tut = wn.mainloop() print(" Work 'tut = wn.mainloop()' necessary")
def draw(self): """ This method draws the beam that it is called on and all weights hanging from it. It does so recursively. The base case is when this method is called on a Weight object. To draw the entire puzzle, we would call this method on the head of the puzzle, the top most beam. :return: None :pre (for first call): Pos ( 0, 0 ) Heading( East ) :pre: Pos( Some position along the beam that it hangs from, relative to the origin) Heading( South ) :post: Pos( Some position along the beam that it hangs from, relative to the origin) Heading( South ) """ # The turtle must always start by facing south turtle.setheading(SOUTH) # Draw a vertical line downward from the beam # above turtle.forward(BEAM_LEVEL) # Position in this beams list of hanging objects index = 0 # Turn to draw the left hanging objects turtle.right(RIGHT_AN) # So long as there are objects to draw, and they # are on the left hand side of the beam, keep going while index != len(self.hanging) and int( self.hanging[index].distance) < 0: # Draw out to where the object hangs from the beam turtle.forward((self.hanging[index].distance * -1) * self.scale) turtle.left(RIGHT_AN) # Make a recursive call upon the object # hanging from this beam self.hanging[index].draw() turtle.right(RIGHT_AN) # Move back turtle.back((self.hanging[index].distance * -1) * self.scale) # Increment the value of the index index = index + 1 # Turn to draw the right hanging objects turtle.right(180) # So long as there are objects to draw, and they # are on the right hand side of the beam, keep going while index != len(self.hanging) and int( self.hanging[index].distance) > 0: # Draw out to where the object hangs from the beam turtle.forward(self.hanging[index].distance * self.scale) turtle.right(RIGHT_AN) # Make a recursive call upon the object # hanging from this beam self.hanging[index].draw() turtle.left(RIGHT_AN) # Move back turtle.back(self.hanging[index].distance * self.scale) # Increment the value of the index index = index + 1 # Move the turtle back to where it started turtle.right(RIGHT_AN) turtle.back(BEAM_LEVEL)
x_in_turtle_kords=x/(xmax-xmin)*(xtmax-xtmin) y_in_turtle_kords=y/(ymax-ymin)*(ytmax-ytmin) return x_in_turtle_kords, y_in_turtle_kords x=0 #værdierne af nedenståedne variabler afgør hvor langt der er #mellem tallene på h.h. x- og y-aksen Laengde_x=5 Laengde_y=5 t.pendown() while True: t.goto(konverter_til_turtle_ks(x,0)) t.left(90) t.forward(5) t.write(x) t.back(10) t.forward(5) t.right(90) x=x+Laengde_x if x > xmax: break x=0 y=0 t.penup() t.goto(0,0) t.pendown() t.setheading(90) while True: t.goto(konverter_til_turtle_ks(0,y)) t.left(90) t.forward(5)
turtle.left(90) turtle.forward(40) turtle.left(90) turtle.forward(r9) turtle.up() turtle.forward(t9) turtle.down() turtle.forward(t9) turtle.left(90) turtle.forward(800) turtle.up() turtle.goto(-400, 350) turtle.down() turtle.back(600) turtle.up() turtle.color("red") turtle.shape("turtle") turtle.goto(-400, 380) turtle.right(90) turtle.pendown() # You simply have to beat the maze # You are not allowed to change code above, go round the outside, teleport etc. # This challenge was made by a year 9 girl! # Start coding the solution below. # You can use lists & variables above to help. turtle.speed(8) liner = [r1, r2, r3, r4, r5, r6, r7, r8]
import turtle turtle.penup() turtle.back(250) turtle.pendown() turtle.forward(100) turtle.right(135) turtle.forward(100) turtle.penup() turtle.right(135) turtle.right(90) turtle.forward(120) turtle.left(90) turtle.pendown() turtle.forward(100) turtle.penup() turtle.right(180) turtle.forward(130) turtle.forward(20) turtle.pendown() turtle.forward(50) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(50) turtle.right(90) turtle.forward(100) turtle.penup() turtle.left(90) turtle.forward(150) turtle.right(90)
import turtle turtle.shape('turtle') turtle.speed('slow') fr = 100 n = 12 rot = 360 / n + 360 turtle.right(360 / n) for i in range(n): turtle.forward(fr) turtle.stamp() turtle.back(fr) turtle.right(rot)
turtle.right(90) turtle.forward(100) turtle.dot() turtle.right(90) turtle.forward(15) turtle.penup() turtle.forward(15) turtle.pendown() turtle.forward(15) turtle.penup() turtle.forward(15) turtle.pendown() turtle.forward(15) turtle.penup() turtle.forward(15) turtle.pendown() turtle.forward(15) turtle.dot() turtle.right(90) turtle.forward(100) turtle.dot() turtle.right(133) turtle.forward(75) turtle.dot() turtle.forward(75) turtle.back(75) turtle.right(93) turtle.forward(76) turtle.right(180) turtle.forward(150)
import turtle def koch_curve(rank: int, length: float) -> None: if rank > 0: koch_curve(rank - 1, length / 2) turtle.left(60) koch_curve(rank - 1, length / 2) turtle.right(120) koch_curve(rank - 1, length / 2) turtle.left(60) koch_curve(rank - 1, length / 2) else: turtle.forward(length) turtle.speed(0) turtle.penup() turtle.back(350) turtle.pendown() koch_curve(3, 200) turtle.done()
def Chiko(): t.pensize(2) t.pencolor('#3b1546') t.fillcolor('#623683') t.up() t.right(90) t.forward(30) t.left(90) t.forward(60) t.down() t.begin_fill() t.left(30) t.forward(25) t.left(100) t.forward(20) t.right(70) t.forward(35) t.left(110) t.forward(25) t.right(70) t.forward(45) t.left(95) t.forward(45) t.right(70) t.forward(35) t.left(110) t.forward(35) t.right(65) t.forward(35) t.left(110) t.forward(30) t.right(70) t.forward(30) t.left(100) t.forward(20) t.end_fill() t.up() t.home() t.pencolor('#781d3c') t.fillcolor('#d4597f') t.up() t.forward(60) t.down() t.begin_fill() t.left(90) t.circle(60, 20) t.right(110) t.circle(7, 300) t.right(180) t.circle(60, 60) t.circle(10, 50) t.forward(5) t.right(120) t.circle(13, 50) t.left(30) t.circle(67, 270) t.end_fill() t.fillcolor('#bd4a6b') t.begin_fill() t.circle(67, -80) t.left(20) t.pencolor('#bd4a6b') t.circle(130, 40) t.end_fill() t.circle(130, -40) t.right(22) t.pencolor('#781d3c') t.circle(67, 80) t.up() t.left(5) t.forward(30) t.left(110) t.down() t.pensize(8) t.pencolor('#3b1546') t.fillcolor('white') t.forward(28) t.right(80) t.begin_fill() t.circle(20, 490) t.end_fill() t.right(86) t.forward(8) t.left(86) t.begin_fill() t.circle(-20, 550) t.end_fill() t.left(45) t.forward(20) t.up() t.left(32) t.back(46) t.down() t.pencolor('black') t.circle(1) t.up() t.right(160) t.forward(28) t.down() t.circle(1) t.up() t.left(95) t.forward(40) t.right(85) t.pensize(5) t.pencolor('#8e1237') t.down() t.circle(-30, 30) t.circle(-30, -30) t.up() t.back(25) t.right(20) t.down() t.circle(-30, -30) t.up() t.right(80) t.forward(57) t.down() t.pencolor('#8f0f37') t.circle(2) t.forward(2) t.pensize(2) t.right(20) t.forward(10) t.circle(9, 160) t.up() t.right(87) t.forward(40) t.right(75) t.pencolor() t.fillcolor('#d5597d') t.pencolor('#7b1735') t.pensize(2) t.begin_fill() t.down() t.left(50) t.circle(-30, 55) t.circle(-5, 180) t.circle(30, 50) t.circle(-5, 200) t.forward(15) t.end_fill() t.up() t.right(110) t.forward(110) t.left(20) t.down() t.begin_fill() t.circle(-10, 80) t.circle(-20, 60) t.left(40) t.circle(-60, -20) t.end_fill() t.up() t.right(160) t.forward(50) t.right(45) t.down() t.begin_fill() t.circle(-10, 60) t.circle(5, 120) t.circle(20, 40) t.circle(5, 90) t.circle(60, 17) t.left(70) t.forward(7) t.end_fill() t.up() t.back(7) t.left(90) t.down() t.begin_fill() t.circle(60, 20) t.circle(5, 45) t.circle(20, 37) t.circle(5, 120) t.circle(10, 60) t.right(90) t.forward(10) t.left(80) t.forward(10) t.end_fill() t.up() t.home()
tree(length * 0.75, angle, (color[0], color[1] + 3, color[2] + 1), width * 1.03) t.right(2 * angle) tree(length * 0.75, angle, (color[0], color[1] + 3, color[2] + 1), width * 1.03) t.left(angle) t.color(gcolor) t.penup() t.back(length) glength = 200 gangle = 20 minlength = 50 gcolor = (168, 106, 39) width = 1.5 t.speed(speed="normal") t.left(90) t.penup() t.back(400) t.pendown() treeSimpleVerbose(glength, gangle, minlength=minlength) # verbose drawing #tree(glength, gangle, gcolor, width) t.mainloop()