Python: write a function to create an image of a circle

I’m having a lot of difficulty figuring out the logic behind assignment 6.3.

I’m attempting to visualize the solution as a grid. I generate a list within a list to contain the information I will later use to code an image.
For example, if the radius is 3, the off states would look like this:
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0]

With the intention of turning on the corresponding pixels to the circle function I am to create:
[0, 0, 0, 1, 0, 0, 0] 
[0, 0, 1, 0, 1, 0, 0]
[0, 1, 0, 0, 0, 1, 0]
[1, 0, 0, 0, 0, 0, 1]
[0, 1, 0, 0, 0, 1, 0]
[0, 0, 1, 0, 1, 0, 0]
[0, 0, 0, 1, 0, 0, 0]

Obviously, a radius 3 circle is not going to look very defined, this was just a demonstration. I then intend to parse through each row and use the setPixel() function to activate the pixel in an EmptyImage object.

My trouble is figuring out how to get my function to encode the map of pixels..

I think I am doing this in a much more complicated manner than intended. Any advice?

Code thus far:

from cImage import *
from math import pi

radius   = 3
diameter = radius*2
pixel = Pixel(80,80,80)  # grey pixel

column    = []
for i in range(0, diameter+1): #allow for an odd number of columns

column.append(0)

map = []
for i in range(0, diameter+1): #allow for an odd number of columns

map.append(column)

for i in map:
print(i)

# All this spits out is the circumference, stuck here.
def myCircle(thisRadius):
circumference = 2 * pi * thisRadius
return int(circumference)

print(myCircle(radius))

#win    = ImageWin(“circ”, diameter, diameter)
#cirImg = EmptyImage(diameter, diameter)

Leave a Reply

Your email address will not be published. Required fields are marked *

captcha title thingy * Time limit is exhausted. Please reload the CAPTCHA.