def kwadratZolty(a): dlBokKw = a / 5 turtle.colormode(255) turtle.fillcolor(255, 255, 0) turtle.begin_fill() kwadrOdWierz(dlBokKw) turtle.end_fill()
def drawBar(): turtle.penup() turtle.hideturtle() xAxis=-600 yAxis=-200 turtle.goto(xAxis,yAxis) turtle.color("green") turtle.fillcolor("green") failTurtle=turtle.Turtle() failTurtle.hideturtle() failTurtle.penup() failTurtle.goto(xAxis + 50,yAxis) failTurtle.color("red") failTurtle.fillcolor("red") drawAxis(xTurtle, False) drawAxis(yTurtle, True) yNoPassTurtle.hideturtle() yNoFailTurtle.hideturtle() for i in range(len(studentsYear)): studenPerYear = studentsYear[i] passNo=int(studenPerYear.passNum)*5 failNo=int(studenPerYear.failNum)*5 graphPlot(turtle,passNo,i,yNoPassTurtle,False, studenPerYear) graphPlot(failTurtle,failNo,i,yNoFailTurtle,True,studenPerYear) xAxis=xAxis+150 turtle.goto(xAxis,yAxis) failTurtle.goto(xAxis+50,yAxis)
def draw_move(turtle, cell_size, offset, domino, dx, dy, move_num, step_count): shade = (move_num-1) * 1.0/step_count rgb = (0, 1-shade, shade) turtle.forward((domino.head.x-offset[0]) * cell_size) turtle.left(90) turtle.forward((domino.head.y-offset[1]) * cell_size) turtle.right(90) turtle.setheading(domino.degrees) turtle.forward(cell_size*.5) turtle.setheading(math.atan2(dy, dx) * 180/math.pi) pen = turtle.pen() turtle.pencolor(rgb) circle_pos = turtle.pos() turtle.width(4) turtle.forward(cell_size*0.05) turtle.down() turtle.forward(cell_size*0.4) turtle.up() turtle.pen(pen) turtle.setpos(circle_pos) turtle.forward(8) turtle.setheading(270) turtle.forward(8) turtle.left(90) turtle.down() turtle.pencolor(rgb) turtle.fillcolor('white') turtle.begin_fill() turtle.circle(8) turtle.end_fill() turtle.pen(pen) turtle.write(move_num, align='center') turtle.up()
def circunferencia(simbolos,identificador,linea): p1= obtener_punto(2,identificador,simbolos) radio = obtener_radio(identificador,simbolos) x1 = obtener_x(p1,simbolos) y1 = obtener_y(p1,simbolos) escalar = obtener_escalar(identificador, simbolos,linea) relleno = obtener_color(obtener_relleno(identificador,simbolos,linea)) borde = obtener_color(obtener_borde(identificador,simbolos,linea)) turtle.color(borde) if escalar == 0: escalar=1 tx = obtener_tx(identificador, simbolos,linea) ty = obtener_ty(identificador, simbolos,linea) turtle.pensize(8) turtle.penup() #Trasladar circunferencia x1 = x1 + tx y1 = y1 + ty #turtle.setposition(x1, y1-(radio*44)) #turtle.pendown() #turtle.circle(radio*44) #Escalar circunferencia turtle.penup() #turtle.setposition(x1, y1-(radio*44*escalar)) turtle.setposition(x1*44, (y1*44)-(radio*44*escalar)) turtle.pendown() turtle.fillcolor(relleno) turtle.begin_fill() turtle.circle(radio*44*escalar) turtle.end_fill()
def bloom(radius): for iter in range(18): turtle.circle(radius,20) turtle.begin_fill(); turtle.fillcolor(random.random(),random.random(),random.random()) turtle.circle(-radius/5) turtle.end_fill();
def jeden(): turtle.fd(50) turtle.fillcolor(randint(0,255),randint(0,255),randint(0,255)) turtle.begin_fill() kwadrat(50) turtle.end_fill() turtle.bk(50)
def pezzo(color, colors = colors, unit = unit, alfa = alfa, depth = depth): turtle.pencolor(colors[color]) turtle.fillcolor(color) turtle.begin_fill() for i in range(2): turtle.forward(unit) turtle.left(90) turtle.forward(unit) turtle.left(90) turtle.forward(unit) for i in range(2): turtle.left(alfa) turtle.forward(depth) turtle.left(alfa) turtle.forward(unit) turtle.left(90) turtle.backward(unit) turtle.left(90) turtle.forward(unit) turtle.right(90) for i in range(2): turtle.forward(unit) turtle.left(alfa) turtle.forward(depth) turtle.left(180-alfa) turtle.end_fill() turtle.right(90) turtle.forward(unit) turtle.left(90)
def draw_tree(x,y): startPosX = x startPosY = y turtle.setpos(x,y) turtle.fillcolor("green") turtle.begin_fill() for i in range(0,4): x -=40 y -=80 turtle.goto(x,y) coords.append(turtle.pos()) x += 20 turtle.goto(x,y) bottomCorner = turtle.pos() x = startPosX y = startPosY turtle.setpos(x,y) for i in range(0,4): x +=40 y -=80 turtle.goto(x,y) coords.append(turtle.pos()) x -= 20 turtle.goto(x,y) turtle.goto(bottomCorner) turtle.end_fill()
def base(color = 'blue',colors = colors, lato = lato, unit = unit, alfa = alfa, depth = depth, height = height): turtle.pencolor(colors[color]) turtle.fillcolor(color) turtle.begin_fill() turtle.forward(unit*lato) turtle.left(alfa) turtle.forward(depth*lato) turtle.left(alfa) turtle.forward(height) turtle.left(90+alfa) turtle.forward(depth*lato) turtle.left(alfa) turtle.forward(height) turtle.backward(height) turtle.right(90) turtle.forward(lato*unit) turtle.left(90) turtle.forward(height) turtle.right(180) turtle.forward(height) turtle.right(alfa) turtle.forward(depth*lato) turtle.right(alfa) turtle.forward(lato*unit) turtle.left(alfa) turtle.backward(depth*lato) turtle.right(alfa) turtle.backward(unit*lato) turtle.end_fill() line_base()
def random_col(): x=r.randint(100,250) y=r.randint(180,250) z=r.randint(200,255) t.pencolor(x,y,z) t.fillcolor(z,x,y) return
def Sierpinski(side, steps): """Draw a Sierpinski triangle fractal, recursing the given number of steps. Assume we're starting from a black triangle of with sides of size side*2, point down, with the turtle at the bottom point. """ if not steps: return # Clear a white triangle in the center. turtle.setheading(120) turtle.penup() turtle.forward(side) turtle.pendown() turtle.fill(True) turtle.fillcolor("white") turtle.right(120) turtle.forward(side) turtle.left(120) turtle.forward(side) turtle.left(120) turtle.forward(side) turtle.fill(False) # For each of the black sub-triangles left, run recursively. Sierpinski(side/2, steps-1) turtle.setheading(0) turtle.penup() turtle.forward(side) Sierpinski(side/2, steps-1) turtle.setheading(240) turtle.penup() turtle.forward(side) Sierpinski(side/2, steps-1)
def drawFins(size): turtle.fillcolor("red") turtle.setheading(90) turtle.begin_fill() turtle.forward(0.2*size) turtle.left(120) turtle.forward(0.6*size) turtle.right(120) turtle.forward(0.3*size) turtle.right(40) turtle.forward(0.8*size) turtle.end_fill() turtle.setheading(0) turtle.begin_fill() turtle.penup() turtle.forward(size) turtle.pendown() turtle.begin_fill() turtle.right(50) turtle.forward(0.8*size) turtle.right(40) turtle.forward(0.3*size) turtle.right(120) turtle.forward(0.6*size) turtle.end_fill()
def draw_rectangle(length_float, width_float, color_str): """ Asks for the length, width, and color of the rectangle and draws it using turtle Recieve: The length, width and color of the triangle Return: Nothing Algorithm: Use a for loop and draw a rectangle by going forward the specified length and making a 90 degree turn to the right and then going forward the width and turning 90 degrees to the right Then do the loop again """ turtle.fillcolor(color_str) turtle.pendown() turtle.begin_fill() for i in range(2): turtle.forward(length_float) turtle.right(90) turtle.forward(width_float) turtle.right(90) turtle.end_fill() turtle.penup()
def okoL(a): turtle.begin_fill() wielokat(6, a *4, 1) turtle.end_fill() turtle.rt(180) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.colormode(255) turtle.fillcolor(255, 255, 255) turtle.fd(a) turtle.rt(120) turtle.begin_fill() wielokatZeSkrP(6, 2 * a, 4) turtle.end_fill() turtle.rt(60) turtle.fd(a / 2) turtle.rt(120) turtle.fillcolor(0, 0, 0) turtle.begin_fill() wielokatZeSkrP(6, a, 4) turtle.end_fill()
def plansza(bok): bokMalKw = bok/7 rDuzKol = bokMalKw rMalKol = bokMalKw/2 numPowPlus = 1 numPowKola = 1 ustNaStart(bok) turtle.pu() ##W figurach nie ma krawędzi duzyKwadrat(bok) ustDoPlusa(bokMalKw) while numPowPlus <= 4: plus(bokMalKw, rMalKol) turtle.rt(90) turtle.fd(bokMalKw) numPowPlus = numPowPlus + 1 ustDoKol(bokMalKw) turtle.fillcolor(250, 250, 0) while numPowKola <= 4: turtle.rt(90) turtle.fd(bokMalKw) turtle.lt(180) turtle.begin_fill() turtle.circle(rDuzKol) turtle.end_fill() turtle.lt(180) turtle.fd(bokMalKw * 6) numPowKola = numPowKola + 1 turtle.pd()
def bobMakesASun(turtle, size, color): turtle.fillcolor(color) turtle.begin_fill() for iter in range(2): bobMakesARay(turtle,size) turtle.right(160) turtle.end_fill()
def kwadrat(kolor): #kwadrat t.fillcolor(kolor) t.begin_fill() for i in range(4): t.fd(B) t.rt(90) t.end_fill()
def changeColor(): global currentColor turtle.pencolor(colorList[currentColor]) turtle.fillcolor(colorList[currentColor]) if(currentColor >= len(colorList)-1): currentColor = 0 else: currentColor += 1
def drawFlame(size, degrees, fillcolor="yellow"): turtle.fillcolor(fillcolor) turtle.begin_fill() turtle.setheading(270) drawSemi(size, "right", degrees, "black") turtle.setheading(turtle.heading()+degrees+degrees-180) drawSemi(size, "right", degrees, "black") turtle.end_fill()
def moon(): t.pensize(3) t.pencolor("yellow") t.fillcolor("yellow") t.begin_fill() t.circle(88,-360) t.end_fill() return
def window(): t.pensize(3) t.pencolor("black") t.fillcolor("white") t.begin_fill() rectangle(20,20) t.end_fill() return
def drawDome(size, degrees): turtle.setheading(90) turtle.fillcolor("red") turtle.begin_fill() drawSemi(size, "right", degrees, colour="black" ) turtle.setheading(turtle.heading()+degrees+degrees-180) drawSemi(size, "right", degrees, colour="black") turtle.end_fill()
def choix_couleur(self): #choix d'une couleur pour le triangle self.choix = random.randint(0, len(COULEURS)-1) self.couleur1 = COULEURS[self.choix] self.choix = random.randint(0, len(COULEURS)-1) self.couleur2 = COULEURS[self.choix] tt.pencolor(self.couleur1) tt.fillcolor(self.couleur2)
def star(x): t.pencolor("yellow") t.fillcolor("yellow") t.begin_fill() for i in range(5): t.forward(x) t.right(144) t.end_fill() return
def __draw__(self) : for j in(1,2,3): turtle.fillcolor("lightgreen") turtle.pencolor("black") turtle.forward(self.s * 10) turtle.left(72) turtle.forward(self.s * 10) turtle.left(72) exitonclick()
def draw_circle(turtle, color, size, x, y): turtle.penup() turtle.color(color) turtle.fillcolor(color) turtle.goto(x,y) turtle.pendown() turtle.begin_fill() turtle.circle(size) turtle.end_fill()
def circle(x,y,size,color): turtle.penup() turtle.goto(x,y) turtle.pendown() turtle.fillcolor(color) turtle.begin_fill() turtle.circle(size/2) turtle.end_fill() turtle.penup()
def draw_bauble(): colours = ["red","yellow","orange","blue","purple","aquamarine","gold","maroon","plum","pink",] turtle.fillcolor(random.choice(colours)) turtle.begin_fill() for i in range(60): turtle.forward(1) turtle.right(6) turtle.end_fill() return
def set_color(clr): """ A function that sets the pen and fill color to :param clr: :param clr: :return: None """ turtle.pencolor(clr) turtle.fillcolor(clr) return None
def draw_pot(): turtle.fillcolor("brown") turtle.begin_fill() for i in range(2): turtle.forward(30) turtle.right(90) turtle.forward(40) turtle.right(90) turtle.end_fill()
def draw_ear(turtle): turtle.fillcolor("white") turtle.begin_fill() turtle.circle(10) turtle.end_fill()
def circle(): t.begin_fill() t.fillcolor("white") t.circle(7) t.end_fill()
def Doraemon(): head() scarf() face() nose() mouth() beard() my_goto(0, 0) turtle.seth(0) turtle.penup() turtle.circle(150, 50) turtle.pendown() turtle.seth(30) turtle.fd(40) turtle.seth(70) turtle.circle(-30, 270) turtle.fillcolor('#00a0de') turtle.begin_fill() turtle.seth(230) turtle.fd(80) turtle.seth(90) turtle.circle(1000, 1) turtle.seth(-89) turtle.circle(-1000, 10) turtle.seth(180) turtle.fd(70) turtle.seth(90) turtle.circle(30, 180) turtle.seth(180) turtle.fd(70) turtle.seth(100) turtle.circle(-1000, 9) turtle.seth(-86) turtle.circle(1000, 2) turtle.seth(230) turtle.fd(40) turtle.circle(-30, 230) turtle.seth(45) turtle.fd(81) turtle.seth(0) turtle.fd(203) turtle.circle(5, 90) turtle.fd(10) turtle.circle(5, 90) turtle.fd(7) turtle.seth(40) turtle.circle(150, 10) turtle.seth(30) turtle.fd(40) turtle.end_fill() # 左手 turtle.seth(70) turtle.fillcolor('#ffffff') turtle.begin_fill() turtle.circle(-30) turtle.end_fill() # 脚 my_goto(103.74, -182.59) turtle.seth(0) turtle.fillcolor('#ffffff') turtle.begin_fill() turtle.fd(15) turtle.circle(-15, 180) turtle.fd(90) turtle.circle(-15, 180) turtle.fd(10) turtle.end_fill() my_goto(-96.26, -182.59) turtle.seth(180) turtle.fillcolor('#ffffff') turtle.begin_fill() turtle.fd(15) turtle.circle(15, 180) turtle.fd(90) turtle.circle(15, 180) turtle.fd(10) turtle.end_fill() # 右手 my_goto(-133.97, -91.81) turtle.seth(50) turtle.fillcolor('#ffffff') turtle.begin_fill() turtle.circle(30) turtle.end_fill() # 口袋 my_goto(-103.42, 15.09) turtle.seth(0) turtle.fd(38) turtle.seth(230) turtle.begin_fill() turtle.circle(90, 260) turtle.end_fill() my_goto(5, -40) turtle.seth(0) turtle.fd(70) turtle.seth(-90) turtle.circle(-70, 180) turtle.seth(0) turtle.fd(70) # 铃铛 my_goto(-103.42, 15.09) turtle.fd(90) turtle.seth(70) turtle.fillcolor('#fdd200') turtle.begin_fill() turtle.circle(-20) turtle.end_fill() turtle.seth(170) turtle.fillcolor('#ffd200') turtle.begin_fill() turtle.circle(-2, 180) turtle.seth(10) turtle.circle(-100, 22) turtle.circle(-2, 180) turtle.seth(180 - 10) turtle.circle(100, 22) turtle.end_fill() turtle.goto(-13.42, 15.09) turtle.seth(90) turtle.fd(16) turtle.dot(10) my_goto(0, -150) black_eyes()
#RoseDraw.py import turtle as t # 定义一个曲线绘制函数 def DegreeCurve(n, r, d=1): for i in range(n): t.left(d) t.circle(r, abs(d)) # 初始位置设定 s = 0.2 # size t.setup(450 * 5 * s, 750 * 5 * s) t.pencolor("black") t.fillcolor("red") t.speed(100) t.penup() t.goto(0, 900 * s) t.pendown() # 绘制花朵形状 t.begin_fill() t.circle(200 * s, 30) DegreeCurve(60, 50 * s) t.circle(200 * s, 30) DegreeCurve(4, 100 * s) t.circle(200 * s, 50) DegreeCurve(50, 50 * s) t.circle(350 * s, 65) DegreeCurve(40, 70 * s) t.circle(150 * s, 50)
>>> turtle.reset() >>> turtle.speed(0) >>> for i in range(50): turtle.circle(5*i) turtle.left(10) >>> turtle.reset() >>> turtle.color('red') >>> turtle.speed(0) >>> for i in range(50): turtle.circle(5*i) turtle.left(10) >>> turtle.fillcolor('green') >>> turtle.reset() >>> turtle.color('red') >>> turtle.fillcolor('green') >>> turtle.speed(0) >>> for i in range(50): turtle.circle(5*i) turtle.left(10) >>> turtle.filling('yellow') Traceback (most recent call last): File "<pyshell#87>", line 1, in <module> turtle.filling('yellow') TypeError: filling() takes 0 positional arguments but 1 was given >>> turtle.filling()
import turtle turtle.penup() turtle.speed(0) turtle.setpos(0, 0) turtle.pendown() turtle.color("white", "black") turtle.colormode(1.0) SQUARES = 60 SIDE = 150 shade = 0.0 for count in range(SQUARES): turtle.fillcolor(shade, shade, shade) turtle.begin_fill() turtle.left(360 // SQUARES) turtle.forward(SIDE) turtle.left(90) turtle.forward(SIDE) turtle.left(90) turtle.forward(SIDE) turtle.left(90) turtle.forward(SIDE) turtle.left(90) turtle.end_fill() shade += 1.0 / float(SQUARES) turtle.done()
turtle.down() #turtle.speed(1) print turtle.pensize() turtle.pensize(10) turtle.fd(100) turtle.width(5) turtle.pen(pencolor='red') turtle.bk(200) print sorted(turtle.pen().items()) print turtle.isdown() turtle.up() print turtle.isdown() turtle.pencolor('yellow') print turtle.colormode() turtle.width(1) turtle.fillcolor('blue') turtle.color('red', 'green') turtle.reset() turtle.goto(100, 100) turtle.clear() turtle.write('Home = ', True, align='center') x = turtle.xcor() y = turtle.ycor() turtle.write((x, y), True) turtle.exitonclick()
turtle.left(90) #逆时针转动画笔90度 turtle.fd(200) turtle.pendown() #放下画笔,移动画笔即开始绘制 turtle.right(90) #设置画笔的大小 turtle.pensize(2) # 花蕊 turtle.fillcolor("red") #填充颜色 turtle.begin_fill() #开始填充 turtle.circle(10,180) turtle.circle(25,110) turtle.left(50) turtle.circle(60,45) turtle.circle(20,170) turtle.right(24)
turtle.goto(bay + 1, -ed_time) turtle.goto(bay + 1, -bg_time) turtle.goto(bay, -bg_time) turtle.end_fill() turtle.penup() turtle.goto(bay + 0.25, -(bg_time + ed_time) / 2 - 0.25) turtle.pendown() turtle.write(teu) PaintAxis(bays, math.ceil(max_time)) for i in range(bays): sz = len(bay_plan[i]) for j in range(sz): crane, teu, bg_time, ed_time = bay_plan[i][j] Fill(crane, i, teu, bg_time, ed_time) turtle.fillcolor('white') turtle.penup() turtle.goto(0, -max_time) turtle.pendown() turtle.goto(bays, -max_time) turtle.goto(bays * (5.0 / 6.0), -max_time) turtle.write('max time : ' + str(max_time) + 'h') turtle.penup() turtle.goto(bays, -max_time) turtle.pendown() turtle.done()
import turtle as tu tu.penup() tu.goto(-200, 100) tu.pendown() i = 0 a = 50 while i < 11: if i % 4 == 0: tu.fillcolor("yellow") if i % 4 == 1: tu.fillcolor("red") if i % 4 == 2: tu.fillcolor('green') if i % 4 == 3: tu.fillcolor('darkorange1') tu.begin_fill() for ii in range(4): #画正方形 tu.forward(a) tu.right(90) tu.forward(a) tu.end_fill() i = i + 1 tu.done()
import turtle turtle.title('正方体') n = 100 # 边长 # 正面 turtle.begin_fill() turtle.fillcolor('#069') for x in range(4): turtle.forward(n) turtle.right(90) turtle.end_fill() # 上面 turtle.begin_fill() turtle.fillcolor('#ccc') turtle.left(45) turtle.forward(n * 0.6) turtle.right(45) turtle.forward(n) turtle.right(135) turtle.forward(n * 0.6) turtle.end_fill() # 右侧 turtle.up() turtle.goto(n, -n) turtle.down() turtle.left(180) turtle.forward(n * 0.6) turtle.left(45) turtle.forward(n) turtle.hideturtle()
import turtle as t import math as m t.setup() t.fillcolor("red") t.seth(130) t.begin_fill() t.circle(100, 200) a = 100 * m.cos(m.radians(40)) + 100 * m.sin(m.radians(30)) aa = a / m.cos(m.radians(30)) t.fd(aa) t.up() t.goto(0, 0) t.down() t.seth(50) t.circle(-100, 200) t.fd(aa) t.end_fill() t.up() t.goto(300, 300) t.done()
for i in range(steps): nextPoint = [ a * math.sin((i + 1) * minAngle), -b * math.cos((i + 1) * minAngle) ] nextPoint = [ nextPoint[0] * math.cos(rotateAngle) - nextPoint[1] * math.sin(rotateAngle), nextPoint[0] * math.sin(rotateAngle) + nextPoint[1] * math.cos(rotateAngle) ] turtle.setpos(nextPoint) turtle.hideturtle() turtle.begin_fill() turtle.fillcolor('dark sea green') eclipseR(200, 150, 360, 50, 30) turtle.end_fill() turtle.begin_fill() turtle.fillcolor('bisque') eclipseR(200, 150, 360, 50, 60) turtle.end_fill() turtle.begin_fill() turtle.fillcolor('lavender') eclipseR(200, 150, 360, 50, 90) turtle.end_fill() turtle.begin_fill() turtle.fillcolor('gold') eclipseR(200, 150, 360, 50, 120) turtle.end_fill() turtle.begin_fill()
import turtle angle = 20 crawl = 150 turtle.left(angle) turtle.fillcolor("black") turtle.forward(crawl) turtle.left(90) turtle.forward(crawl) turtle.left(90) turtle.forward(crawl) turtle.left(90) turtle.forward(crawl) turtle.left(90) turtle.left(angle) turtle.fillcolor("red") turtle.forward(crawl) turtle.left(90) turtle.forward(crawl) turtle.left(90) turtle.forward(crawl) turtle.left(90) turtle.forward(crawl) turtle.left(90) turtle.left(angle) turtle.fillcolor("green") turtle.forward(crawl)
#import turtle as t import turtle as t t.screensize(400, 400) # 正方形 t.pensize(5) t.penup() t.goto(-350, 250) t.pendown() t.pencolor('green') t.begin_fill() t.fillcolor('green') for i in range(4): t.forward(80) t.left(90) t.end_fill() t.done()
turtle.rt(90) turtle.fd(comp) def triangulo(x, y, lado, orient2): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.setheading(orient2) for a in range(3): turtle.fd(lado) turtle.lt(120) #House Body turtle.fillcolor('red') turtle.begin_fill() retangulo(0, 0, 100, 100, 0) turtle.end_fill() #House Chimney turtle.fillcolor('black') turtle.begin_fill() retangulo(-15, 80, 80, 20, 0) turtle.end_fill() #House Roof turtle.fillcolor('green') turtle.begin_fill() triangulo(-100, 0, 100, 0) turtle.end_fill()
def nose(): my_goto(-10, 158) turtle.fillcolor('#e70010') turtle.begin_fill() turtle.circle(20) turtle.end_fill()
import turtle as t t.shape("turtle") t.fillcolor("orange") t.begin_fill() t.goto(0, 0) t.goto(300, 0) # 선분1 그리기 t.goto(300, 300) # 선분2 그리기 t.goto(0, 300) # 선분3 그리기 t.goto(0, 0) # 선분4 그리기 t.end_fill() input()
right_limit = (turtle.window_width() / 2) - 100 upper_limit = (turtle.window_height() / 2) - 100 lower_limit = (-turtle.window_height() / 2) + 100 (x, y) = turtle.pos() inside = left_limit < x < right_limit and lower_limit < y < upper_limit return inside def move_turtle(line_length): pen_colors = ["red", "orange", "yellow", "green", "blue", "purple"] turtle.pencolor(random.choice(pen_colors)) if inside_window(): angle = random.randint(0, 180) turtle.right(angle) turtle.forward(line_length) else: turtle.backward(line_length) line_length = get_line_length() line_width = get_line_width() turtle.shape("turtle") turtle.fillcolor("green") turtle.bgcolor("black") turtle.speed("fastest") turtle.pensize(line_width) while True: move_turtle(line_length)
#!/usr/bin/python3 import turtle turtle.pensize(5) turtle.pencolor("yellow") turtle.fillcolor("red") turtle.begin_fill() for _ in range(5): turtle.forward(200) turtle.right(144) turtle.end_fill() turtle.penup() turtle.goto(-150,-120) turtle.color("violet") turtle.write("Done", font=('Arial', 40, 'normal')) turtle.done()
def draw_circle(color, r): turtle.fillcolor(color) turtle.begin_fill() turtle.circle(r) turtle.end_fill()
def height_square(): global size global color turtle.begin_fill() turtle.fillcolor(color) turtle.penup() turtle.right(90 turtle.forward(1.25 * size) turtle.left(90) turtle.pendown() turtle.forward(5 * size) turtle.right(90) turtle.forward(2.5 * size) turtle.right(90) turtle.forward(5 * size) turtle.right(90) turtle.forward(2.5) turtle.right(90) turtle.end_fill() def star_4(): global size global color turtle.penup() turtle.right(90) turtle.forward(2) turtle.left(60) tirtle.pendown() turtle.begin_fill() turtle.fillcolor(color) turtle.forward(2.25 * size) turtle.right(30) turtle.forward(2.25 * size) turtle.left(120) turtle.forward(2.25 * size) turtle.right(30) turtle.forward(2.25 * size) turtle.left(120) turtle.forward(2.25 * size) turtle.right(30) turtle.forward(2.25 * size) turtle.left(120) turtle.forward(2.25 * size) turtle.right(30) turtle.forward(2.25 * size) turtle.left(120) turtle.end_fill() def star_5(): global size global color turtle.penup() turtle.tight(9) turtle.forward(2) turtle.left(60) turtle.pendown() turtle.begin_fill() turtle.colorfill(color) turtle.forward(2 * size) turtle.right(120) turtle.forward(2 * size) turtle.left(120) turtle.forward(2) turtle.right(30) turtle.forward(2) turtle.left(120) turtle.forward(2 * size) turtle.right(30) turtle.forward(2 * size) turtle.left(120) turtle.forward(2 * size) turtle.right(30) turtle.forward(2 * size) turtle.left(120) turtle.forward(2 * size) turtle.right(30) turtle.left(120) turtle.end_fill() def change_shape(): global shape shape = shape_list[cs] cs = cs + 1 if cs >= len(shape_list) cs = 0 def make_shape(): global shape if shape == "circle" turtle.circle() elif shape == "square" turtler.square() elif shape == "triangle" turtle.triangle elif shape == "square_width" turtle.square_width() elif shape== "square_height" turtle.square_height() elif shape=="star_4" turtle.star_4() elif shape=="star_5" turtle.star_5() elif shape == "nothing" else print "error" turtle.getscreen().onkeypress(hide/see_turtle(),"v") turtle.getscreen().onkeypress(size_big(),"add") turtle.getscreen().onkeypress(size_small(),"minus") turtle.getscreen().onkeypress(change_color,"c") turtle.getscreen().onkeypress(change_shape,"s") turtle.onscreenclick(make_shape(),btn = 1,add = True) turtle.ondrag(make_shape(),btn = 1,add = True) turtle.getscreen().listen() turtle.mainloop()
#program, williamPrudencio_lab2-15.py, 01/26/19 ''' This program will use Turtle Graphics to draw the first shape shown on page 107 of the "Starting Out With Python" book. ''' import turtle #Change the fill color to orange------------ turtle.fillcolor("orange") #Begin filling the shape with color---------- turtle.begin_fill() #Move turtle using x & y coordinates to make the design turtle.goto(200, 200) turtle.goto(400, 0) turtle.goto(200, -200) turtle.goto(-200, 200) turtle.goto(-400, 0) turtle.goto(-200, -200) turtle.goto(0, 0) #Hide turtle turtle.hideturtle() #Stop filling the shape with color---------- turtle.end_fill() #Close turtle---------------------------- turtle.done()
def circle(): global color turtle.begin_fill() turtle.fillcolor(color) turtle.circle(5) turtle.end_fill()
def draw_face(turtle): turtle.fillcolor('white') turtle.begin_fill() turtle.circle(20) turtle.end_fill()
def fill_circle(color, r1): turtle.color(color, color) turtle.fillcolor() turtle.begin_fill() draw_circle(r1) turtle.end_fill()
#Task 1: My first square import turtle turtle.fillcolor("Brown") turtle.begin_fill() turtle.pencolor("Red") turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.right(90) turtle.forward(100) turtle.end_fill() #Task 2 Measurements in programing turtle.fillcolor("Blue") turtle.begin_fill() turtle.pencolor("Purple") turtle.forward(180) turtle.right(90) turtle.forward(180) turtle.right(90) turtle.forward(180) turtle.right(90) turtle.forward(180) turtle.end_fill() turtle.penup() turtle.pendown() #Task 3: Draw a triangle turtle.pensize(5)
import turtle as t t.fillcolor("blue") t.begin_fill() t.circle(150, 180) t.end_fill()
import random # Allow user to choose color of turtle color = input("What color should the turtle be?\t") # Using if-elif-else statements to make program more interactive if (color == "blue" or color == "pink"): print(f"{color} is my favorite color! Nice choice!") elif (color == "brown" or color == "yellow"): print(f"{color} is my not favorite color, but to each their own...") else: print(f'{color} has been selected') # Changing the turtle color and fill color turtle.pencolor(color) turtle.fillcolor(color) # Named constants SCREEN_WIDTH = 600 SCREEN_HEIGHT = 600 TARGET_WIDTH = 25 FORCE_FACTOR = 30 PROJECTILE_SPEED = 1 NORTH = 90 SOUTH = 270 EAST = 0 WEST = 180 # I am using range() to place target in random coordinate # on the screen TARGET_LLEFT_X = random.randint(1,SCREEN_WIDTH/2)
""" 用turtle模塊繪圖 這是一個非常有趣的模塊 它模擬一只烏龜在窗口上爬行的方式來進行繪圖 Version: 0.1 Author: 駱昊 Date: 2018-03-14 """ import turtle turtle.pensize(3) turtle.penup() turtle.goto(-180, 150) turtle.pencolor('red') turtle.fillcolor('yellow') turtle.pendown() turtle.begin_fill() for _ in range(36): turtle.forward(200) turtle.right(170) turtle.end_fill() turtle.mainloop()