Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
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.
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.
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 definedWhat did you do wrong? How do you fix it?
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.
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.
After importing the library you enter
can = Canvas(200,150) sq = Square() Canvas.add(sq)What goes wrong? Why?
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.)
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()