def main(): ap = ArgumentParser() ap.add_argument('--speed', type=int, default=10, help='Number 1-10 for drawing speed, or 0 for no added delay') ap.add_argument('program') args = ap.parse_args() for kind, number, path in parse_images(args.program): title = '%s #%d, path length %d' % (kind, number, path.shape[0]) print(title) if not path.size: continue pen_up = (path==0).all(axis=1) # convert from path (0 to 65536) to turtle coords (0 to 655.36) path = path / 100. turtle.title(title) turtle.speed(args.speed) turtle.setworldcoordinates(0, 655.36, 655.36, 0) turtle.pen(shown=False, pendown=False, pensize=10) for i,pos in enumerate(path): if pen_up[i]: turtle.penup() else: turtle.setpos(pos) turtle.pendown() turtle.dot(size=10) _input('Press enter to continue') turtle.clear() turtle.bye()
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 __drawstate(self, x, y, state): turtle.penup() turtle.home() turtle.setpos(x*10, y*10) if state == 1: turtle.pen(fillcolor="black") if state == 0: turtle.pen(fillcolor="white") turtle.pendown() self.__drawsquare()
def main(): # eixos turtle.setworldcoordinates(-pi,-2,pi,2) linha(-pi,0,pi,0) linha(0,-2,0,2) # inicializa turtle.pen(pensize=3, pencolor='red') grafico(sin, -pi,pi) turtle.pen(pencolor='blue') grafico(cos,-pi,pi) turtle.hideturtle() turtle.exitonclick()
def drawGrid(): turtle.color("black") turtle.pen(fillcolor = "black", pensize=2) turtle.penup() turtle.goto(initX1, initY1) turtle.pendown() turtle.forward(grid_len) turtle.right(90) turtle.forward(grid_len) turtle.right(90) turtle.forward(grid_len) turtle.right(90) turtle.forward(grid_len)
def set_scale(lines,grid=False): """This sets the coordinate scale so that lines will nearly fill the window that you're drawing in. It doesn't actually draw anything. If grid=True, it will then draw a grid. """ global lowerleft global upperright lowerleft = min([min(x0,y0,x1,y1) for ((x0,y0),(x1,y1)) in lines]) upperright = max([max(x0,y0,x1,y1) for ((x0,y0),(x1,y1)) in lines]) size = upperright - lowerleft margin = size*.1 turtle.setworldcoordinates(lowerleft-margin,lowerleft-margin,upperright+margin,upperright+margin) turtle.pen(speed=10,shown=False) if grid: draw_grid(lowerleft,upperright)
def drawGrid(state): turtle.pen(fillcolor = "black", pensize=2) turtle.penup() if state == 1: turtle.goto(initX1, initY1) else: turtle.goto(initX2, initY2) turtle.pendown() turtle.forward(grid_len) turtle.right(90) turtle.forward(grid_len) turtle.right(90) turtle.forward(grid_len) turtle.right(90) turtle.forward(grid_len)
def draw(age,month): #draw function, takes input and uses that to draw turtle graphics turtle.pen() turtle.forward(age) turtle.left(month) turtle.forward(age) turtle.forward(age) turtle.left(month) turtle.forward(age) time.sleep(5) return 0 return 0
def draw_lines(lines, color='black', width=3, dots=0, visible=False): """draw every line in lines""" turtle.pen(speed=10,shown=False) turtle.color(color) turtle.width(width) for line in lines: ((x0,y0),(x1,y1)) = list(line) turtle.penup() turtle.goto((x0,y0)) turtle.pendown() if dots>0: turtle.dot(dots) if visible: # turtle.pen(speed=10,shown=True) turtle.goto((x1,y1)) # turtle.pen(speed=10,shown=False) else: turtle.goto((x1,y1))
def dashforward(l): ll = l / 6.0 for i in range(6): turtle.forward(ll) if turtle.pen()["pendown"]: turtle.penup() else: turtle.pendown()
def draw_match(turtle, cell_size, offset, cell): turtle.forward((cell.x-offset[0]) * cell_size) turtle.left(90) turtle.forward((cell.y-offset[1]) * cell_size) turtle.right(90) pen = turtle.pen() turtle.color('red') turtle.up() turtle.back(10) turtle.right(90) turtle.begin_fill() turtle.circle(10) turtle.left(90) turtle.forward(5) turtle.right(90) turtle.circle(5) turtle.left(90) turtle.end_fill() turtle.pen(pen)
def view(self): import turtle coords = [ref.image_coord_mm for ref in self.reflections] x, y = zip(*coords) min_x, max_x = min(x), max(x) min_y, max_y = min(y), max(y) low = min(min_x, min_y) high = max(max_x, max_y) turtle.title("Reflections from " + self.reflections_filename) turtle.setworldcoordinates(low, low, high, high) turtle.pen(speed=0,pensize=2) turtle.hideturtle() for ref in self.reflections: (x, y) = ref.image_coord_mm turtle.penup() turtle.setx(x) turtle.sety(y) turtle.pendown() turtle.circle(1.0, steps=8) turtle.done()
def draw_position(turtle, size=10, color='red'): old_pen = turtle.pen() old_pos = turtle.pos() old_heading = turtle.heading() turtle.color(color) turtle.begin_fill() turtle.left(90) turtle.forward(size*0.5) turtle.right(120) turtle.forward(size) turtle.right(120) turtle.forward(size) turtle.right(120) turtle.forward(size*0.5) turtle.right(90) turtle.end_fill() turtle.setheading(old_heading) turtle.setpos(old_pos) turtle.pen(old_pen)
def draw_capture_circle(turtle, cell_size, offset, domino, move_num=None): x = (domino.head.x + domino.tail.x) * 0.5 - offset[0] y = (domino.head.y + domino.tail.y) * 0.5 - offset[1] pen = turtle.pen() turtle.forward(x*cell_size) turtle.left(90) turtle.forward(y*cell_size) turtle.right(90) turtle.setheading(270) turtle.forward(8) turtle.left(90) turtle.down() turtle.pencolor('red') turtle.fillcolor('red' if move_num is None else 'white') turtle.begin_fill() turtle.circle(8) turtle.end_fill() turtle.pen(pen) if move_num is not None: turtle.write(move_num, align='center')
def test_pen(self): some_english_colors = ['blue', (0.5, 0.3, 0.2), 'brown', 'orange'] some_spanish_colors = ['azul', (0.5, 0.3, 0.2), 'marron', 'naranja'] pen_options = [('shown', 'se_muestra', [True, False]), ('pendown', 'bajar_lapiz', [True, False]), ('pencolor', 'color_de_lapiz', some_english_colors, some_spanish_colors), ('fillcolor', 'color_de_relleno', some_english_colors, some_spanish_colors), ('pensize', 'tamano_lapiz', [1, 2, 3, 4, 5]), ('speed', 'velocidad', range(1, 11)), ('resizemode', 'modo_cambio_tamano', ['auto', 'user', 'noresize'], ['auto', 'usuario', 'sin_cambio_de_tamano']), ('stretchfactor', 'factor_inclinacion', [(1, 1), (1, 2), (2, 1), (2, 2)]), ('outline', 'ancho_contorno', [1, 2, 3]), ('tilt', 'rotar', [1, 2, 3])] for entry in pen_options: english_key = entry[0] spanish_key = entry[1] english_values = entry[2] if len(entry) > 3: spanish_values = entry[3] else: spanish_values = english_values for english_value, spanish_value in zip(english_values, spanish_values): self.clear() tortuga.pen(**{english_key: english_value}) tortuga.forward(3) turtle.pen(**{english_key: english_value}) turtle.forward(3) tortuga.pen(**{english_key: spanish_value}) tortuga.forward(3) turtle.pen(**{english_key: english_value}) turtle.forward(3) tortuga.pen(**{spanish_key: spanish_value}) tortuga.forward(3) turtle.pen(**{english_key: english_value}) turtle.forward(3) self.assert_same()
def drawNodes(treeMin, eventDict, depth, nodeDict): """Takes as input treeMin - a list of the starting nodes of the best reconciliations eventDict - the DTL format dictionary depth - a starting y-coordinate nodeDict - a dictionary of nodes and their coordinates. This function recursively draws the nodes of the DTL format dictionary, then connects them using the connect function aboves""" numTips = 0 for key in eventDict.keys(): if eventDict[key][0][0] == "C": numTips+=1 width = numTips * 200 DISPLACE = width/2 dip = 15 if len(eventDict)<25: radius = 30 else: radius = 13 dip = 15 width = width/2 DISPLACE = DISPLACE/2 if treeMin == []: for key in nodeDict: for item in range(len(nodeDict[key][1:])): connect(turtle.Turtle(), nodeDict[key][0], nodeDict[key][item+1], radius) for thing in eventDict[key][item][1:-1]: if thing !=(None, None): connect(turtle.Turtle(), nodeDict[key][item+1], nodeDict[thing][0], radius) return difference = ((len(eventDict))*2)/numTips numSols = len(treeMin) turtle.speed(0) turtle.pen(pencolor = "black") eventList = [] newtreeMin = [] for x in range(len(treeMin)): if not treeMin[x] in nodeDict: nodeDict[treeMin[x]] = [((x+1)*width/(numSols + 1)-DISPLACE, depth + radius)] turtle.penup() turtle.setpos((x+1)*width/(numSols+1)-DISPLACE, depth) turtle.pendown() turtle.circle(radius) turtle.left(130) turtle.penup() turtle.forward(radius) turtle.pendown() turtle.right(130) turtle.write(treeMin[x], font = ("arial", 12, "normal")) for y in eventDict[treeMin[x]]: if type(y)== list: eventList.append((y[0], treeMin[x])) if y[1] !=(None, None) and not y[1] in newtreeMin: newtreeMin.append(y[1]) if y[2] !=(None, None) and not y[2] in newtreeMin: newtreeMin.append(y[2]) numEvents = len(eventList) for event in range(len(eventList)): turtle.penup() nodeDict[eventList[event][1]].append(((event+1)*width/(numEvents+1)-DISPLACE, depth -(difference-radius))) turtle.setpos(((event+1)*width/(numEvents+1))-DISPLACE, depth - difference) turtle.pendown() turtle.circle(radius) turtle.left(95) turtle.penup() turtle.forward(radius) turtle.pendown() turtle.right(95) turtle.write(eventList[event][0], font = ("arial", 12, "normal")) turtle.ht() drawNodes(newtreeMin, eventDict, depth - 2*difference, nodeDict)
import turtle from math import pi, sin turtle.pen(speed=0) # for j in range(52): # turtle.left(5) # # for i in range(4): # nepracuje se s argumentem i, proste se probehne seznam o i polozkach # # turtle.speed(10) # turtle.pencolor("blue") # turtle.fillcolor("yellow") # turtle.forward(70) # turtle.right(90) # turtle.shape('turtle') from math import pi def obvod_obdelnika(sirka,vyska): return 2*(sirka+vyska) print(obvod_obdelnika(2,3)) def obsah_elipsy(a,b): return pi*a*b print(obsah_elipsy(2,3)) # colors = ["blue", "black", "red", "goldenrod", "green"]
def draw(self): if int(turtle.heading()) == 180: turtle.right(180) #snowperson drawing sn = SnowPerson(self.posX, self.posY) sn.draw() #SnowMan Features #Hair and hat #left x = self.posX y = self.posY turtle.pen(pencolor="brown", pensize=2) turtle.up() p = x - 20 q = y + 55 turtle.setposition(p, q) turtle.down() q = y p = x - 40 turtle.setposition(p, q) turtle.up() p = x - 15 q = y + 55 turtle.setposition(p, q) turtle.down() q = y + 18 p = x - 28 turtle.setposition(p, q) #right turtle.up() p = x + 20 q = y + 55 turtle.setposition(p, q) turtle.down() q = y p = x + 40 turtle.setposition(p, q) turtle.up() p = x + 15 q = y + 55 turtle.setposition(p, q) turtle.down() q = y + 18 p = x + 28 turtle.setposition(p, q) #hat p = x q = y + 110 turtle.up() turtle.setposition(p, q) turtle.down() t = Triangle(p, q) t.draw() #lips p = x q = y + 17.5 turtle.up() turtle.setposition(p, q) turtle.down() turtle.pen(fillcolor="red", pencolor="red", pensize=1) turtle.begin_fill() turtle.circle(3) turtle.end_fill() turtle.pen(fillcolor="", pencolor="black", pensize=2) #body items p = x q = y - 15 turtle.up() turtle.setposition(p, q) turtle.down() c = Circle(7, "yellow") c.draw() p = x q = y - 55 turtle.up() turtle.setposition(p, q) turtle.down() c = Circle(7, "violet") c.draw() #base items p = x q = y - 125 turtle.up() turtle.setposition(p, q) turtle.down() c = Circle(7, "yellow") c.draw() p = x q = y - 180 turtle.up() turtle.setposition(p, q) turtle.down() c = Circle(7, "violet") c.draw()
sides = raw_input("number of sides to shape ") i = sides.isdigit() while i != True: print("Input MUST be a number") sides = raw_input("number of sides to shape ") i = sides.isdigit() sides = int(sides) shapeangle = 360 / sides print shapeangle #print turtle.pencolor() #print turtle.fillcolor() #print turtle.pensize() turtle.pen(fillcolor="Red", pencolor="blue", pensize=1) for x in range(0,72): turtle.fill(True) turtle.left(5) for n in range(0,sides): turtle.forward(150) turtle.left(shapeangle) #hide turtle once drawing complete turtle.hideturtle() #pause time.sleep(1) #grab screen ts = turtle.getscreen()
# squarespriral2.py import turtle t = turtle.Pen() t2 = turtle.Pen() t3 = turtle.pen() t.speed(0) for x in range(100): t.forward(2*x) t2.forward(2*x) t3.forward(7*x) t.left(91) t2.right(91) t3.left(80)
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import turtle >>> turtle.pen() {'shown': True, 'pendown': True, 'pencolor': 'black', 'fillcolor': 'black', 'pensize': 1, 'speed': 3, 'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 1, 'tilt': 0.0} >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.reset() >>> turtle.shape('turtle') >>> a = "Hello world" >>> for i in a: print(i) H e l l o w o r l d >>> for i in range(10):
def writer(text='coterie'): tl.setworldcoordinates(-1000.,-1000.,1000.,1000.) tl.shape('turtle') tl.color('white') tl.pen(pencolor = 'black', pensize = 5) tl.penup() ycrd = 0 xcrd = -450 text = str(text) text = text.lower() for i in text: if i is 'c': tl.goto(xcrd,ycrd) tl.pendown() tl.right(90) tl.forward(70) tl.left(90) tl.forward(70) tl.left(90) tl.penup() tl.forward(70) tl.pendown() tl.left(90) tl.forward(70) tl.penup() tl.right(180) xcrd += 120 ycrd -= 0 if i is 'o': tl.goto(xcrd,ycrd) tl.pendown() tl.right(90) tl.forward(70) tl.left(90) tl.forward(70) tl.left(90) tl.forward(70) tl.left(90) tl.forward(70) tl.penup() tl.right(180) xcrd += 120 ycrd -= 0 if i is 't': tl.goto(xcrd+70,ycrd) tl.pendown() tl.right(180) tl.forward(35) tl.left(90) tl.forward(70) tl.left(180) tl.forward(70) tl.left(90) tl.forward(35) tl.penup() tl.right(180) xcrd += 120 ycrd -= 0 if i is 'e': tl.goto(xcrd,ycrd) tl.pendown() tl.right(90) tl.forward(70) tl.left(90) tl.forward(70) tl.penup() tl.left(90) tl.forward(35) tl.pendown() tl.left(90) tl.forward(70) tl.right(90) tl.forward(35) tl.right(90) tl.forward(70) tl.penup() xcrd += 120 ycrd -= 0 if i is 'i': tl.goto(xcrd+35,ycrd) tl.pendown() tl.right(90) tl.forward(10) tl.penup() tl.forward(20) tl.pendown() tl.forward(40) tl.right(180) tl.penup() tl.forward(70) tl.right(90) xcrd += 120 ycrd -= 0 if i is 'r': tl.goto(xcrd+35,ycrd) tl.pendown() tl.right(90) tl.forward(70) tl.right(180) tl.forward(70) tl.right(90) tl.forward(50) tl.right(180) tl.forward(30) tl.right(180) tl.penup() xcrd += 120 ycrd -= 0 else: pass print(tl.position())
#named handler. signal.signal(signal.SIGINT, handler) #Create the pyramid pyramid_example = Pyramid(EXAMPLE_NODES, EXAMPLE_LEVELS) #Print the game description to the output file and console, #and print the pyramid to the output file. print(GAME_DESCRIPTION) output_file.write(GAME_DESCRIPTION + "\n") #Hide the turtle pen cursor by setting the pen attribute 'shown' to false. #Speed = 5 is half speed. hideturtle() to speed up the drawing. #penup() removes the line #trail left behind when drawing to the screen. turtle.pen(shown=False, speed=5) turtle.hideturtle() turtle.penup() #Draw the pyramid of nodes draw_pyramid(pyramid_example) #Set the cursor position to the first node, 1, which is at 0,0 turtle.setpos(0, 0) current_pos = turtle.stamp() #Continue rolling the die and traversing the pyramid until all #nodes in the pyramid have been visited. while pyramid_example.visited_nodes < EXAMPLE_NODES: #Draw a dot at the current node, and set the yellow to red intensity color #at this node based on how many dots it has
Python 3.7.8 (v3.7.8:4b47a5b6ba, Jun 27 2020, 04:47:50) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license()" for more information. >>> import turtle >>> turtle.Screen() <turtle._Screen object at 0x7fd5c37a8790> >>> turtle.pen() {'shown': True, 'pendown': True, 'pencolor': 'black', 'fillcolor': 'black', 'pensize': 1, 'speed': 3, 'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 1, 'tilt': 0.0} >>> turtle.shape("turtle") >>> turtle.forward(200) >>> turtle.shape("rectangle") Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> turtle.shape("rectangle") File "<string>", line 8, in shape File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/turtle.py", line 2776, in shape raise TurtleGraphicsError("There is no shape named %s" % name) turtle.TurtleGraphicsError: There is no shape named rectangle >>> turtle.left(90) >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.reset() >>> for i in range(4): turtle.forward(200) turtle.left(90) >>> turtle.reset()
t.up() t.goto(x - 15, y - 6) t.write("{}".format((i * label)), align="right") x_ratio = 709.0 / 256 y_ratio = 450.0 / pixels colors = ["red", "green", "blue"] for j in range(len(hist)): h = hist[j] x = -354 y = -199 t.up() t.goto(x, y) t.down() t.color(colors[j]) for i in range(256): x = i * x_ratio y = h[i] * y_ratio x = x - (709 / 2) y = y + -199 t.goto((x, y)) img = "22333.tif" histograms = [] arr = gdal_array.LoadFile(img) for b in arr: histograms.append(histogram(b)) draw_histogram(histograms) t.pen(shown=False) t.done
#2.7.py import turtle as t t.setup(1000, 1000) t.pen(shown=True, pendown=False, speed=0) a = 500 t.goto(-250, -250) t.seth(90) t.pendown() while (a != 0): t.fd(a) a -= 2.5 t.right(90) t.ht() t.done()
tcircrad = 15 # hide turtle and set draw speed turtle.setup(width=3000, height=1080, startx=0, starty=0) turtle.screensize(3000, 1080) turtle.hideturtle() turtle.speed(10) # line turtle.penup() turtle.right(180) turtle.forward(clusterlength * 0.5) turtle.right(180) turtle.pendown() turtle.pen(pencolor="black", pensize=4) turtle.forward(clusterlength) ## draw orfs turtle.penup() turtle.right(180) turtle.forward(clusterlength + offset) a, b = turtle.xcor(), turtle.ycor() print(a, b) turtle.right(90) turtle.pendown() a = 0 for n in orfs: turtle.pen(fillcolor=n[3], pencolor="black", pensize=4) turtle.begin_fill()
def togglePen(): if turtle.pen()["pendown"]: turtle.penup() else: turtle.pendown() print "Penstatus", turtle.pen()["pendown"]
How do dinosaurs pay their bills? With tyrannosaurus checks! >>> silly_string = 'He said, "Aren't can't shouldn't wouldn't."' SyntaxError: invalid syntax >>> silly_string = "He said, /"Chicken/'s!" SyntaxError: invalid syntax >>> silly_string = "He said, \Aren\'t can\'t shouldn\'t wouldn\t.\"" >>> print (silly_string) He said, \Aren't can't shouldn't wouldn ." >>> silly_string = "He said, \"Aren\'t can\'t shouldn\'t wouldn\'t.\"" >>> print (silly_string) He said, "Aren't can't shouldn't wouldn't." >>> silly_string = '''He said, "Aren't couldn't shouldn't wouldn't."''' >>> print (silly_string) He said, "Aren't couldn't shouldn't wouldn't." >>> import turtle >>> turtle.write <function write at 0x00000000050ADA58> >>> install turtle SyntaxError: invalid syntax >>> import turtle >>> >>> t = turtle.pen >>> t = turtle.pen() >>> import turtle >>> t = turtle.pen() =============================== RESTART: Shell =============================== >>> import turtle >>> t = turtle.pen()
def drawLine(x1, y1, x2, y2, color='black', size=1): turtle.pen(pencolor=color, pensize=size) turtle.penup() turtle.goto(x1, y1) turtle.pendown() turtle.goto(x2, y2)
import turtle as t wn = t.Screen() wn.bgcolor("light blue") wn.title("Python") t.dot(50) t.pen(pencolor="black", fillcolor="white", pensize=10, speed=9) t.begin_fill() t.circle(180) t.circle(170) t.circle(160) t.circle(150) t.circle(140) t.circle(130) t.circle(120) t.circle(110) t.circle(100) t.circle(90) t.circle(80) t.circle(70) t.circle(60) t.circle(50) t.circle(40) t.circle(30) t.circle(20) t.circle(10) t.circle(0) t.circle(-10) t.circle(-20) t.circle(-30) t.circle(-40)
""" for i in range(2): t.circle(r, angle) t.left(180 - angle) def flower(t, n, r, angle): """Use the Turtle (t) to draw a flower with (n) petals, each with the radius (r) and angle. """ for i in range(n): petal(t, r, angle) t.left(360.0 / n) turtle.pen(pencolor="#770E13", pensize="1") circ("#770E13", 400) turtle.pen(pencolor="#E67B47", pensize="1") circ("#E67B47", 390) turtle.pen(pencolor="#ECE19F", pensize="1") circ("#ECE19F", 380) turtle.begin_fill() turtle.pen(pencolor="red", pensize="1") turtle.fillcolor("red") turtle.speed(0) turtle.pen(pencolor="red", pensize="1") for k in range(40): square(270) turtle.rt(10) turtle.end_fill() turtle.pen(pencolor="orange", pensize="1")
import turtle t = turtle.pen() t.color(1,5) t.circle(30) t.forward(50) t.right(90) t.left(50) t.forward(60) t.circle(30)
import turtle turtle.pen() turtle.speed(0) for i in range(50): turtle.circle(5 * i) turtle.left(45)
# Pulls the pen up (no drawing when the turtle moves) turtle.penup() turtle.pu() turtle.up() # Puts the pen down (draws when the turtle moves) # You can use any of these methods turtle.pendown() turtle.pd() turtle.down() # Returns the pen's attributes in a dictionary # Tells you pen color, whether the pen is down or up, pensize, speed, etc. # The dictionary can be used as the pen argument, where pen is a dictionary # The pendict parameter is one of more of the keyword arguments that are in the list penstate = turtle.pen() turtle.pen(penstate, fillcolor = "yellow") # Returns True is the pen is down and False if it's up turtle.isdown() # ----------------------------------------------- #Color # Returns or sets the pen color # Can accept a colorstring (includes hex codes in the form of strings) # Can accept and RGB value in the form of a tuple or individual numbers turtle.colormode(255) turtle.pencolor() turtle.pencolor("red")
import turtle from math import pi, sin turtle.pen(speed=0) # for j in range(52): # turtle.left(5) # # for i in range(4): # nepracuje se s argumentem i, proste se probehne seznam o i polozkach # # turtle.speed(10) # turtle.pencolor("blue") # turtle.fillcolor("yellow") # turtle.forward(70) # turtle.right(90) # turtle.shape('turtle') from math import pi def obvod_obdelnika(sirka, vyska): return 2 * (sirka + vyska) print(obvod_obdelnika(2, 3)) def obsah_elipsy(a, b): return pi * a * b print(obsah_elipsy(2, 3))
import turtle as t t.pen(speed =0) def vk(l, n): if n == 1: t.forward(l) return d = l / 3 vk(d, n - 1) t.left(60) vk(d, n - 1) t.right(120) vk(d, n - 1) t.left(60) vk(d, n - 1) def f(l, n): t.up() t.goto( - l / 2, l / 3 ) t.down() for i in rang(3): vk(l, n) t.right(120) f(300, 6) """ from tkinter import * import os
import turtle t = turtle.pen() turtle.bgcolor('black') t.speed(0) sides = 2 colors = ['blue','white'] for x in range(120): t.pencolor(colors[x % sides]) t.forward(x)
#!/usr/bin/env python import turtle turtle.pen(fillcolor="black", pencolor="red", pensize=10)
import turtle from Arduino import Arduino pin=14 #A0 startPressure=295 #the reading we get with no pressure startSize=10 #which we will equate with drawing a radius of 10px modifyFactor=10 #modified by a factor of 10 board=Arduino('9600', 'COM6') board.pinMode(pin, 'INPUT') #set up turtle pen turtle.pen(fillcolor="purple", pencolor="black", pensize=10) turtle.speed(0) #don't delay drawing when called turtle.penup() #don't draw while we set up turtle.right(90) #degrees turtle.forward(modifyFactor*startSize) turtle.left(90) turtle.pendown() #start drawing try: while True: pressure=board.analogRead(pin) adjustedPressure=pressure-(startPressure-startSize) print("pressure="+str(pressure)+ " - adjustedPressure="+str(adjustedPressure)) turtle.clear() turtle.begin_fill() turtle.circle(modifyFactor*adjustedPressure) turtle.end_fill() except (KeyboardInterrupt, SystemExit): print('exiting') turtle.bye()
#!/usr/bin/env python # -*- coding : Utf-8 -*- import turtle as ttl import random as rd # Initialisations ttl.ht() ln_lig = 20 ln_s = 15 nbl = 20 la = 45 # Point zéro for ll in range(nbl): ttl.pen(speed = 5) ttl.up() ttl.goto(0, 0) ttl.down() angles = [rd.random() * 2 * la - la for x in range(ln_lig)] ttl.color([0, 0, 0]) for n in range(ln_lig): ttl.left(angles[n]) ttl.forward(ln_s) ttl.color([1, 0, 0]) ttl.pen(speed = 0) ttl.begin_fill(); ttl.circle(ln_s / 4); ttl.end_fill() # Fin ttl.mainloop()
#! /usr/bin/python3 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # Neven Sajko from turtle import degrees, forward, circle, left, pen (n, d, r) = input().split() (n, d, r) = (int(n), int(d), int(r)) degrees(n) # 'n' is the full circle. for unused_count in range(n): forward(d-4*r) pen(pendown=False) forward(2*r) pen(pendown=True) left(n/4) circle(r, 2*n-1) left(-n/4)
if not first_pixel: first_pixel = pixel t.goto(pixel) t.down() t.goto(first_pixel) t.up() t.goto([0,0]) t.write(state[NAME], align="center", font=("Arial",16,"bold")) for city in cities: pixel = convert(city[POINTS]) t.up() t.goto(pixel) # Place a point for the city t.dot(10) # Label the city t.write(city[NAME] + ", Pop.:" + str(city[POP]), align = "left") t.up() biggest_city = max(cities, key = lambda city:city[POP]) t.goto(0,-200) t.write("The biggest city is: " + biggest_city[NAME]) western_city = min(cities, key = lambda city:city[POINTS]) t.goto(0,-220) t.write("The western-most city is: " + western_city[NAME]) t.pen(shown=False) t.done()
def start(): """Initializes the turtle session with pre-defined presets""" turtle.getscreen() turtle.left(90) turtle.pen(fillcolor='#FFCB05', pencolor='#00274C', speed=5) return None
def draw_dragon(length, depth=5, **kwargs): turtle.pen(**kwargs) turtle.setheading(90) turtle.forward(length) draw_X(length, depth)
import turtle a = True turtle.speed(1000) x = 0 turtle.shape('turtle') turtle.right(270) turtle.pen(fillcolor="yellow", pencolor="black", pensize=1) turtle.begin_fill() for x in range(720): turtle.forward(1) turtle.left(0.5) turtle.end_fill() turtle.pen(fillcolor="blue", pencolor="black", pensize=1) turtle.penup() turtle.goto(-40, 30) turtle.pendown() turtle.begin_fill() for x in range(120): turtle.forward(1) turtle.left(3) turtle.end_fill() turtle.penup() turtle.goto(-80, 30) turtle.pendown() turtle.begin_fill() for x in range(120): turtle.forward(1) turtle.left(3) turtle.end_fill() turtle.pen(pensize=5) turtle.penup()