def rysuj(): turtle.tracer(0, 0) # wylaczenie animacji co KROK, w celu przyspieszenia turtle.hideturtle() # ukrycie glowki zolwika turtle.penup() # podnosimy zolwia, zeby nie mazal nam linii podczas ruchu ostatnie_rysowanie = 0 # ile kropek temu zostal odrysowany rysunek for i in xrange(ILE_KROPEK): # losujemy wierzcholek do ktorego bedziemy zmierzac do = random.choice(WIERZCHOLKI) # bierzemy nasza aktualna pozycje teraz = turtle.position() # ustawiamy sie w polowie drogi do wierzcholka, ktorego wczesniej obralismy turtle.setpos(w_polowie_drogi(teraz, do)) # stawiamy kropke w nowym miejscu turtle.dot(1) ostatnie_rysowanie += 1 if ostatnie_rysowanie == OKRES_ODSWIEZENIA: # postawilismy na tyle duzo kropek, zeby odswiezyc rysunek turtle.update() ostatnie_rysowanie = 0 pozdrowienia() turtle.update()
def draw(self, x, y, width, height, max_length=None, force_fields=None): """Draw the string. The grammar-system axiom is extended to the specified depth""" self.reset() turtle.setup(width,height,None,None) turtle.tracer(200,0) self.penup() self.setposition(x,y) self.origin = x, y self.max_length = max_length while not self.grammar_system.done and \ self.grammar_system.generation < self.depth: self.grammar_system.step() if (self.max_length is not None and len(self.grammar_system.string) > self.max_length): self.hideturtle() print("Drawing exceeded maximum length") return False print(self.grammar_system.string) if force_fields: for force_field in force_fields: self.force_fields.append(Attractor(force_field['type'], force_field['effect'], force_field['x'], force_field['y'], force_field['size'])) non_null = self._draw(self.grammar_system.string, self._rules) self.hideturtle() turtle.update() return non_null
def set(): #set of parameters turtle.hideturtle() turtle.tracer(1e3,1) turtle.left(95) turtle.penup() turtle.goto(0,-turtle.window_height()/2) turtle.pendown()
def draw_maze(): t.speed(0) turtle.tracer(10, 25) t.pensize(3) t.penup() t.goto(0, 0) t.pendown() t.goto(20 * NC, 0) t.goto(20 * NC, 20 * NR) t.goto(0, 20 * NR) t.goto(0, 0) for i, ns in enumerate(nodes): y1, x1 = points[i] for n in (n for n in ns if n > i): y2, x2 = points[n] t.penup() if n == i + 1: t.goto(20 * x2, 20 * y1) t.pendown() t.goto(20 * x2, 20 * (y1 + 1)) else: t.goto(20 * x1, 20 * y2) t.pendown() t.goto(20 * (x1 + 1), 20 * y2)
def setup(): turtle.hideturtle() turtle.tracer(1e3,0) turtle.left(90) turtle.penup() turtle.goto(0,-turtle.window_height()/2) turtle.pendown()
def __init__(self, length=10, angle=90, colors=None, lsystem=None): import turtle self.length = length self.angle = angle if colors is None: self.colors = ['red', 'green', 'blue', 'orange', 'yellow', 'brown'] if lsystem is not None: self.lsystem(lsystem) # draw number self.ith_draw = 0 # origin of next draw self.origin = [0, 0] # bounding_box self._box = 0, 0, 0, 0 # turtle head north and positive angles is clockwise turtle.mode('world') turtle.setheading(90) turtle.speed(0) # fastest turtle.hideturtle() turtle.tracer(0, 1) # set pencolor self.pencolor()
def draw(self): super(DragonLSystem, self).draw() turtle.setup(800,600) wn = turtle.Screen() wn.bgcolor('lightblue') wn.title("Wingled Dragon") self.turtle = turtle.Turtle() self.turtle.shape('blank') turtle.tracer(int(sys.argv[2]),25) t = self.turtle t.reset() t.penup() t.setpos(-200,0) t.pendown() i = 200.0 for c in self.state: if c == "F": t.forward(math.ceil(i)) elif c == "+": t.right(90) elif c == "-": t.left(90) elif c == "C": i = i/math.sqrt(2) t.left(45) wn.exitonclick()
def extension1(): turtle.tracer(False) for i in range(50): turtle.setheading( random.randint(0,360)) shapelib.parallelogram( random.randint(-350,-250), random.randint(-300, 300), random.random(), 'red') for i in range(50): turtle.setheading( random.randint(0,360)) shapelib.cross( random.randint(-200, -100), random.randint(-300, 300), random.random(), 'yellow') for i in range(50): turtle.setheading( random.randint(0,360)) shapelib.star( random.randint(-50, 50), random.randint(-300, 300), random.random(), 'pink') for i in range(50): turtle.setheading( random.randint(0,360)) shapelib.star( random.randint(100, 200), random.randint(-300, 300), random.random(), 'orange') for i in range(50): turtle.setheading( random.randint(0,360)) shapelib.cross( random.randint(250, 350), random.randint(-300, 300), random.random(), 'green') for i in range(50): turtle.setheading( random.randint(0,360)) shapelib.parallelogram( random.randint(400, 500), random.randint(-300, 300), random.random(), 'blue')
def skyobjects( x, y, scale ): '''puts all of the objects in sky functions togehter''' t.tracer(False) star(x-300*scale, y+225*scale, 1*scale, 'True', 'orange') cloud(x+250*scale, y+200*scale, 1*scale, 'gray') cloud(x+175*scale, y+125*scale, 0.5*scale, 'gray') cloud(x+125*scale, y+215*scale, 0.25*scale, 'gray')
def Run(): #bounds nearRange = [0, 50] farRange = [50, 200] frusHL = 100 #Logic nearDist = random.uniform(nearRange[0], nearRange[1]) farDist = random.uniform(farRange[0], farRange[1]) d = frusHL * 2 an = nearDist af = farDist b = (d*d + af*af - an*an) / (2 * d) radius = math.sqrt(b*b + an*an) originY = -frusHL + b #text.insert('end', 'Origin: %d\n' % originY) #Render turtle.clear() turtle.hideturtle() turtle.tracer(0, 0) turtle.penup() turtle.goto(-farDist, frusHL) turtle.pendown() turtle.goto(-nearDist, -frusHL) turtle.goto(nearDist, -frusHL) turtle.goto(farDist, frusHL) turtle.goto(-farDist, frusHL) turtle.penup() DrawCircle(0, originY, radius); turtle.update()
def __init__(self, model): """Initialize the view at the starting of the application.""" self.model = model self.cellWidth = self.CELL_WIDTH self.model = model self.gridSize = model.GRID_SIZE self.player = self.model.player1 self.screen = turtle.Screen() self.gridWidth = self.CELL_WIDTH * self.gridSize self.playerGrid = self.player.getGrid(self.player.PLAYER_GRID) self.enemyGrid = self.player.getGrid(self.player.OPPONENT_GRID) self.iconsToDraw = [] turtle.title('BATTLESHIP : {} vs {}'.format( self.model.player1.playerName, self.model.player2.playerName)) self.__setScreen() self.__setColor() turtle.tracer(0, 0) gridWidth = self.gridWidth gridAnchorPoints = [] gridAnchorPoints.append(( -self.width/2 + self.GRID_MARGINLEFT, self.height/2 - self.GRID_MARGINTOP - gridWidth)) gridAnchorPoints.append(( self.width/2 - gridWidth - self.GRID_MARGINRIGHT, self.height/2 - self.GRID_MARGINTOP - gridWidth )) self.__drawGrid(gridAnchorPoints[0], gridWidth) self.__drawGrid(gridAnchorPoints[1], gridWidth) self.gridAnchorPoints = gridAnchorPoints
def foliageRight( x, y, scale): ''' foliage scenery right side of image use tree() and leaf() functions defined earlier to make a variety of size and color foliage using for loops to make multiple''' t.tracer(False) for i in range(5): tree( x+random.randint( 100, 350 )*scale, y+random.randint( -300, -100 )*scale, random.randint( 1, 2 )*scale) for i in range(10): leaf( x+random.randint( 100, 300 )*scale, y+random.randint( -300, -100 )*scale, random.random()*scale, 'red' ) for i in range(10): leaf( x+random.randint( 100, 300 ), y+random.randint( -300, -100 ), random.random()*scale, 'orange' ) for i in range(10): leaf( x+random.randint( 100, 300 )*scale, y+random.randint( -300, -100 )*scale, random.random()*scale, 'yellow' )
def setTurtle(self): """Initializes the turtle object and screen object, while also setting the speed to the maximum""" self.t = turtle.Turtle() self.s = turtle.Screen() self.t.speed(0) turtle.tracer(0,0)
def setup(): turtle.hideturtle() turtle.tracer(1e3,0) turtle.left(90) turtle.penup() turtle.goto(-100,-100) turtle.pendown()
def tree1(argv, x, y): lsys_filename1 = argv[1] lsys1 = ls.createLsystemFromFile( lsys_filename1 ) print lsys1 num_iter1 = int( 3 ) dist = float( 5 ) angle1 = float( 22 ) s1 = ls.buildString( lsys1, num_iter1 ) #draw lsystem1 '''this is my first lsystem with filename mysystem1.txt with 3 iterations and with angle = 45 dist = 10''' turtle.tracer(False) turtle.speed(50000000) turtle.up() turtle.goto(0,0) turtle.goto(x, y) turtle.down() turtle.pencolor('White') it.drawString( s1, dist, angle1 ) # wait and update turtle.update()
def drawSetup(title,xlimits,xscale,ylimits,yscale,axisThickness=None): turtle.title(title) xmin, xmax = xlimits ymin, ymax = ylimits #turtle.setup(xmax-xmin,ymax-ymin,0,0) #window-size globals()['xmin'] = xmin globals()['xmax'] = xmax globals()['ymin'] = ymin globals()['ymax'] = ymax globals()['xscale'] = xscale globals()['yscale'] = yscale turtle.setworldcoordinates(xmin,ymin,xmax,ymax) #turtle.speed(0) #turtle.speed() does nothing w/ turtle.tracer(0,0) turtle.tracer(0,0) drawGrid() #drawGridBorder() turtle.pensize(axisThickness) drawXaxis() drawXtickers() numberXtickers() drawYaxis() drawYtickers() numberYtickers() turtle.pensize(1)
def __init__(self): # Janela sobre self.janSobre = None # Cor de fundo self.corFundo = "gray" turtle.screensize(1000, 700, self.corFundo) turtle.setup(width=1000, height=700) turtle.title("cidadeBela - Janela de desenho") turtle.speed(0) turtle.tracer(4) # Definindo variáveis globais self._tamPadrao = "" # Listas de prédios self.predios = ['Casa', 'Hotel'] self.prediosProc = [ 'hotel', 'hotelInv', 'casa', 'casaInv' ] # Sorteando elementos self.sorteioPredios = [["casa", 1], ["hotel", 1]] self.sorteioPrediosInv = [["casaInv", 1], ["hotelInv", 1]] # Cores dos prédios self.coresHotel = ["076080190", "255255255", "167064057", "153204255", "000090245", "201232098", "255058123", "010056150", "130255255", "255255000", "255000000", "255127042", "000255000", "255170255", "000255170", "212000255", "170255127", "127212255", "255127127", "255212085", "212212255", "255255127", "222202144" ] self.coresCasa = ['209187103', '115155225', '130047006', '255137111', '203229057', '017130100', '025195159', '204057065', '194082255', '092221159', '167045055', '238243030', '069241248', '000156228', '159094040', '048033253', '040209239', '138164253', '190042177', '000122159', '255255255', '253208201', '245228133'] self.coresLoja = ['255255255', '253208201', '245228133' ] # Janelas dos prédios self.janelasHotel = janelas.janelasHotel self.janelasCasa = janelas.janelasCasa self.janelasLoja = janelas.janelasLoja self.janelasTodas = janelas.janelasTodas # Tetos dos prédios self.tetosHotel = tetos.tetosHotel self.tetosCasa = tetos.tetosCasa self.tetosLoja = tetos.tetosLoja self.tetosTodas = tetos.tetosTodas # Portas dos prédios self.portasHotel = portas.portasHotel self.portasCasa = portas.portasCasa self.portasLoja = portas.portasLoja self.portasTodas = portas.portasTodas
def floor( x, y, scale ): t.tracer(False) position1 = [-600, -500, -400, -300, -200, -100, 0, 100, 200, 300, 400, 500] position2 = [-550, -450, -350, -250, -150, -50, 50, 150, 250, 350, 450, 550] for i in range(len(position1)): t.begin_fill() t.color('Black') bsl.buildingblock(x+position1[i]*scale, y-300*scale, 50*scale, 50*scale) t.end_fill() for i in range(len(position1)): t.begin_fill() t.color('Gold') bsl.buildingblock(x+position2[i]*scale, y-300*scale, 50*scale, 50*scale) t.end_fill() for i in range(len(position1)): t.begin_fill() t.color('Gold') bsl.buildingblock(x+position1[i]*scale, y-250*scale, 50*scale, 50*scale) t.end_fill() for i in range(len(position1)): t.begin_fill() t.color('Black') bsl.buildingblock(x+position2[i]*scale, y-250*scale, 50*scale, 50*scale) t.end_fill() for i in range(len(position1)): t.begin_fill() t.color('Black') bsl.buildingblock(x+position1[i]*scale, y-200*scale, 50*scale, 50*scale) t.end_fill() for i in range(len(position1)): t.begin_fill() t.color('Gold') bsl.buildingblock(x+position2[i]*scale, y-200*scale, 50*scale, 50*scale) t.end_fill()
def draw(self, w, h, dot = False): norm = CoordinateNormalizer(self, w, h) window = turtle.Screen() cursor = turtle.Turtle() window.setup(w, h) window.setworldcoordinates(0, 0, w, h) window.delay(0) cursor.ht() turtle.tracer(0) cursor.up() for way in self.getWays(): tags = self.ways[way].tags line = self.getPolyline(way) for (x, y) in line: cursor.pencolor('black') x, y = norm(x, y) cursor.setpos(x, y) if dot: cursor.dot() if not cursor.isdown(): cursor.down() cursor.up() turtle.update() window.exitonclick()
def initialize_plot(self, positions): self.positions = positions self.minX = minX = min(x for x,y in positions.values()) maxX = max(x for x,y in positions.values()) minY = min(y for x,y in positions.values()) self.maxY = maxY = max(y for x,y in positions.values()) ts = turtle.getscreen() if ts.window_width > ts.window_height: max_size = ts.window_height() else: max_size = ts.window_width() self.width, self.height = max_size, max_size turtle.setworldcoordinates(minX-5,minY-5,maxX+5,maxY+5) turtle.setup(width=self.width, height=self.height) turtle.speed("fastest") # important! turtle is intolerably slow otherwise turtle.tracer(False) # This too: rendering the 'turtle' wastes time turtle.hideturtle() turtle.penup() self.colors = ["#d9684c","#3d658e","#b5c810","#ffb160","#bd42b3","#0eab6c","#1228da","#60f2b7" ] for color in self.colors: s = turtle.Shape("compound") poly1 = ((0,0),(self.cell_size,0),(self.cell_size,-self.cell_size),(0,-self.cell_size)) s.addcomponent(poly1, color, "#000000") turtle.register_shape(color, s) s = turtle.Shape("compound") poly1 = ((0,0),(self.cell_size,0),(self.cell_size,-self.cell_size),(0,-self.cell_size)) s.addcomponent(poly1, "#000000", "#000000") turtle.register_shape("uncolored", s)
def sky( x, y, scale ): '''draws a huge blue square given location and scale''' t.tracer(False) t.begin_fill() t.color('light blue') buildingblock(x-1000*scale, y+0*scale, 2000*scale, 1075*scale) t.end_fill()
def grass( x, y, scale ): '''draws a huge blue square given location and scale''' t.tracer(False) t.begin_fill() t.color('green') buildingblock(x-1000*scale, y-1000*scale, 2000*scale, 1075*scale) t.end_fill()
def drawPattern(turt, offx, offy, radius, step): # Points is the number of points per side, NOT including the corner points # Draw lines between the points around teh box in the given pattern # drawRect(turt, offx, offy, sizex, sizey) # Basic rectangle to outline the shape pointsl = drawCricle(turt, offx, offy, radius, step) turtle.tracer(1) for p in range(len(pointsl)): turt.color(getRandColor(cols)) for p2 in range(len(pointsl)-3): if not p+p2+2 > len(pointsl)-1: drawLine(turt, pointsl[p][0], pointsl[p][1], pointsl[p+p2+2][0], pointsl[p+p2+2][1]) else: drawLine(turt, pointsl[p][0], pointsl[p][1], pointsl[p+p2+2 - len(pointsl)][0], pointsl[p+p2+2 - len(pointsl)][1]) turtle.update() # Draw a nice looking border around the rectangle # turt.pensize(10) # Make it thick # drawRect(turt, offx, offy, sizex, sizey) # turt.pensize(1) # Reset pen size turt.penup() turt.setpos(offx, offy) #Sit in the centre of the circle at the end turtle.update()
def foliageLeft(): ''' foliage scenery left side of image use tree() and leaf() functions defined earlier to make a variety of size and color foliage using for loops to make multiple''' turtle.tracer(False) for i in range(5): tree( random.randint( -300, -100 ), random.randint( -300, -100 ), random.randint( 1, 2 )) for i in range(10): leaf( random.randint( -300, -100 ), random.randint( -300, -100 ), random.random(), 'red' ) for i in range(10): leaf( random.randint( -300, -100 ), random.randint( -300, -100 ), random.random(), 'orange' ) for i in range(10): leaf( random.randint( -300, -100 ), random.randint( -300, -100 ), random.random(), 'yellow' )
def main(): # 打开/关闭龟动画,并为更新图纸设置延迟。 turtle.tracer(False) Init() SetupClock(160) turtle.tracer(True) Tick() turtle.mainloop()
def drawRect(t, x1, y1, sizex, sizey): # Simply draws a rectangle turtle.tracer(0) # If this is 0, the rectangle is drawn instantly drawLine(t, x1 - sizex/2, y1 - sizey/2, x1 + sizex/2, y1 - sizey/2) # Up drawLine(t, x1 - sizex/2, y1 + sizey/2, x1 + sizex/2, y1 + sizey/2) # Down drawLine(t, x1 - sizex/2, y1 - sizey/2, x1 - sizex/2, y1 + sizey/2) # Left drawLine(t, x1 + sizex/2, y1 - sizey/2, x1 + sizex/2, y1 + sizey/2) # Right turtle.update()
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 painting( x, y, scale ): t.tracer(False) t.begin_fill() t.color('Brown') bsl.buildingblock(x-400*scale, y-75*scale, 250*scale, 250*scale) t.end_fill() bsl.myscene2(-275, 50,.10) t.setheading(0)
def __init__(self): self.turtle = turtle.Turtle() self.turtle.hideturtle() self.struct_header = '>III' self.size = 40 self.mh = None self.reset() turtle.tracer(__DEBUG__)
def drawleaf(self): turtle.tracer(0) self.turt.color("green") self.turt.pensize(random.randint(5, 10)) self.turt.penup() self.turt.right(random.randint(-20, 20)) self.turt.pendown() self.turt.forward(10)