Python Forum

Full Version: I need help with a circle random color code and error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I got this assignment and I am completely lost and stumped, it is supposed to draw 20 random circles in random sizes and random locations, I have to index the colors. What does that mean? I am doing it but it says bad color string. Also the count range is not counting how many circles there are, it is counting how many colors, and the 20 circles have to be 3 colors only, but the amount of circles on my code has to be the same as the amount of colors there are, so there can only be 3 circles. Please help me figure this out because it is very frustrating and I don't know how to use index for each color.


[sourcecode language="python" wraplines="false" collapse="false"]
import turtle
import time
from random import randint, choice
from turtle import Screen, Turtle


#variables
horizontal = int()
radius = int()
colors = ["red", "blue", "green","yellow"]
pen_size = int()

horizontal = 5
radius = 25
pen_size = 2

#loop to draw the circles
for count in range(0, 4):
#set the fill color, pen size and fill color
turtle.fillcolor(colors[count])
turtle.pensize(pen_size)
turtle.begin_fill()
#draw circle
turtle.circle(radius)
#reset location, radius and pen size
horizontal = horizontal + 75
radius = radius + 20
pen_size = pen_size + 2
#moving the turtle
turtle.penup()
turtle.goto(horizontal, 0)
turtle.pendown()
turtle.end_fill()
time.sleep(1)
turtle.reset()
turtle.write("Ready for more circles?", align = "center", font=("Arial", 16, "bold"))
time.sleep(3)
turtle.reset()


colors = ['red', 'green', 'blue']


#loop to draw the circles
radius = randint(10, 90)
vertical = randint(10,90)
horizontal = randint(10,90)
pen_size = randint(0,10)
#set the fill color, pen size and fill color
for count in range(0, 20):
turtle.fillcolor('blue'[1])
turtle.fillcolor(colors[count])
turtle.pensize(pen_size)
turtle.begin_fill()
#draw circle
turtle.circle(radius)
#reset location, radius and pen size
#moving the turtle
turtle.penup()
turtle.goto(horizontal, 0)
turtle.pendown()
turtle.end_fill()
time.sleep(1)
turtle.reset()
turtle.write("Ready for more circles?", align = "center", font=("Arial", 16, "bold"))
time.sleep(3)
turtle.reset()

[/sourcecode]
Please, post your code in python tags, full traceback, if you get any - in error tags
(Mar-21-2021, 05:42 AM)Vxploit Wrote: [ -> ]So I got this assignment and I am completely lost and stumped, it is supposed to draw 20 random circles in random sizes and random locations, I have to index the colors. What does that mean? I am doing it but it says bad color string. Also the count range is not counting how many circles there are, it is counting how many colors, and the 20 circles have to be 3 colors only, but the amount of circles on my code has to be the same as the amount of colors there are, so there can only be 3 circles. Please help me figure this out because it is very frustrating and I don't know how to use index for each color.

[Image: 0?ui=2&ik=4a102f5490&attid=0.1&permmsgid..._kmiqgoq90]
You need to put your code in the message using a "python" tag. The image file does not display.

While there are three colors (Red, Green, Blue, or RGB), an actual color is a "triple" of three values: the percentage of red, the percentage of green, and the percentage of blue. They are not represented as percentages, but as integers in the range 0..255, where 0 is no color and 255 is 100%. So pure red is <255, 0, 0>; pure green is <0, 255, 0> and pure blue is <0, 0, 255>. But you can combine these, and not use 100%. For example, yellow is <255, 255, 0>, cyan is <0, 255, 255> and magenta is <255, 0, 255> Black is <0,0,0> and white is <255,255,255> (which I didn't put in white because you couldn't see it, but highlight the area between the <>s here: <255,255,255>. Values of the form <n,n,n> are shades of gray. Pink is <255, 153, 204>. Orange is <255, 204, 0>. Purple is <153, 51, 204>. So if you choose three random color values for each circle, you have a choice of 16,777,216 possible colors. But I can't make any suggestions unless I can see what you have written. I even tried pasting the URL into my browser bar, but nothing happened.
How do I use a python tag? I don't get how this all works.
Click the blue and yellow icon in the edit box. Paste your code between the tags that appear. All of your indentation is preserved. Works great.