Ask coding questions

← Back to all posts
Can you help me with filling the shape with a desired color?
BooleanBean (3)

This is in Python. It would be good if you could help me with this, but please don't fork, just ask for edit access(long story).

Comments
hotnewtop
RYANTADIPARTHI (6011)

Solution

use begin_fill, and end_fill

from turtle import *  
x = int (input('Please enter num of lines, in order to make your shape\n'))
y = int (input('Please enter the thickness of your line\n'))
z = int (input('How long would you like your line to be?\n'))
a = input('What colour would you like your shape to be filled with?\n')
b = input('What color would you like the edge of your shape to be?\n')
c = input('What color would you like the turtle to be?\n')

begin_fill("blue", "green")
for i in range(x):
	color(b, a)
	speed(6)
	begin_fill()
	pensize(y)
	forward(z)
	left(360/x)
	print('You have made your shape. ')
end_fill()

and to get it to work, you need to initialize your entire code.

from turtle import *  
t = turtle.Turtle()
t.color("red")
t.speed(0)
x = int (input('Please enter num of lines, in order to make your shape\n'))
y = int (input('Please enter the thickness of your line\n'))
z = int (input('How long would you like your line to be?\n'))
a = input('What colour would you like your shape to be filled with?\n')
b = input('What color would you like the edge of your shape to be?\n')
c = input('What color would you like the turtle to be?\n')


t.begin_fill("blue", "green")
for i in range(x):
	t.color(b, a)
	t.speed(6)
	t.begin_fill()
	t.pensize(y)
	t.forward(z)
	t.left(360/x)
	print('You have made your shape. ')
t.end_fill()

like that.
That should work