Difference between revisions of "CSC111 Lab 11 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- =Download= =Simple Test= <source lang="python"> from graphicsH import GraphicsWindow MAXWIDTH = 800 MAXHEIGHT = 600 def main(): win = GraphicsWindow(MAXWI...")
 
(Challenge)
Line 40: Line 40:
  
 
==Challenge==
 
==Challenge==
Generate 1000 random rects of random colors at random locations
+
Generate 500 random rects of random colors at random locations
  
 
=Draw circles=
 
=Draw circles=

Revision as of 09:19, 14 April 2014

--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 500 random rects of random colors at random locations

Draw circles