A program for fun to see how red and blue appears blended to purple due to resolution I do some art both analog and digital. This time I did some color test digitally. To work on my programming skill so that it's shareable I'm asking for help to get some code review.


How's the readability?  
Is it easy to follow line of thought?  
Suggestion as to how to improve?


I'm using John Zelles graphics.py for this



#A program for fun to see how red, blue and purple appears at resolution 

from math import *
from graphics import *

def hole(win, centerx, centery, radius): #draws an inverted sphere
    for circle in range(radius, 0, -1):
        c = Circle(Point(centerx, centery), circle)
        c.setWidth(0)
        coloratangle = int(sin(circle/radius*pi/2)*255) #max resolution from black to white is 255 steps
        c.setFill(color_rgb(coloratangle * (circle % 2), 0, coloratangle * ((circle + 1) % 2))) # Modulus instead of Boolean? Modulus in c.setFill or in another line?
        c.draw(win)

windowheight = 1350
windowwidth = 730
win = GraphWin("My Circle", windowheight, windowwidth)
win.setBackground(color_rgb(255, 100, 100))

centerx = int(windowheight / 2)
centery = int(windowwidth / 2) #intetger
radius = int(sqrt(centerx**2 + centery**2)) #pythagoras

hole(win, centerx, centery, radius)

win.getMouse() # Pause to view result
win.close()    # Close window when done
I actually ran this. Good thing I don't have epilepsy, because wow. The flashing is intense.

There are many ways to improve this, depending on how technical you want to get. Move to a more advanced graphics library that's able to draw circles in an off-screen memory buffer before showing them in tkinter, your current windowing framework. This will speed up the rendering significantly and won't create that flashing (unless that's part of your art?).

There's a bug where moving your window creates even more flashing - this time, instead of being due to the concentric circles being rendered from the outside in, I suspect it's from the circles being re-rendered by graphics.py rather than flattening the representation of the image to a rasterized buffer. Rendering to an off-screen buffer will fix this, too.

There's another bug: closing the window produces this stack trace -

  File "/opt/pycharm-community-2019.2.1/helpers/pydev/pydevd.py", line 2060, in &lt;module&gt;
    main()
  File "/opt/pycharm-community-2019.2.1/helpers/pydev/pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/opt/pycharm-community-2019.2.1/helpers/pydev/pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/opt/pycharm-community-2019.2.1/helpers/pydev/pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/opt/pycharm-community-2019.2.1/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/gtoombs/PycharmProjects/zelles/zelles.py", line 25, in &lt;module&gt;
    win.getMouse() # Pause to view result
  File "/home/gtoombs/.virtualenvs/zelles/lib/python3.7/site-packages/graphics/__init__.py", line 316, in getMouse
    if self.isClosed(): raise GraphicsError("getMouse in closed window")
graphics.GraphicsError: getMouse in closed window


which means that you're not handling shut-down gracefully. See if you can change your exit condition to be either when the mouse event is received or the window is closed.