CSI Lab 07 - Snow Day Version

Tuesday, February 26th

Objectives:


Introduction

This lab is based on some of the material from chapter 5 - in particular, section 5.4

If you have not done so, you may want to read this material before proceeding.

I present this lab as though it were a lab.  HOWEVER, you don't really have to do it like a lab and you don't need to get signatures.  Work through the lab just like it was a a lab, but then submit it like it was a programming assignment.  See the final instructions at the bottom for how "submission" will work.


Activity A : Exploring Graphics Methods

JES contains just a few simple methods that can be used to add graphics and text onto Picture objects.  Let's see how these work.

If you haven't already done so, make sure you have a copy of the "blank" canvas in your mediasources folder (7inX95in.jpg). 

Type the following commands in the interactions pane:

>>> setMediaPath()
>>> pic = makePicture("7inX95in.jpg")
>>> show(pic)
>>> addLine(pic,10,10,200,100)
>>> repaint(pic)
What do you observe happens?

 

In addition to addLine() there are several other methods that you can use with a Picture

Play with each of these and see how they are used.


Activity B : Using Graphics Methods, pt 1

In the spirit of the upcoming Missouri Valley Conference basketball tournament, we want to use the methods you played with in Activity A to write a method that is part of the Picture class and which adds a simple "stick figure" Panther fan to a picture.

In the programming pane of JES:

[SIG1]  Demonstrate this method for a TA. By typing:

>>> pic = makePicture("7inX95in.jpg")
>>> drawPantherFan(pic)
>>> repaint(pic)

 

[SIG2]  As I have said numerous times, since this method takes in a picture as a parameter it is available to any instance of the Picture class.  Repeat the three  lines of code listed above, except load a different picture in the first step (for example, pull up the old mascot photo).  Demonstrate this for a TA.


Activity C : Using Graphics Methods, pt 2

The method that you wrote in Activity B makes it really easy to draw a single Panther fan.  However, we know that there are literally hundreds of Panther Fans around the state of Iowa.  Suppose we wanted to create a picture that had a group of three Panther Fan in it. 

Would you want to create additional methods called drawPantherFan2() and drawPantherFan3() which drew these additional fans at different spots on your Picture?

Of course not!

For example, the authors of JES didn't create a whole bunch of addLine() methods - one that draws a line from 1,1 to 100,100 and another that draws a line from 1,1 to 200,200 .  Instead, they created an addLine() method that takes in (among other things) four parameters representing the starting  x-coordinate the starting y-coordinate, etc.

Copy your original drawPantherFan() method and rename this copy addPantherFan() (notice that you should leave the original drawPantherFan() alone).  addPantherFan() should take in three coordinates - the picture to draw on (just like before) and an x location and a y location - and draws the panther fan based on that location.

Once you are done with this, write an additional method called addPantherCrowd().  This method should contain a simple "for" loop that produces several Panther fans all in a row by using iterative calls to your new drawPantherFan() method.  Use the value of the loop counter as part of your calculation for where each fan should be located on the screen.

[SIG3]  Demonstrate these modifications for a TA.


Activity D : More Graphics Methods (using Strings)

In addition to what you would normally consider "graphics" JES has the ability to print text (a String) to the graphics of a picture through the use of the addText() method

Modify your addPantherCrowd() method so that it includes the printing of at least two different and appropriate Strings of Text on your picture.

[SIG4]  Demonstrate these modifications for a TA

 


Activity E : BONUS Activity - Adding in your own personal touch

HAVE AT IT.  Use what you have learned to make an even more exciting Panther Fan scene.

[BONUS SIG]  Show this to me when you get done (I want to see what you come up with!)

 


Submitting this week's lab

Since this week's lab is last minute due to the change in schedule due to the weather, and since I am not requiring you to actually be in the lab, and since I don't want to actually collect a couple of signatures...

To get credit for this week's lab you should create a directory called lab7 at the root level of your P: Drive.  Inside of this directory you should create a file called lab7.py which contains the three methods listed above:

When all the methods are working to your liking (and including the bonus activity if appropriate) create a (possibly blank) file called "done" also in your lab7 directory.  I will not grade your activity until that "done" file shows up.