random circles using SimpleGraphics
<p>I need to make a circle by adjusting conditions on the heights, this program using a lot of random circles but I am unsure where to go from here? I am trying to use the following equation d = (sqrt)((x1 âx2)^2 +(y1 â y2)^2). Right now the program draws many random circles, so adjusting the formula i should be able to manipulate it so that certain circles are red in the centre (like the japan flag).</p>

<pre><code># using the SimpleGraphics library
from SimpleGraphics import *

# use the random library to generate random numbers
import random

diameter = 15


##
# returns a valid colour based on the input coordinates
#
# @param x is an x-coordinate 
# @param y is a y-coordinate 
# @return a colour based on the input x,y values for the given flag
##
def define_colour(x,y):
##

if y &lt; (((2.5 - 0)**2) + ((-0.5 - 0)**2)**(1/2)):
c = 'red'
else:
c = 'white'

return c


return None


# repeat until window is closed
while not closed():

# generate random x and y values 
x = random.randint(0, getWidth())
y = random.randint(0, getHeight())

# set colour for current circle
setFill( define_colour(x,y) )

# draw the current circle
ellipse(x, y, diameter, diameter)
</code></pre>

<p>Here's some code that endlessly draws circles. Circles that are close to the centre of the screen will be drawn in red, all other circles will be drawn in white. Eventually, this will create an image similar to the flag of Japan, although the edge of the inner red "circle" will not be smooth.</p>

<p>I have not tested this code because I don't have the <code>SimpleGraphics</code> module, and I'm not having much success locating it via Google or pip.</p>

<pre><code>from SimpleGraphics import *
import random

diameter = 15

width, height = getWidth(), getHeight()
cx, cy = width // 2, height // 2

# Adjust the multiplier (10) to control the size of the central red portion   
min_dist_squared = (10 * diameter) ** 2

def define_colour(x, y):
    #Calculate distance squared from screen centre
    r2 = (x - cx) ** 2 + (y - cy) ** 2
    if r2 &lt;= min_dist_squared:
        return 'red'
    else:
        return 'white'

# repeat until window is closed
while not closed():
    # generate random x and y values 
    x = random.randrange(0, width)
    y = random.randrange(0, height)

    # set colour for current circle
    setFill(define_colour(x, y))

    # draw the current circle
    ellipse(x, y, diameter, diameter)
</code></pre>

python python-3.x graphics