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 init_turtle(): """ Стартовые настройки для рисования """ turtle.colormode(255) turtle.speed(10) turtle.pensize(3)
def main(): while True: side = input("Please enter the total length of the figure: ") try: side = int(side) except: print('Please enter a valid number.\n') continue break while True: id = input("Please enter MSU ID (including the starting letter): ") if len(id) == 9 and id[0].isalpha() and all(d.isdigit() for d in id[1:]): break else: print('Please enter a valid MSU ID.\n') continue turtle.colormode(1.0) turtle.speed(0) drawQ1(id, side/2) drawQ2(id, side/2) drawQ3(id, side/2) drawQ4(id, side/2) time.sleep(20) turtle.bye()
def __init__(self): self.figure = turtle.Turtle() self.speed = 5 self.figure.speed(self.speed) turtle.colormode(255) self.army = {} self.army['default'] = self.figure
def startTurtle(): t = Turtle() t.speed(10) t.up() t.setpos(-dim/2,-dim/2) colormode(255) return t
def main(configuration): t = Turtle() t.speed(10) t.up() t.setpos(-configuration['size']/2,-configuration['size']/2) colormode(255) sierpinski(t,configuration['level'],configuration['size'])
def kwadratZolty(a): dlBokKw = a / 5 turtle.colormode(255) turtle.fillcolor(255, 255, 0) turtle.begin_fill() kwadrOdWierz(dlBokKw) turtle.end_fill()
def main(): ''' main function''' turtle.colormode(255) global wn wn = turtle.Screen() # Get a reference to the window global text text = turtle.Turtle() # Create turtle for text draw_header(text) one = turtle.Turtle() # Create turtle for choice of 1 draw_one(one) two = turtle.Turtle() # Create turtle for choice of 2 draw_two(two) quit_box = turtle.Turtle() # use a "quitter" turtle to stop the loop. draw_quit(quit_box) wn.listen() while True: #main loop #numb=8 # we could allow the user to enter this. quit_box.onclick(handler_quit) one.onclick(handler_one) two.onclick(handler_two) #display_many(numb) wn.bye()
def elementSowy(r, bokKw, rMalegoKola): ##Rysujemy OD ŚRODKA turtle.colormode(255) turtle.fillcolor(209, 183, 255) turtle.begin_fill() turtle.circle(r) turtle.end_fill() turtle.pu() turtle.lt(90) turtle.fd(r) turtle.lt(45) turtle.fd(r) turtle.lt(45+90) turtle.pd() turtle.fillcolor(0, 0, 255) turtle.begin_fill() kwadrat(bokKw) turtle.end_fill() turtle.pu() turtle.fd((bokKw/4)*3) turtle.lt(90) turtle.fd(bokKw/4) turtle.pd() turtle.fillcolor(255, 255, 255) turtle.begin_fill() turtle.circle(rMalegoKola) turtle.end_fill() turtle.pu() turtle.fd(bokKw / 2) turtle.pd() turtle.begin_fill() turtle.circle(rMalegoKola) turtle.end_fill()
def main(i): t.speed('fastest'); t.tracer(1,0); t.colormode(255) t.lt(90) while (i >= 1): drawLineOfSqrs(i) i -= 1 raw_input()
def init_turtle(): turtle.ht() turtle.up() turtle.speed(0) turtle.setpos(-500, -300) turtle.left(60) turtle.colormode(255) turtle.pencolor((150, 150, 0)) turtle.down()
def losujKolor(): losowaLiczba = randint(1, 3) turtle.colormode(255) if losowaLiczba == 1: turtle.fillcolor(238, 255, 0) ##Zolty elif losowaLiczba == 2: turtle.fillcolor(255, 187, 0) ##Pomaranczowy else: turtle.fillcolor(255, 0, 0) ##Czerwony
def start(t,x,y): colormode(255) t.reset() t.speed(0) t.hideturtle() t.left(90) t.penup() t.setpos(x,y) t.pendown()
def wyborKoloru(): kolor = randint(1, 3) turtle.colormode(255) if kolor == 1: turtle.fillcolor(255, 0, 0) ##Zmienić kolor na czerwony elif kolor == 2: turtle.fillcolor(0, 0, 255) ##Zmienić kolor na niebieski elif kolor == 3: turtle.fillcolor(242, 255, 0) ##Zmienić kolor na żółty
def rgbSquare(): r = input("Enter a value between 0-255: ") g = input("Enter a value between 0-255: ") b = input("Enter a value between 0-255: ") turtle.colormode(255) turtle.pencolor(r, g, b) for i in range(4): turtle.forward(100) turtle.right(90)
def patternC(patPosX, patPosY, sq_size, t): ############################################################################################## #--------------------------------------- SET UP ---------------------------------------------# ############################################################################################## # Change color value format to RGB 0-255 turtle.colormode(255) # Pen draw size t.width(2) ############################################################################################## #------------------------------------- MOVE FUNCTION ----------------------------------------# ############################################################################################## # To move without drawing def move(positionX,positionY,t): t.pu() t.setpos(patPosX+positionX,patPosY+positionY) t.pd() ############################################################################################## #------------------------------------ SQUARE FUNCTION ---------------------------------------# ############################################################################################## def drawSquare(color, size,t): t.fillcolor(color) t.fill(True) for i in range(0,4): t.fd(sq_size*size) t.right(90) t.fill(False) ############################################################################################## #------------------------------------ DRAW SQUARES ------------------------------------------# ############################################################################################## move(-sq_size*.4,+sq_size*.4,t) drawSquare((236,142,150),.8,t) move(-sq_size*.3,+sq_size*.3,t) drawSquare((43,16,84),.6,t) ############################################################################################## #----------------------------------- DIAMOND FUNCTION ---------------------------------------# ############################################################################################## def drawDiamond(color, size,t): t.fillcolor(color) t.fill(True) t.circle(sq_size*size, 360, 4) t.fill(False) ############################################################################################## #------------------------------------ DRAW DIAMONDS -----------------------------------------# ############################################################################################## move(0,-sq_size*.35,t) drawDiamond((48,128,169),.35,t) move(0,-sq_size*.25,t) drawDiamond((116,35,61),.25,t) move(0,-sq_size*.15,t) drawDiamond((12,76,51),.15,t) move(0,-sq_size*.05,t) drawDiamond((245,164,48),.05,t)
def ready(rad): turtle.speed(0) turtle.ht() turtle.up() turtle.goto(0,-rad) turtle.down() turtle.colormode(1) turtle.bgcolor('black') turtle.pensize(1.1)
def kwZam(bok): numPow = 1 turtle.colormode(255) turtle.fillcolor(randint(0, 255), randint(0, 255), randint(0, 255)) turtle.begin_fill() while(numPow <= 4): turtle.fd(bok) turtle.lt(90) numPow = numPow + 1 korMala(bok) turtle.end_fill()
def display_nim(numb): '''called to display numb many circles of random colors''' turtle.colormode(255) position=-150 for i in range(numb): num = turtle.Turtle() num.shape("circle") num.color(random.randrange(256),random.randrange(256),random.randrange(256)) num.penup() num.setposition(position+20*i, 130) num.stamp()
def main(): turtle.colormode(1.) turtle.speed(0) for depth in range(9): if 7 > depth > 4: # for faster rendering. turtle.getscreen().tracer(0) global count count = 0 hilbert(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, depth) turtle.getscreen().tracer(1) #time.sleep(2) turtle.Screen().exitonclick()
def background_color(self, quadruple): operand1_dir = int(quadruple['operand_1']) operand2_dir = int(quadruple['operand_2']) operand3_dir = int(quadruple['result']) operand1 = self.memory_map.get_value(operand1_dir) operand2 = self.memory_map.get_value(operand2_dir) operand3 = self.memory_map.get_value(operand3_dir) self.log.write(" ****************** Quadruple " + str(self.current_quadruple) + " **********************") self.log.write(" * background_color: " + str(operand1) + ' ' + str(operand1) + ' ' + str(operand3)) turtle.colormode(255) turtle.bgcolor(operand1, operand2, operand3)
def draw_star(length,color): turtle.goto( turtle.pos() + (0,3.08)) turtle.colormode(255) turtle.fillcolor(color) turtle.begin_fill() turtle.setheading(-90) turtle.right(18) for i in range(1,6): turtle.forward(length) turtle.right(72) turtle.forward(length) turtle.left(144) turtle.end_fill()
def draw_rectangle(height,length,color): # color is input as a string, ex. "violet" "red" or their 8-bit hex, # # like "#EE82EE" "#FF0000" # turtle.colormode(255) turtle.fillcolor(color) turtle.begin_fill() turtle.setheading(-90) for i in range(1,3): turtle.forward(height) turtle.left(90) turtle.forward(length) turtle.left(90) turtle.end_fill()
def bloom(radius): turtle.colormode(255) for rad in range(40, 10, -5): for looper in range(360//rad): turtle.up() turtle.circle(radius+rad, rad) turtle.begin_fill() turtle.fillcolor((200+random.randint(0, rad), 200+random.randint(0, rad), 200+random.randint(0, rad))) turtle.down() turtle.circle(-rad) turtle.end_fill()
def trapez(kolor): turtle.colormode(255) turtle.fillcolor(kolor) turtle.begin_fill() turtle.rt(90) turtle.fd(26 * 2) turtle.lt(90+45) turtle.fd(37) turtle.lt(45) turtle.fd(26) turtle.lt(90) turtle.fd(26) turtle.lt(180) turtle.end_fill()
def lacznik(segment): numPow = 1 turtle.colormode(255) turtle.fillcolor(165, 165, 165) turtle.begin_fill() while(numPow <= 4): turtle.fd(segment) turtle.rt(90) turtle.fd(segment) turtle.lt(90) turtle.fd(segment) turtle.lt(90) numPow = numPow + 1 turtle.end_fill()
def draw_flag(country_str, flag_width_float, orientation_str): """ Asks the for the name of the country, the width and the orientation and draws a the flag using turtle Recieve: The name of country, the width of the flag, and the orientation Return: Nothing Algorithm: Save the initial position Check to make sure the country is valid Check to make sure the width is valid and more than zero Check to make sure the orientation is vallid Check to see what country needs to be drawn and call the corresponding function Go back to the intial position """ turtle.colormode(255) initial_pos_list = [turtle.xcor(), turtle.ycor(), turtle.heading()] country_str = country_str.lower() orientation_str = orientation_str.lower() if is_valid_country(country_str) == False: print('***Invalid country name. Please try again.***') return if type(flag_width_float) == str or flag_width_float <= 0.00: print('***Invalid flag width. Please try again.***') return if orientation_str == 'landscape' or orientation_str == 'portrait': if orientation_str == 'portrait': turtle.right(90) else: print('***Invalid orientation. Please try again.***') return if country_str == 'denmark': draw_denmark(flag_width_float) elif country_str == 'sweden': draw_sweden(flag_width_float) elif country_str == 'faroe islands': draw_faroe_island(flag_width_float) elif country_str == 'norway': draw_norway(flag_width_float) elif country_str == 'iceland': draw_iceland(flag_width_float) elif country_str == 'finland': draw_finland(flag_width_float) go_to_pos(initial_pos_list) turtle.fillcolor('black')
def main(): t = turtle.Turtle() turtle.setup(width=1280, height=600) turtle.colormode(255) ##turtle.bgcolor(0, 0, 0) ##t.fillcolor(0, 255, 0) ##t.pencolor(0, 0, 0) t.speed(0) t.penup() t.left(90) t.backward(startSize) t.pendown() drawTree(t, startSize, startDepth) t.getscreen()._root.mainloop()
def plus(bokMalKw, rMalKol): turtle.colormode(255) turtle.fillcolor(250, 250, 0) numPow = 1 turtle.fd(bokMalKw) turtle.lt(90) while numPow <= 4: turtle.begin_fill() kwadrat(bokMalKw) turtle.end_fill() turtle.rt(90) korMalaPlus(bokMalKw) numPow = numPow + 1 koloNaSrPlusa(bokMalKw, rMalKol) ustNaStartPlus(bokMalKw)
def main(): #prompt = raw_input() t = turtle.Turtle() turtle.setup(width=1280, height=1280) t.hideturtle() turtle.colormode(255) t.speed(0) t.penup() t.left(90) t.backward(height) t.right(90) t.backward(startSize/2) t.pendown() drawOct(t, startSize, startDepth) t.getscreen()._root.mainloop()
def demo2(): """Demo of some new features.""" # 使用最慢速度 0最快,1-10逐渐加快 turtle.speed(1) # 隐藏画笔(即海龟箭头),同 turtle.hideturtle()。此时只要画笔是按下状态,虽然隐藏了但是还是能绘制图形的 #turtle.ht() # 显示画笔,同 turtle.showturtle() #turtle.st() # 设置画笔线条粗细为3,同turtle.width(3) turtle.pensize(3) # 设置海龟箭头当前方向角度(当前模式下海龟箭头当前位置指向(0,0)点的向量角度),turtle.towards(0, 0)其实是当前方向的反方向 turtle.setheading(turtle.towards(0, 0)) # 计算半径(海龟箭头当前位置到(0,0)位置距离的一半) radius = turtle.distance(0, 0) / 2.0 # 海龟箭头右转90度,即以海龟箭头当前位置到(0,0)为直径画 turtle.rt(90) # 画18次角度为10度的小段圆弧,画笔每按下画一小段就再抬起移动一小段 for _ in range(18): switchpen(turtle.getturtle()) turtle.circle(radius, 10) turtle.write("wait a moment...") # 等待2秒 time.sleep(2) # 撤销所有 while turtle.undobufferentries(): turtle.undo() # 清屏并将画笔位置和方向恢复到初始状态并保持画笔形状不变,即位置到原点(0, 0),因为模式是"standard"方向恢复向右,"standard"/"world"模式方向也恢复到默认的向右,"logo"模式方向恢复到默认的向上 turtle.reset() # 海龟箭头左转90度 turtle.lt(90) turtle.colormode(255) # 定义等边三角形默认的边长 laenge = 10 turtle.pencolor("green") # 设置画笔线条粗细为3, 同turtle.width(3) turtle.pensize(3) # 海龟箭头左转180度 turtle.lt(180) # i为-2 到15 共遍历18次,之所以i有负数,是因为内循环中turtle.fillcolor(255-15*i, 0, 15*i)中的15*i不能超过255(即colormode的值) for i in range(-2, 16): print("当前i=", i) # 后15次画的图形进行填充,每次填充色不同 if i > 0: turtle.begin_fill() turtle.fillcolor(255 - 15 * i, 0, 15 * i) # 画等边三角形 for _ in range(3): turtle.fd(laenge) turtle.lt(120) # 后15次画的图形填充完毕 if i > 0: turtle.end_fill() # 每画完一个等边三角形,等边三角形的变成增加10像素,并且角度左转15度 laenge += 10 turtle.lt(15) # 达到 慢->快->慢->快 的效果 (速度值>10 则被置为0即最快速度) turtle.speed((turtle.speed() + 1) % 12) # 海龟箭头左转120度 turtle.lt(120) # 画笔抬起 turtle.pu() # 向前移动70像素 turtle.fd(70) # 海龟箭头向右转30度 turtle.rt(30) # 画笔放下 turtle.pd() # pencolor设置成红色并且fillcolor设置成黄色 turtle.color("red", "yellow") # 速度设置成最快 turtle.speed(0) # 画图形并填充 turtle.begin_fill() for _ in range(4): # 绘制1/4圆 turtle.circle(50, 90) # 右转90度 turtle.rt(90) # 前移30像素 turtle.fd(30) # 右转90度 turtle.rt(90) # 图形填充完毕 turtle.end_fill() # 海龟箭头左转90度 turtle.lt(90) # 画笔抬起 turtle.pu() # 向前移动30像素 turtle.fd(30) # 画笔放下 turtle.pd() # 海龟箭头图标设置成海龟 turtle.shape("turtle") # 获取(默认的)第一个Turtle实例对象 tri = turtle.getturtle( ) # 下文中的 tri(默认的)第一个Turtle实例对象,可以将所有的tri替换成turtle,比如tri.lt(100) 可改成 turtle.lt(100) # 设置tri的(海龟箭头和)画笔大小的缩放模式为auto,此模式下(海龟箭头和)画笔随 pensize变化而变化. tri.resizemode("auto") # 创建一个新的Turtle实例对象并返回该对象实例 turtle1 = turtle.Turtle() # 设置turtle1的(海龟箭头和)画笔大小的缩放模式为auto,此模式下(海龟箭头和)画笔随 pensize变化而变化. turtle1.resizemode("auto") # turtle1的海龟箭头图标设置成海龟 turtle1.shape("turtle") turtle1.reset() turtle1.lt(90) # turtle1设置画笔速度为0最大速度 turtle1.speed(0) # turtle1的画笔抬起 turtle1.pu() # turtle1的画笔移动到坐标点(280, 40) turtle1.goto(280, 40) # turtle1的左转30度 turtle1.lt(30) # turtle1的画笔放下 turtle1.pd() # turtle1设置画笔速度为6 turtle1.speed(6) # turtle1的pencolor设置成蓝色并且fillcolor设置成橘黄色 turtle1.color("blue", "orange") # 设置画笔线条粗细为2, 同turtle.width(2) turtle1.pensize(2) # tri设置画笔速度为6 tri.speed(6) # tri方向指向turtle1当前位置 tri.setheading(tri.towards(turtle1)) count = 1 # 只要tri与turtle1之间距离>4像素进入循环 while tri.distance(turtle1) > 4: turtle1.fd(3.5) turtle1.lt(0.6) tri.setheading(tri.towards(turtle1)) tri.fd(4) if count % 20 == 0: # 当前位置拷贝一份turtle1实例的当前海龟箭头图标 turtle1.stamp() # 当前位置拷贝一份tri实例的当前海龟箭头图标 tri.stamp() # tri间断效果 switchpen(tri) # turtle1间断效果 #switchpen(turtle1) count += 1 tri.write("CAUGHT! ", font=("Arial", 16, "bold"), align="right") tri.pencolor("black") tri.pencolor("red") # 等待2秒 time.sleep(2) # 此处的turtle.undobufferentries()等价于turtle.getturtle().undobufferentries()或tri.undobufferentries()表示只要第一个turtle实例可以撤销,就一直撤销,因为tri的操作数量相对于turtle1要多,为了两个对象都撤销完所以用了前者 while turtle.undobufferentries(): # tri对象撤销一步 tri.undo() # turtle1对象撤销一步 turtle1.undo() # tri对象向前移动50像素 tri.fd(50) tri.write(" Click anywhere to exit!", font=("Courier", 12, "bold")) # 获取海龟屏幕TurtleScreen对象实例 screen = turtle.getscreen() # 注册点击事件,点击海龟屏幕TurtleScreen任何位置,触发close_window函数 screen.onclick(close_window)
import turtle import random turtle.colormode(255) # default black, changing to rgb tim = turtle.Turtle() screen = turtle.Screen() def getRandomColor(): r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) return (r, g, b) def drawSpirograph(size_of_gap): for _ in range(360 // size_of_gap): tim.speed("fastest") tim.color(getRandomColor()) tim.circle(100) tim.setheading( tim.heading() + size_of_gap) #Set the orientation of the turtle to to_angle. drawSpirograph(5) screen.exitonclick()
def output_vaccine_png(input_file, out_f): min_pep_length = 8 max_pep_length = 100 pep_seqs, pep_ids, junct_scores = parse_input(input_file) #Error if not a peptide sequence for every peptide ID if len(pep_ids) != len(pep_seqs): print( "Error: Not an equal number of peptide sequences and peptide IDs") sys.exit() conversion_factor = get_conversion_factor(pep_seqs) num_peptides = get_peptide_num(pep_seqs, min_pep_length, max_pep_length) #draw vaccine #800,600 turtle.setup(800, 600) t = turtle.Turtle() myWin = turtle.Screen() turtle.colormode(255) turtle.mode("logo") t.speed(0) t.hideturtle() #negative radius draws circle clockwise circle_radius = -200 circle_pos = (-200, 0) header_pos = (0, 0) wht_space_angle = 15 pen_thick = 5 pen_thin = 2 pep_id_space = 45 + num_peptides junct_seq_space = 25 draw_header(t, header_pos) t.pu() t.setpos(circle_pos) t.pd() t.pensize(pen_thick) angle_parsed = 0 #add white space in circle before genes draw_wht_space(t, circle_radius, wht_space_angle) angle_parsed += wht_space_angle draw_junction(t, pen_thin) #draw main part of circle junctions_parsed = 0 peptides_parsed = 0 for pep in pep_seqs: junction_parsed, angle_parsed = draw_peptide( t, pep, pep_ids, peptides_parsed, pen_thick, angle_parsed, conversion_factor, min_pep_length, max_pep_length, junctions_parsed, junct_scores, circle_radius, pep_id_space, junct_seq_space, pen_thin) junctions_parsed += junction_parsed peptides_parsed += 1 #add white space in circle after genes draw_junction(t, pen_thin) draw_wht_space(t, circle_radius, wht_space_angle) output_screen(t, out_f)
#Name: Dante Rivera #Date: August 27th, 2018 #This program draws a teardrop filled with shades of blue import turtle #Import the turtle drawing package turtle.colormode(255) #Allows colors to be given as 0...255 tess = turtle.Turtle() #Create a turtle tess.shape("turtle") #Make it turtle shaped tess.backward(100) #Move her backwards, to give more space to draw #For 0,10,20,...,250 for i in range(0, 255, 10): tess.forward(10) #Move forward tess.pensize(i) #Set the drawing size to be i (larger each time) tess.color(0, 0, i) #Set the red channel to be i (brighter each time)
# This does a star with Juan & I. import turtle turtle.write("hello world", "center") #turtle.shapetransform(25, 10, 15, 1) turtle.color("red", "green") turtle.colormode("blue") turtle.speed(20) for i in range(5): turtle.forward(200) turtle.right(144) turtle.clear() for i in range(5): turtle.fd(50) turtle.rt(144) for i in range(5): turtle.fd(10) turtle.rt(144) turtle.done()
def drawgraph(): global result t.clearscreen() t.ht() t.delay(0) t.speed(0) t.penup() t.colormode(255) k = 1 + max(result) // 50 t.seth(0) for i in range(5): t.goto(-243, 40 * i - 280) t.pendown() t.forward(500) t.penup() t.seth(90) for i in range(11): t.goto(-243 + 50 * i, -280) t.pendown() t.forward(160) t.penup() for i in range(1, 10): t.goto(-220 + 50 * i, -150) t.write(str(i), move=False, align="left", font=("맑은 고딕", 12, "normal")) t.color(255, 0, 0) t.goto(-233, -190) t.write('야생', move=False, align="left", font=("맑은 고딕", 12, "normal")) t.color(0, 0, 255) t.goto(-233, -230) t.write('내성', move=False, align="left", font=("맑은 고딕", 12, "normal")) t.color(0, 0, 0) t.goto(-233, -270) t.write('전체', move=False, align="left", font=("맑은 고딕", 12, "normal")) for i in range(9): t.goto(-178 + 50 * i, -190) t.write(str(result[2 * i]), move=False, align="left", font=("맑은 고딕", 10, "normal")) t.goto(-178 + 50 * i, -230) t.write(str(result[2 * i + 1]), move=False, align="left", font=("맑은 고딕", 10, "normal")) t.goto(-178 + 50 * i, -270) t.write(str(result[2 * i] + result[2 * i + 1]), move=False, align="left", font=("맑은 고딕", 10, "normal")) ####### 그래프 틀 for i in range(1): t.penup() t.goto(-150, -50) t.seth(90) t.pendown() t.forward(300) t.right(135) t.forward(10) t.penup() t.goto(-150, 250) t.pendown() t.right(90) t.forward(10) t.penup() t.goto(-150, -50) t.seth(0) t.pendown() t.forward(300) t.right(135) t.forward(10) t.penup() t.goto(150, -50) t.pendown() t.right(90) t.forward(10) t.penup() t.goto(-170, 250) t.write('개체 수', move=False, align="left", font=("맑은 고딕", 10, "normal")) t.goto(160, -58) t.write('세대', move=False, align="left", font=("맑은 고딕", 10, "normal")) t.seth(90) for i in range(1, 10): t.goto(30 * i - 152, -78) t.write(str(i), move=False, align="left", font=("맑은 고딕", 10, "normal")) t.goto(30 * i - 150, -58) t.pendown() t.forward(12) t.penup() t.seth(0) for i in range(1, 10): t.goto(-192, 30 * i - 60) t.write(str(5 * k * i), move=False, align="left", font=("맑은 고딕", 10, "normal")) t.goto(-158, 30 * i - 50) t.pendown() t.forward(16) t.penup() ######## 그래프 내용 t.colormode(255) t.color(255, 0, 0) t.penup() for i in range(9): t.goto(-150 + 30 * (i + 1), (-50 + int(270 * (result[2 * i] / (9 * 5 * k))))) t.pendown() t.color(0, 0, 255) t.penup() for i in range(9): t.goto(-150 + 30 * (i + 1), (-50 + int(270 * (result[2 * i + 1] / (9 * 5 * k))))) t.pendown() t.color(0, 0, 0) t.penup() t.ht() t.speed(0) t.pensize(2) for i in range(9): t.goto(-150 + 30 * (i + 1), (-50 + int(270 * (result[2 * i] + result[2 * i + 1]) / (9 * 5 * k)))) t.pendown() t.penup() t.pensize(1) t.color(0, 0, 0) t.goto(-143, -340) t.write('결과를 기록하신 후 이 창을 닫아 주세요.', move=False, align="left", font=("맑은 고딕", 12, "normal"))
def drawDisk(nDisk, gameboard, n, R, G, B): # draws the disk you pass as parameter t = turtle.Turtle() t.hideturtle() turtle.colormode(255) t.fillcolor(R, G, B) t.speed(0) boardSize = 30 + 80 + (4 * (40 + (30 * (n - 1)))) t1 = (boardSize / 4) t2 = (boardSize / 2) t3 = ((boardSize / 4) * 3) diskSize = 40 + (30 * (nDisk - 1)) originX = (-250) - (40 + (30 * n)) originY = (-100) - (20 * n) tHeight = (20 * n) + 20 dPos = diskPosition(gameboard, nDisk) #Position of disk by order of lists g = diskPosInList(gameboard, nDisk) #Position of disk within its list # get index of elem in the sublist and index of arrival if dPos == 0: # if destination tower = 1 and is empty #t.hideturtle() t.penup() t.goto(originX + t1, originY + 20 + (g * 20)) #goto tower 1 t.pendown() t.fillcolor(R, G, B) t.begin_fill() t.forward(diskSize / 2) t.left(90) t.forward(20) t.left(90) t.forward(diskSize) t.left(90) t.forward(20) t.left(90) t.left(diskSize / 2) t.end_fill() elif dPos == 1: # if destination tower = 2 and is empty #t.hideturtle() t.penup() t.goto(originX + t2, originY + 20 + (g * 20)) #goto tower 1 t.pendown() t.fillcolor(R, G, B) t.begin_fill() t.forward(diskSize / 2) t.left(90) t.forward(20) t.left(90) t.forward(diskSize) t.left(90) t.forward(20) t.left(90) t.left(diskSize / 2) t.end_fill() elif dPos == 2: # if destination tower = 3 and is empty #t.hideturtle() t.penup() t.goto(originX + t3, originY + 20 + (g * 20)) #goto tower 1 t.pendown() t.fillcolor(R, G, B) t.begin_fill() t.forward(diskSize / 2) t.left(90) t.forward(20) t.left(90) t.forward(diskSize) t.left(90) t.forward(20) t.left(90) t.left(diskSize / 2) t.end_fill()
def eraseBoard(n): boardSize = 30 + 80 + ( 4 * (40 + (30 * (n - 1))) ) # 10px towers, gap of 20px between towers, biggestDisk = 40+(30*n-1) originX = (-250) - (40 + (30 * n)) originY = (-100) - (20 * n) tHeight = (20 * n) + 20 t = turtle.Turtle() t.hideturtle() t.penup() t.goto(originX, originY) t.pendown() turtle.colormode(255) t.pencolor(105, 105, 105) t.fillcolor(105, 105, 105) t.begin_fill() i = 0 while i < 2: t.forward(boardSize) t.left(90) t.forward(20) t.left(90) i += 1 t.end_fill() t1 = (boardSize / 4) t2 = (boardSize / 2) t3 = ((boardSize / 4) * 3) t.penup() t.goto(originX + t1, originY + 20) #goto tower 1 t.pendown() t.fillcolor(105, 105, 105) t.begin_fill() t.forward(5) #tower draw t.left(90) t.forward(tHeight) t.left(90) t.forward(10) t.left(90) t.forward(tHeight) t.left(90) t.end_fill() t.penup() t.goto(originX + t2, originY + 20) #goto tower 2 t.pendown() t.fillcolor(105, 105, 105) t.begin_fill() t.forward(5) #tower draw t.left(90) t.forward(tHeight) t.left(90) t.forward(10) t.left(90) t.forward(tHeight) t.left(90) t.end_fill() t.penup() t.goto(originX + t3, originY + 20) #goto tower 3 t.pendown() t.fillcolor(105, 105, 105) t.begin_fill() t.forward(5) #tower draw t.left(90) t.forward(tHeight) t.left(90) t.forward(10) t.left(90) t.forward(tHeight) t.left(90) t.end_fill()
return stillin #set some colours for turtle's trail red = 0 green = 20 blue = 40 while isin: #turtle turns left and right randomly dice = randint(1, 2) if dice == 1: t.left(90) elif dice == 2: t.right(90) turtle.colormode(cmode=255) t.pencolor(red, green, blue) #changing colors if red > 254: red = 0 if green > 254: green = 0 if blue > 254: blue = 0 red += 1 green += 1 blue += 1 t.forward(5) turtle.exitonclick()
"""import colorgram rgb_colors=[] colors = colorgram.extract('hrist.jpg', 30) for color in colors: r=color.rgb.r g = color.rgb.g b = color.rgb.b new_color=(r,g,b) rgb_colors.append(new_color) print(rgb_colors)""" import turtle as turtle_module import random from turtle import Screen turtle_module.colormode(255) Screen().bgcolor("black") tim = turtle_module.Turtle() tim.speed("fastest") tim.penup() tim.hideturtle() color_list = [(202, 164, 109), (238, 240, 245), (150, 75, 49), (223, 201, 135), (52, 93, 124), (172, 154, 40), (140, 30, 19), (133, 163, 185), (198, 91, 71), (46, 122, 86), (72, 43, 35), (145, 178, 148), (13, 99, 71), (233, 175, 164), (161, 142, 158), (105, 74, 77), (55, 46, 50), (183, 205, 171), (36, 60, 74), (18, 86, 90), (81, 148, 129), (148, 17, 20), (14, 70, 64), (30, 68, 100), (107, 127, 153), (174, 94, 97), (176, 192, 209)] tim.setheading(225) tim.forward(300) tim.setheading(0) number_of_dots = 100
def SetColor(cor = ("#000000"),espessura = 0): turtle.resetscreen() turtle.colormode(255) turtle.color(cor) turtle.pensize(espessura)
# 08.02.2021, Frollo # Level: Intermediate # Project: Create a Damien Hirst painting using module turtle import turtle import random turtle.colormode(255) # change the module to use the rgb color code tim = turtle.Turtle() tim.speed("fastest") tim.penup() # remove the lines connecting the dots tim.hideturtle() # remove the turtle ## extract the colors of the painting "painting.jpg" # import colorgram as cg # rgb_colors = [] # list of tuples # colors = cg.extract("painting.jpg", 30) # for color in colors: # r = color.rgb.r # g = color.rgb.g # b = color.rgb.b # new_color = (r, g, b) # rgb_colors.append(new_color) # # print(rgb_colors) # copy the output rgb_colors and remove first # two colors as they are the background of the painting color_list = [(238, 246, 244), (249, 243, 247), (1, 12, 31), (53, 25, 17), (218, 127, 106), (10, 104, 159), (242, 213, 68), (149, 83, 39), (215, 87, 63), (155, 6, 24), (165, 162, 31), (157, 62, 102),
def drawboard(): """ Fonction à utiliser une seule fois pour dessiner l'ensemble de la table au début de de la simulation. """ turtle.colormode(0xFF) # Set les couleurs en version RGB 255 # Règle la vitesse et la taille de la tortue de dessin # Par définition il exite un objet nommé "turtle" qui nous sert uniquement # au dessin sur la table turtle.speed(100) turtle.shapesize(0.1, 0.1, 0.1) turtle.penup() # coordonnées turtle centrée = CTC # coordonnées mm centrée = CMC # coordonnées mm offset = CMO # dessiner le cadre dessin_Zone_Couleur(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(2000, "y"), 3000 * ECHELLE, 2000 * ECHELLE, AQA) # dessiner la zone de jeu1 dessin_Zone(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(1070, "y"), 400 * ECHELLE, 540 * ECHELLE, BLE) # dessiner la zone de jeu2 dessin_Zone(convert_CMOtoCTC(2600, "x"), convert_CMOtoCTC(1070, "y"), 400 * ECHELLE, 540 * ECHELLE, YL) # dessiner la zone de jeu jaune bas dessin_Zone(convert_CMOtoCTC(1150, "x"), convert_CMOtoCTC(2000, "y"), 100 * ECHELLE, 300 * ECHELLE, YL) # dessiner la zone de jeu bleu bas dessin_Zone(convert_CMOtoCTC(1750, "x"), convert_CMOtoCTC(2000, "y"), 100 * ECHELLE, 300 * ECHELLE, BLE) # dessiner les rochers dessin_Zone(convert_CMOtoCTC(889, "x"), convert_CMOtoCTC(2000, "y"), 22 * ECHELLE, 150 * ECHELLE, BLC) dessin_Zone(convert_CMOtoCTC(2089, "x"), convert_CMOtoCTC(2000, "y"), 22 * ECHELLE, 150 * ECHELLE, BLC) dessin_Zone(convert_CMOtoCTC(1489, "x"), convert_CMOtoCTC(2000, "y"), 22 * ECHELLE, 300 * ECHELLE, BLC) # dessiner les zones de couleurs des bases dessin_Zone_Couleur(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(530, "y"), 400 * ECHELLE, 30 * ECHELLE, GR) dessin_Zone_Couleur(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(1100, "y"), 400 * ECHELLE, 30 * ECHELLE, RD) dessin_Zone_Couleur(convert_CMOtoCTC(2600, "x"), convert_CMOtoCTC(530, "y"), 400 * ECHELLE, 30 * ECHELLE, RD) dessin_Zone_Couleur(convert_CMOtoCTC(2600, "x"), convert_CMOtoCTC(1100, "y"), 400 * ECHELLE, 30 * ECHELLE, GR) # dessiner les zones de couleurs des bases rochers dessin_Zone_Couleur(convert_CMOtoCTC(1050, "x"), convert_CMOtoCTC(2000, "y"), 100 * ECHELLE, 300 * ECHELLE, GR) dessin_Zone_Couleur(convert_CMOtoCTC(1250, "x"), convert_CMOtoCTC(2000, "y"), 100 * ECHELLE, 300 * ECHELLE, RD) dessin_Zone_Couleur(convert_CMOtoCTC(1650, "x"), convert_CMOtoCTC(2000, "y"), 100 * ECHELLE, 300 * ECHELLE, GR) dessin_Zone_Couleur(convert_CMOtoCTC(1850, "x"), convert_CMOtoCTC(2000, "y"), 100 * ECHELLE, 300 * ECHELLE, RD) dessin_Zone(convert_CMOtoCTC(0, "x"), convert_CMOtoCTC(2000, "y"), 3000 * ECHELLE, 2000 * ECHELLE, BLC) dessin_Gobies_init() turtle.title("Simulation de la coupe") turtle.home() # Retourne en 0;0 CTC
def eraseDisk(nDisk, gameboard, n): R = 105 G = 105 B = 105 t = turtle.Turtle() t.hideturtle() turtle.colormode(255) t.speed(0) boardSize = 30 + 80 + (4 * (40 + (30 * (n - 1)))) t1 = (boardSize / 4) t2 = (boardSize / 2) t3 = ((boardSize / 4) * 3) diskSize = 40 + (30 * (nDisk - 1)) originX = (-250) - (40 + (30 * n)) originY = (-100) - (20 * n) tHeight = (20 * n) + 20 dPos = diskPosition(gameboard, nDisk) g = diskPosInList(gameboard, nDisk) # get index of elem in the sublist and index of arrival if dPos == 0: # if destination tower = 1 and is empty #t.hideturtle() t.penup() t.goto(originX + t1, originY + 20 + (g * 20)) #goto tower 1 t.pendown() t.pencolor(R, G, B) t.fillcolor(R, G, B) t.begin_fill() t.forward(diskSize / 2) t.left(90) t.forward(20) t.left(90) t.forward(diskSize) t.left(90) t.forward(20) t.left(90) t.left(diskSize / 2) t.end_fill() elif dPos == 1: # if destination tower = 2 and is empty #t.hideturtle() t.penup() t.goto(originX + t2, originY + 20 + (g * 20)) #goto tower 1 t.pendown() t.pencolor(R, G, B) t.fillcolor(R, G, B) t.begin_fill() t.forward(diskSize / 2) t.left(90) t.forward(20) t.left(90) t.forward(diskSize) t.left(90) t.forward(20) t.left(90) t.left(diskSize / 2) t.end_fill() elif dPos == 2: # if destination tower = 3 and is empty #t.hideturtle() t.penup() t.goto(originX + t3, originY + 20 + (g * 20)) #goto tower 1 t.pendown() t.pencolor(R, G, B) t.fillcolor(R, G, B) t.begin_fill() t.forward(diskSize / 2) t.left(90) t.forward(20) t.left(90) t.forward(diskSize) t.left(90) t.forward(20) t.left(90) t.left(diskSize / 2) t.end_fill()
def draw_plot(): turtle.reset() turtle.setup(width=500, height=300, startx=200, starty=200) turtle.colormode(255) turtle.speed('fastest') turtle.pensize(2) turtle.title(lines[0]) ninety = 0 eighty = 0 seventy = 0 sixty = 0 other = 0 for score in scores: if score >= 90: ninety += 1 elif score >= 80: eighty += 1 elif score >= 70: seventy += 1 elif score >= 60: sixty += 1 else: other += 1 scalar = 500 ninety = ninety / len(scores) * scalar eighty = eighty / len(scores) * scalar seventy = seventy / len(scores) * scalar sixty = sixty / len(scores) * scalar other = other / len(scores) * scalar def draw_bar(x, y, text, length, r, g, b, width): turtle.penup() turtle.goto(x, y) turtle.fillcolor(r, g, b) turtle.begin_fill() turtle.pendown() turtle.setheading(90) turtle.forward(length) turtle.setheading(0) turtle.forward(width) turtle.setheading(270) turtle.forward(length) turtle.setheading(180) turtle.forward(width) turtle.penup() turtle.end_fill() turtle.goto(x + 30, -90) turtle.pendown() font = ("Arial", 10, "bold") turtle.write(text, align='center', font=font) x, y = -150, -100 width = 60 draw_bar(x, y, '90%', ninety, 0, 255, 0, width) x += width draw_bar(x, y, '80%', eighty, 102, 255, 102, width) x += width draw_bar(x, y, '70%', seventy, 255, 255, 102, width) x += width draw_bar(x, y, '60%', sixty, 255, 178, 102, width) x += width draw_bar(x, y, '<60%', other, 255, 0, 0, width) turtle.hideturtle()
import colorgram from turtle import Turtle, Screen, colormode import random tim = Turtle() tim.shape("turtle") colormode(255) tim.speed("fastest") imported_colors = colorgram.extract('images/image.jpg', 20) colors_list = [] tim.hideturtle() for color in imported_colors: rgb = color.rgb color_red = rgb.r color_green = rgb.g color_blue = rgb.b color = (color_red, color_green, color_blue) colors_list.append(color) def hirst_painter(picture_size, dot_size, offset, colors): """ Function to draw a masterpiece of circles having the same diameter and offset but different colors. :param picture_size: Number of circles in the line and in column. :param dot_size: Defines size of the circle. :param offset: Distance between the circles. :param colors: Colors to be used in painting :return: None """ y = -430
# Fifty shades of grey! import turtle turtle.penup() turtle.setpos(-100, 250) turtle.pendown() turtle.pencolor('olive') turtle.write('Fifty Shades of Grey', font=("Arial", 18, "bold")) turtle.penup() turtle.setpos(0, 0) turtle.pendown() turtle.color("black", "white") turtle.colormode(1.0) SQUARES = 50 SIDE = 150 shade = 1.0 for count in range(SQUARES): turtle.fillcolor(shade, shade, shade) turtle.begin_fill() turtle.left(360 // SQUARES) for side in range(4): turtle.forward(SIDE) turtle.left(90) turtle.end_fill() shade -= turtle.colormode() / float(SQUARES)
#AnotherClass: A different class, neither subclasses nor subclassed class AnotherClass(object): func = Parent.func print(Parent.func is Parent.func) # False, new object created print(Parent.func2 is Parent.func2) # False, new object created print(Child.func is Child.func) # False, new object created print(AnotherClass.func is AnotherClass.func) # True, original object used #Section 101.2: Turtle example import turtle, time, random #tell python we need 3 different modules turtle.speed(0) #set draw speed to the fastest turtle.colormode(255) #special colormode turtle.pensize(4) #size of the lines that will be drawn def triangle(size): #This is our own function, in the parenthesis is a variable we have defined that #will be used in THIS FUNCTION ONLY. This fucntion creates a right triangle turtle.forward(size) #to begin this function we go forward, the amount to go forward by is the variable size turtle.right(90) #turn right by 90 degree turtle.forward(size) #go forward, again with variable turtle.right(135) #turn right again turtle.forward(size * 1.5) #close the triangle. thanks to the Pythagorean theorem we know that this line must be 1.5 times longer than the other two(if they are equal) while(1): #INFINITE LOOP turtle.setpos(random.randint(-200, 200), random.randint(-200, 200)) #set the draw point to a random (x,y) position turtle.pencolor(random.randint(1, 255), random.randint(1, 255), random.randint(1, 255)) #randomize the RGB color triangle(random.randint(5, 55)) #use our function, because it has only one variable we can #simply put a value in the parenthesis. The value that will be sent will be random between 5 - 55, end #the end it really just changes ow big the triangle is. turtle.pencolor(random.randint(1, 255), random.randint(1, 255), random.randint(1, 255))#randomize color again
def getColor(): t.colormode(255) return random.randint(0, 255)
import turtle from turtle import * import random turtle.colormode(225) class Square(Turtle): def __init__(self, size, shape, color): Turtle.__init__(self, shape) self.size(size) self.shape=shape self.color(color) def random_color(self): r = random.randint(0,256) g = random.randint(0,256) b = random.randint(0,256) self.color= color(r,g,b) s=Square(10,"square","black") s.random_color()
import turtle turtle.colormode(255) #brings in the colormode functions turtle.bgcolor('black') bob = turtle.Turtle() bob.pensize(10) bob.speed(11) for n in range(255): #use the loop variable for the color values c = (255, n, n) bob.color(c) bob.circle(n) bob.right(200)
import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.color((255, 155, 192), "pink") t.setup(840, 500) t.speed(10) #鼻子 t.pu() t.goto(-100, 100) t.pd() t.seth(-30) t.begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: a = a - 0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.seth(90) t.fd(25) t.seth(0)
t.right(60) # rotate right for smaller "fork" branch yt(length * 0.6) # create second smaller branch t.left(30) # rotate back to original heading t.forward(-length) # move back to original position return # leave the function, continue with calling program ## import colorsys ## GRADIENT_SPEC = [ ## (1.0, 1.0, 1.0), # white ## (1.0, 0.0, 0.0), # red ## (0.0, 1.0, 0.0), # green ## (0.0, 0.0, 1.0), # blue ## (0.0, 0.0, 0.0)] # black ## ## def gradient(d, spec=GRADIENT_SPEC): ## """ d in [0..1] """ ## N = len(spec) ## idx = int(d * (N - 1)) ## t = math.fmod(d * (N - 1), 1.0) ## col1 = colorsys.rgb_to_hsv(*spec[min(N - 1, idx)]) ## col2 = colorsys.rgb_to_hsv(*spec[min(N - 1, idx + 1)]) ## hsv = tuple(a * (1 - t) + b * t for a, b in zip(col1, col2)) ## r, g, b = colorsys.hsv_to_rgb(*hsv) ## # return '#%02X%02X%02X' % (r * 255, g * 255, b * 255) ## return r,g,b # Main t.colormode(1.0) yt(100) # create a tree, the first branch has a length of 200 pixel
rgb_colors =[] colors = colorgram.extract("dia_18/image.jpg", 30) for color in colors: r = color.rgb.r g = color.rgb.g b = color.rgb.b new_color = (r, g, b) rgb_colors.append(new_color) print(rgb_colors) """ import turtle as turtle_module import random turtle_module.colormode(255) #Especifico colores tipo RGB tim = turtle_module.Turtle() #Creo un objeto llamado tim de tipo Turtle tim.penup() #Indico que oculte la linea de desplazamiento tim.hideturtle() #Indico que oculte la tortuga color_list = [(241, 227, 205), (196, 162, 115), (213, 228, 240), (242, 220, 231), (218, 240, 229), (130, 166, 189), (66, 101, 133), (186, 145, 164), (136, 71, 96), (134, 177, 156), (143, 91, 63), (219, 204, 129), (169, 160, 53), (66, 118, 89), (125, 33, 55), (178, 95, 119), (67, 27, 48), (86, 154, 126), (194, 98, 77), (221, 173, 190), (66, 36, 22), (31, 42, 69), (162, 209, 191), (72, 153, 169), (108, 120, 165), (230, 174, 163), (45, 54, 104), (180, 185, 215), (154, 207, 217), (120, 39, 30)] tim.setheading(135) # Apunto la tortuga a 135 grados
import turtle turtle.penup(); turtle.goto(-300,0); turtle.write('Welcome to Monopoly', move=False, align="left", font=("Arial",48, "normal")); turtle.reset(); turtle.speed(10000); turtle.penup(); turtle.colormode(255); turtle.goto(-150,0); turtle.write('MONOPOLY', move=False, align="left", font=("Monotype Corsiva",48, "normal")); turtle.goto(-600,340); turtle.pendown(); #turtle.hideturtle(); turtle.shape('turtle'); for i in range(2): turtle.forward(1200); turtle.right(90); turtle.forward(680); turtle.right(90); turtle.penup(); turtle.goto(-460,230); turtle.pendown(); for i in range(2): turtle.forward(920); turtle.right(90); turtle.forward(460); turtle.right(90); turtle.left(90); for i in range (5): turtle.forward(110); turtle.right(90);
# On my honor, I have neither given nor recieved unauthorized aid # This program is drawing a turtle with turtle import turtle as t t.mode("logo") # changes the angle directions so that they are normal cardinal directions t.speed(10) # increased the drawing speed t.colormode(255) # changed the color mode to RGB values t.pensize(5) # changed the size of the pen radius = 150 tempRadius = radius # temporary radius for drawing the pattern on the turtle shell coords = [] # holds coordinates of the turtle when it reaches each 5th of the circle headings = [] # holds the directions/orientations of the turtle when it reaches each 5hth of the circle def start(): # this function is preparation for the rest of the program t.setheading(270) # sets the orientation to west t.penup() # stops drawing; "lifts the pen" t.goto((0,radius)) # goes to the given point; this is so the turtle/body of the turtle is centered t.ht() # hides the turtle icon t.pendown() # resumes drawing; "puts down the pen" def body(): # draws the body of the turtle t.fillcolor("green") # fill color is green t.begin_fill() # where it knows to start to fill the shape for x in range(5): # This if statement is drawing 5 segments of the shell. # This way, I can add the coordinates and headings of the turtle after # Each segment is done so I can easily draw the limbs and head t.circle(radius,72,2) coords.append(t.pos()) headings.append(t.heading())
import turtle as tl import random as rd main=tl.Turtle() screen=tl.Screen() screen.bgcolor("black") main.hideturtle() main.speed(0) l=["red","orange","yellow","green","cyan","purple"] main.color("cyan") for i in range(120): main.pensize(3) #main.color(l[i%6]) r=rd.randint(0,255) g=rd.randint(0,255) b=rd.randint(0,255) tl.colormode(255) main.pencolor(r,g,b) for i in range(3): main.forward(170) main.left(90) main.forward(170) main.left(93) tl.done()
import turtle bob = turtle.Turtle() bob.width(10) bob.speed(11) turtle.colormode(255) turtle.bgcolor(0, 0, 0) from Function_Universe import * from Function_Phoenix import * #------------------------------------------------------------------------------- Cosmos(bob, 45, 103) Stars(bob, 6, 70) #------------------------------------------------------------------------------- bob.penup() bob.goto(-200, 200) bob.pendown() Wirl(bob, 7, 50) bob.penup() bob.goto(-200, -200) bob.pendown() Wirl(bob, 7, 50) bob.penup() bob.goto(200, -200) bob.pendown() Wirl(bob, 7, 50)
# coding:utf-8 import turtle as t t.screensize(400, 300, "blue") t.pensize(4) # 设置画笔的大小 t.colormode(255) # 设置GBK颜色范围为0-255 t.color((255,155,192),"pink") # 设置画笔颜色和填充颜色(pink) t.setup(840,500) # 设置主窗口的大小为840*500 t.speed(10) # 设置画笔速度为10 #鼻子 t.pu() # 提笔 t.goto(-100,100) # 画笔前往坐标(-100,100) t.pd() # 下笔 t.seth(-30) # 笔的角度为-30° t.begin_fill() # 外形填充的开始标志 a=0.4 for i in range(120): if 0<=i<30 or 60<=i<90: a=a+0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: a=a-0.08 t.lt(3) t.fd(a) t.end_fill() # 依据轮廓填充 t.pu() # 提笔 t.seth(90) # 笔的角度为90度 t.fd(25) # 向前移动25 t.seth(0) # 转换画笔的角度为0 t.fd(10)
def draw(list_rectangles, list_squares): """ DRAW """ turtle.title("Holberton Grafics -- by Jonatan Mazo") turtle.colormode(255) turtle.setup(width=1280, height=720, startx=0, starty=0) turtle.bgcolor(255, 255, 255) turtle.pensize(3) list_dict = [] for figure in list_rectangles: list_dict.append(figure.to_dictionary()) count = 0 colors = ["Red", "FireBrick", "Dark Red"] turtle.color("Red") turtle.write("Rectangle task", False, "center", ("", 60, "")) turtle.penup() turtle.setposition(0, -30) turtle.pendown() turtle.write("by: jonatan Mazo", False, "center", ("", 20, "")) turtle.penup() turtle.setposition(-320, -180) turtle.pendown() turtle.pencolor("dark red") turtle.delay(100) turtle.forward(640) turtle.clear() for attr in list_dict: turtle.delay(0) turtle.penup() turtle.setposition(attr["x"], attr["y"]) turtle.pendown() turtle.pencolor(colors[count]) turtle.delay(10) print(attr) for edge in range(2): turtle.forward(attr["width"]) turtle.left(90) turtle.forward(attr["height"]) turtle.left(90) count += 1 turtle.delay(0) turtle.penup() turtle.setposition(-320, -180) turtle.pendown() turtle.pencolor("dark red") turtle.delay(100) turtle.forward(640) turtle.clear() turtle.delay(0) turtle.penup() turtle.setposition(0, 0) turtle.pendown() turtle.color("Red") turtle.write("Square task", False, "center", ("", 60, "")) turtle.penup() turtle.setposition(0, -30) turtle.pendown() turtle.write("by: jonatan Mazo", False, "center", ("", 20, "")) turtle.penup() turtle.setposition(-320, -180) turtle.pendown() turtle.pencolor("dark red") turtle.delay(100) turtle.forward(640) turtle.clear() list_dict = [] for figure in list_squares: list_dict.append(figure.to_dictionary()) count = 0 colors = ["Red", "FireBrick", "Dark Red"] for attr in list_dict: turtle.delay(0) turtle.penup() turtle.setposition(attr["x"], attr["y"]) turtle.pendown() turtle.pencolor(colors[count]) turtle.delay(10) print(attr) for edge in range(4): turtle.forward(attr["size"]) turtle.left(90) count += 1 turtle.delay(0) turtle.penup() turtle.setposition(-320, -180) turtle.pendown() turtle.pencolor("dark red") turtle.delay(100) turtle.forward(640) turtle.clear() turtle.clear() turtle.delay(0) turtle.penup() turtle.setposition(0, 0) turtle.pendown() turtle.color("Red") turtle.write("Thanks for watch", False, "center", ("", 60, "")) turtle.penup() turtle.setposition(0, -30) turtle.pendown() turtle.write("Holberton", False, "center", ("", 20, "")) turtle.penup() turtle.setposition(-320, -180) turtle.pendown() turtle.pencolor("dark red") turtle.delay(20) turtle.forward(640) turtle.clear() turtle.delay(0) turtle.penup() turtle.setposition(0, 0) turtle.pendown() turtle.clear() red = 0 for sp in range(300): if red < 252: red += 2 else: red = 253 turtle.pencolor(red, 0, 0) turtle.pensize(sp / 90) for tri in range(5): turtle.forward(4 * (sp / 2)) # Size of pligon turtle.left(45) # degrees to make a polygon turtle.left(sp / 100) turtle.penup() turtle.setposition(0, 300) turtle.pendown() turn = turtle.heading() turtle.left(360 - turn) turtle.pencolor("White") turtle.pensize(20) turtle.backward(100) turtle.forward(200) turtle.penup() turtle.setposition(0, 290) turtle.pendown() turtle.color("Black") turtle.write("Click to close", False, "center", ("", 10, "")) turtle.penup() turtle.setposition(0, 0) turtle.pendown() print("\nprocess successfully completed") print("\n----------------------------\n") print("waiting for a click to close the turtle window") turtle.exitonclick() # Use a click of mouse to exit