Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 150
Introduction to Computer Science

Michael Goldwasser

Fall 2005

Dept. of Math & Computer Science

Homework Assignment 02

slugraphics warmup

Contents:


Overview

Topic: slugraphics warmup
Related Reading: Documentation on slugraphics package
Due: 1:10pm, Monday 12 September 2005

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

Try to find the errors in the following statements/programs without using a computer. Then try running them on the computer to help find the errors or confirm your answers.

  1. (4 points)

    When starting to draw a picture to the screen you enter:

    	can = Canvas(100,100)
    	
    Python gives you an error with the last line saying:
    	NameError: name 'Canvas' is not defined
    	
    What did you do wrong? How do you fix it?

  2. (4 points)

    Assuming that you have already sucessfully created a Canvas instance called can, you enter the following to draw a blue circle centered in a red square:

            sq = Square()
            sq.setSize(40)
            sq.moveTo(30,30)
            sq.setFillColor("Red")
            can.add(sq)
                    
            cir = Circle()
            cir.moveTo(50,50)
            cir.setRadius(15)
            cir.setFillColor("Blue")
            can.add(cir)
            can.refresh()
    	
    But, the circle never appears. What's wrong with the above program? Edit the program so it works as desired.

  3. (4 points)

    Assuming that you have already created an instance of the Square class called sq, what's wrong with the statement

            sq.setFillColor(Red)
    	
    Give two different ways to fix this statement.

  4. (4 points)

    After importing the library you enter

            can = Canvas(200,150)
            sq = Square()
            Canvas.add(sq)
    	
    What goes wrong? Why?

  5. (4 points)

    Consider the following:

            can = Canvas(200,150)
            
            rect = Rectangle()
            rect.setWidth(50)
            rect.setHeight(75)
            rect.moveTo(25,25)
            
            rect = Rectangle()
            rect.setWidth(100)
            rect.setHeight(25)
            
            can.add(rect)
            can.add(rect)
            can.refresh()
    	
    Only one rectangle appears? Why? How would you get two different rectangles to show up? (There's several ways to fix this.)


Extra Credit

  1. (2 points)

    The following code executes, but doesn't display anything. What's wrong?

            can = Canvas()
            g = Group()
            sq = Square()
            cir = Circle()
            g.add(sq)
            g.add(cir)
            can.refresh()
          


Michael Goldwasser
CSCI 150, Fall 2005
Last modified: Wednesday, 07 September 2005
Course Home | Homework | Lab Hours | Programming | Schedule & Lecture Notes | Submit