CSC111 Lab 11 2014

From dftwiki3
Revision as of 17:42, 13 April 2014 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- =Download= =Simple Test= <source lang="python"> from graphicsH import GraphicsWindow MAXWIDTH = 800 MAXHEIGHT = 600 def main(): win = GraphicsWindow(MAXWI...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 17:42, 13 April 2014 (EDT)


Download

Simple Test

from graphicsH import GraphicsWindow

MAXWIDTH = 800
MAXHEIGHT = 600


def main():
    win = GraphicsWindow(MAXWIDTH, MAXHEIGHT)
    canvas = win.canvas()

    canvas.setFill( 255, 0, 0  )    # full red
    canvas.drawRect( 100, 100, 300, 200 )

    win.wait()

main()

Improve on it

  • Try with different colors by picking a different combination of the three ints in setFill()
  • Try a random color. Hints: to generate a random number between 0 and 255, you can do this:
# at the top of the program
from random import seed
from random import randrange

def main():
    seed()
    ...
    x = randrange( 256 ):

Challenge

Generate 1000 random rects of random colors at random locations

Draw circles