# Draw a smooth color gradient from black at the top of the window to gold # (255, 192, 64) at the bottom of the window. The gradient is drawn from # bottom to top. from SimpleGraphics import * # For each row on the screen from bottom to top for y in range(getHeight() - 1, -1, -1): # Compute the amount of red, green and blue for the current row r = int(y / (getHeight() - 1) * 255) g = int(y / (getHeight() - 1) * 192) b = int(y / (getHeight() - 1) * 64) # I have explicitly cast r, g and b to integers to deal with a change # made in Python 3.5.0 which does not allow the format operator (%) to # format a floating point number in hexadecimal using the %x format. If you # are running an earlier version then the integer casts are not necessary. # Set the current color setColor(r, g, b) # Draw a horizontal line in that color line(0, y, getWidth() - 1, y)