Python Forum
I need help with a circle random color code and error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with a circle random color code and error
#1
Photo 
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]
Reply
#2
Please, post your code in python tags, full traceback, if you get any - in error tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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.
Reply
#4
How do I use a python tag? I don't get how this all works.
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How Can I Draw Circle With Turtle İn Python ? mdm 2 2,752 Jun-03-2021, 02:07 PM
Last Post: DPaul
  Turtle circle Fabio87 3 2,480 Dec-17-2020, 10:52 PM
Last Post: Fabio87
  Calculate area of a circle pythonuser1 20 7,035 Apr-15-2020, 03:18 AM
Last Post: Skaperen
  Intersection of a triangle and a circle Gira 3 3,625 May-19-2019, 06:04 PM
Last Post: heiner55
  Creating code to make up to 4 turtle move simultaneously in a random heading J0k3r 3 5,496 Mar-05-2018, 03:48 PM
Last Post: mpd
  Need help displaying random color Ellicore 1 3,815 Feb-20-2018, 11:30 PM
Last Post: Larz60+
  radius of circle question charlottecrosland 5 4,222 Sep-11-2017, 09:50 AM
Last Post: charlottecrosland

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020