python,python-2.7,turtle-graphics
It looks like each draw_leaf call begins when the turtle is at the far end of the leaf that it just previously drew. So the polygon that is filled during the current draw_leaf includes that end point. This is more apparent if you draw each leaf with a different color....
python,image,python-2.7,turtle-graphics
The turtle module does have support for images, but only GIF images, not PNG or any other format. As the docs for addshape say: name is the name of a gif-file and shape is None: Install the corresponding image shape. And if you look at the source, they're serious about...
You just need to call the mainloop() function on the turtle module. So your last line should be: turtle.mainloop() ...
You can use the circle to draw the circle: chloe.pencolor("blue4") # draw the spokes for i in range(24): chloe.forward(20) chloe.backward(20) chloe.left(15) # raise pen chloe.up() # head down chloe.setheading(270) # go forward 20 chloe.forward(20) # reset heading chloe.setheading(0) # pen down chloe.down() # draw the circle chloe.circle(20) ...
begin_fill and end_fill don't take any arguments. You can specify fill color as the second argument to turtle.color. Additionally, begin_fill and end_fill should go outside the loop, because they should be called once per polygon rather than once per line. side_number = int(input("How many sides should the polygon have?")) side_length...
python,geometry,python-3.4,turtle-graphics
I think you may have some misunderstanding with regard to some of the functions in the turtle library. Firstly, turtle.window_height() and turtle.window_width() return the height and width of the window, so (as these values are not being assigned) those two lines do nothing. Similarly, turtle.Screen() returns an object, so again...
python,function,recursion,turtle-graphics,spiral
Depending on the values of initialLength and multiplier, it is very possible that your function will never be exactly 1. You check for this right here: if initialLength == 1 or newLength ==1: up() If it never reaches exactly one, the turtle will never stop drawing. Try changing it to:...
In the if statement, you should first turn, then go forward: Suppose you are at (0,299), and the turtle is facing up, you will go forward (let's say 100), then turn (let's say left). You will then be at (0, 399), facing left. You will then go in the else...
Some important things to note: turtle.pendown() does not change the particular instance or race, you want race.pendown() Each time you do race = turtle.Turtle(), you make a new instance of race Take this statement out side of the for loop. Each loop you make you need to move race (for...
As Brian states, you will probably want to choose a potential buyer and potential seller (so the sellers don't run out of goods etc). However, if you really want all buyers to buy from all sellers with a suitable price, you want code that uses 'myself' to access the variables...
Generally, yes, you do want to avoid using the form from module import *. That that does is that it opens up the module (a normal python file), and essentially takes every function, class, etc. defined within that file and adds it to your namespace. And you're right -- *...
Maybe you call your file turtle.py and now Python can't find oryginal turtle file in library.
A reason might be that your map only has positive coordinates. So the robot obviously cant find a route as the goal is not on the map. Maybe have a look at your map using rviz....
You could try something like this from turtle import * def drawcircles(circum): #multiples of 10 while circum > 0: circle(circum) circum -= 10 penup() left(90) forward(10) right(90) pendown() drawcircles(50) exitonclick() I draw a circle, reset the position and draw again, the only catch with this code is that the circumference...
python,python-2.7,graphics,turtle-graphics
It's still turtle.mainloop(), not wn.mainloop(). I suspect the reason for this is since you can make multiple screens, it makes sense to still have the turtle module manage all of the screens instead of trying to potentially make multiple mainloops work together....
#!/usr/bin/python # -*- coding: utf-8 -*- import turtle truck = turtle.Turtle() truck.fd(50) truck.color("blue", "red") truck.begin_fill () truck.circle(50) truck.fd(50) truck.end_fill() truck.color("blue", "green") truck.begin_fill () for i in range(2): truck.right(90) truck.fd (100) truck.right(90) truck.fd(100) truck.end_fill () turtle.done() ...
You can use set xcor ... and set ycor ..., or setxy ... ..., or any other turtle motion command such as fd or bk, to position the turtle however you like. If the turtle's coordinates are both integers, it's on a patch center. If either or both aren't integers,...
python,variables,turtle-graphics
First, you need to define some functions that we will use to define the operations of your turtle object: def forward(): turt.forward(30) def left(): turt.left(90) def right(): turt.right(90) Next, we need to create a dictionary mapping the string keys to the functions that we had just defined: map = {'F':...
You need to figure out the extent of the region defined by the square so you can compare mouse-click positions to it later and see if they're inside it or not. Here's a complete program that first allows the lower-left corner of the square to be defined by a click,...
You can call the font function to set up a different font before calling text. Here are some example calls: font("serif") -- change font font(32) -- change size font("italic") font("serif 32") -- or change both text("Text") Or in your code example: io.write("Enter the time in seconds that the timer will...
python,loops,drawing,turtle-graphics
For circle in range(num, 0, -1):90 (num..1) In For Condition “:” is a must to Indicate the start of the loop, For circle in range(num, 0, -1): #(num..1) Your variable num is not defined as well, Assuming you have misplaced it with variable n. This will give you concentric...
Solved the problem by declaring variables tx, ty = t.pos() and then doing the comparison if tx < -200 or tx > 200 or ty < -200 or ty > 200: playing = False Still don't know why that was an issue....
So you're making a turtle t, then completely ignoring it and passing to drawRectangle a turtle (?) that you have actually never made at all. Obviously, you'll need to pass to the function exactly the turtle you have made, not another! Moreover, the color and fillColor you've set on the...
python,list,split,turtle-graphics
I think you've actually got a wider confusion here. The initial error is that you're trying to call split on the whole list of lines, and you can't split a list of strings, only a string. So, you need to split each line, not the whole thing. And then you're...
python,tkinter,turtle-graphics
Well, I clearly didn't look hard enough. Right there in the documentation is pen.isdown() Sorry, feel free to delete the question.
python,math,canvas,turtle-graphics,sine
y = 50*(math.sin(math.radians(x))) with x in the range from min to max will of course produce the corresponding graph, if (min,max)=(0,300) then from sin(0) to sin(300*pi/180). (x-min)/(max-min) will produce a variable in the range of 0 to 1 -1+2*(x-min)/(max-min) correspondingly a variable in the range from -1 to 1. So...
python,python-3.x,turtle-graphics
You need to specify your forward commands so the turtle starts at the center of the line, and draws one half of the line in front of it and one half behind it. Like this: def drawI(depth, size): if(depth < 1): pass else: #draw the half in front of the...
python,list,python-3.x,turtle-graphics
If you want to iterate over separations: def droplets(t, size, separations): for i in range(len(separations)): t.down() t.circle(size) t.up() t.forward(separations[i]) Or, more simply, just iterate over separations instead of using indexes: def droplets(t, size, separations): for separation in separations: t.down() t.circle(size) t.up() t.forward(separation) ...
python,function,fill,turtle-graphics
You need to draw the column after choosing the colour: def fillColor(t,height): if height >=200: t.fillcolor("red") elif height >= 100 and height < 200: t.fillcolor("yellow") else: t.fillcolor("green") drawBar(t,height) (The first column was black because that is the default fillcolor.)...
You are using t as a variable somewhere else in your program and thus you are getting an error Try import turtle for i in range(tt+2): turtle.goto(horizontal[i], height[i]) This will work...
python,recursion,turtle-graphics
The example invocation you posted (spiral( 100, 90, 0.9 )) seems to treat the second parameter as the degree of each turn whereas you treat it as the number of turns to make a complete 360 degree turn in your code. Either change the call to spiral(20, 4, 0.9) or...
Yes, you can iterate over your Turtle instances, for example by putting them into a list and looping over it: for turtle_instance in [a, b, c, d]: turtle_instance.setpos(...) In fact, it is probably easier to start with them in a list: turtles = [Turtle() for _ in range(4)] # see...
turtle-graphics,iced-coffeescript
The result from hatch is a jquery object, so you can access the jth turtle by using the jquery function eq(j). For example turtles = hatch 10 turtles.eq(5).pen(red).fd(100) ...
Method 1 You are simply importing the package turtle and as you may already know, you are unable to use a variable that has not been declared. Thus, you must reference every item with the package name as a prefix like turtle.Pen or turtle.Turtle. Method 2 You are not importing...
btn=2 references a scroll wheel push (not scroll). btn=3 references a rightclick....
turtle-graphics,ucb-logo,logo-lang
You have to find the perimeter first, then divide it by the total number of rotations, then set that as the value of forward in your loop. E.g. make "d 100 make "p 3.141592654*:d make "i :p/36 repeat 36[fd :i rt 10] you can have all of them in a...
python,if-statement,while-loop,turtle-graphics
for i in range(4): while True: move = input("Enter x, y coordinates for X's move: ") x,y = int(move[0]), int(move[-1]) # don't use eval() if board[x][y] not in ('X', 'O') # if valid tic.goto(x+.25,y+.25) tic.write("X",font=('Arial', 90, 'normal')) board[x][y] = "X" break # break out of loop after doing stuff ...
python,python-3.x,turtle-graphics
I'm not an expert on turtle, but is this what you're looking for? import turtle s = turtle.Screen() t = turtle.Turtle() def drawLine(t, length): t.pendown() t.forward(length) t.penup() def there_and_back(t, length): drawLine(t, length) t.penup() t.right(180) t.forward(length) t.right(180) t.pendown() length = 50 #Question 14 Part b- def spikes(numLines, lengthIncr, angle): for i...