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.
In PA02 you created a border by writing some loops that would draw lines one pixel at a time.
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,10,100)
>>> addLine(pic,10,10,200,10)
>>> addLine(pic,10,100,200,100)
>>> addLine(pic,200,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.
In the spirit of the upcoming Missouri Valley Conference basketball tournament NEXT week, 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.
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.
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
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!)