Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Lab 2 - Intro to JES Summer 2005


Objectives:




Installing JES



If you have not done so already, you need to install JES on your computer.

Downloading JES from the Internet and installing it:

Go here and download the file that corresponds to your computer. Extract it and follow the next step. Copy the folder called "JES" from inside the Windows folder somewhere onto your C: drive.



Installing JES from the CD for Windows Users:



For Mac users:



If you have problems, contact your TA or post your problem to the Lab Questions Page.


After you have JES all set up, open the program by clicking the executable icon with the big JES snake on it. It should be in that main JES folder. A message appears about JES in a new window which you should read and then close. This message is only shown the first time you open JES. Then JES will open a window called JES Settings. Your turn-ins will not be done through JES this semester, so you can skip this step and press cancel. One valuable reference for the JES environment is the Help utility. Click on the Help menu and go to Getting Started with JES. This will provide you with some beginning information about our programming environment. You will need to read it before you complete the lab.



Running a program in JES


Start up JES. Then copy and paste the the Jython code below into a new JES file.

# Simple Picture Example
def example1():
  file = 'waikiki.jpg'
  picture = makePicture(file)
  show(picture)
  for pixel in getPixels(picture):
    redValue = getRed(pixel)
    newColor = makeColor( redValue, 0, 255 - redValue)
    setColor(pixel,newColor)
  repaint(picture)

# Add example2() here:



#Question 1:
#Which operating system are you using? (Linux, Win95/98, WinNT, WinME, MacOSX, etc.)
#
#
#Question 2:
#Explain in English what is happening in each line of example1() and 
#what the words "def", "file", and "picture" mean in it.
#
#Line 1:
#Line 2:
#Line 3:
#Line 4:
#Line 5:
#Line 6:
#Line 7:
#Line 8:
#Line 9:
#
#"def":
#"file":
#"picture":
#Note: we are not looking for text-book definitions of 
#these, but rather how these keywords operate in the above code.


Now you must save and load the file. Click the Load button. A dialogue box will ask you if you would like to save. Click OK, then save the file as lab2.py. The file will then automatically load.

MAKE SURE YOU MAKE THE FILENAME EXACTLY lab2.py! You will lose points if it is off even slightly!

The file waikiki.jpg that we use in example1() is on the CD for this course AND it is in the pack of images and sounds available for download here. This will be referred to as Media Sources.

To retrieve Media Sources from the CD:



Your program should now look somewhat like this:

def example1():  
  file = 'C:\\JES\\MediaSources\\waikiki.jpg'
  picture = makePicture(file)
  show(picture)
  for pixel in getPixels(picture):
    redValue = getRed(pixel)
    newColor = makeColor( redValue, 0, 255 - redValue)
    setColor(pixel,newColor)
  repaint(picture)


or if you're one of those crazy Mac people...

def example1():  
  file = '/Users/Daler Mehndi/JES/MediaSources/waikiki.jpg'
  picture = makePicture(file)
  show(picture)
  for pixel in getPixels(picture):
    redValue = getRed(pixel)
    newColor = makeColor( redValue, 0, 255 - redValue)
    setColor(pixel,newColor)
  repaint(picture)


Side Note: understanding how files and directories work is very important for this class. We make a few assumptions about your prior knowledge in this area. If you are confused, please consult a TA!

Since we have made a change to our lab2.py file, we need to load it into JES before trying to run example1() again. So click on the Load button, and then reply OK to the prompt that pops up. Next, click in the command area. Type example1() at the >>> prompt and hit enter. You should first see a picture of a beach and then it should be replaced by a red and blue picture of that same beach. You have just run your first program in JES!



Writing a Program and Writing a Picture to the Hard Drive



What if we wanted to show a different .jpg file? We would have to change the function to include the entire path name of the new file and then load the new function. We would have to do this every time we wanted to show a new picture. How annoying! Fortunately, there is an easier way to do this. Remember that pickAFile() trick I showed earlier? The function called pickAFile() will let you find the full path to a file on your computer. You can incorporate it into your function.

Here's how:


# Add example2() here:



def example2(): 
  file = pickAFile() 
  picture = makePicture(file)
  show(picture)
  for pixel in getPixels(picture):
    redValue = getRed(pixel)
    newColor = makeColor( redValue, 0, 255 - redValue)
    setColor(pixel,newColor)
  repaint(picture)




There is one more change we want to make. What if we want to see our picture after we quit JES or share our picture with someone else? JES has a way to do this as well. We use the command writePictureTo(). To do this, we will add one more line of code to our program.

writePictureTo() uses two things. First, the picture we want to write out. Second, the location we want to write it to (lets put it in the MediaSources folder). Our command will look something like this:

writePictureTo(picture, 'C:\\JES\\MediaSources\\A_tasteful_picture_of_myself.jpg')


It is VERY important not to forget the .jpg at the end.
Also, remember that if your MediaSources folder is in a different place on your computer,
then the path in the writePictureTo function will be different from shown here.
Here is an example of what our new function should look like.

def example2(): 
  file = pickAFile() 
  picture = makePicture(file)
  show(picture)
  for pixel in getPixels(picture):
    redValue = getRed(pixel)
    newColor = makeColor( redValue, 0, 255 - redValue)
    setColor(pixel,newColor)
  repaint(picture)
  writePictureTo(picture, 'C:\\JES\\MediaSources\\A_tasteful_picture_of_myself.jpg')


Note: For this next step, if you pick a really big picture file, it may take a while for the program to run, so be patient. If you pick a picture that came directly from a digital camera without resizing it with another program, then it could take A Very Long Time.

Next, you can type example2() at the prompt in the command area and hit enter. A File Browser window will appear, allowing you to choose which file you would like to show. Go ahead and pick a different JPEG picture on your computer. If you don't have a picture on your computer that you'd like to use (and turn in), there's plenty of JPEG's in the MediaSources other than waikiki.jpg for your viewing and programming pleasure.

Once again, you will first see the original picture, then the modified picture. As an added benefit you will now have your picture stored on you computer at the location you specified in the writePictureTo command. Find this picture and keep in mind where it is, you will want to use it in the next portion of this lab.



Wait! One last thing!



Below your two functions in the JES program area, add your answers to the questions that you copied and placed there. Each line of your written response needs to start with a # so JES doesn't attempt to run your answers. It should look something like:

# Question 1 
#    answer blah blah blah 
#    blah blah
#
# Question 2 
#
#Line 1: does cool stuff
#Line 2: does even cooler stuff
#Line 3: etc...



Remember, if you are having trouble with any part of the lab, you can post to the Lab Questions page, consult (but not copy) other 1315 students, or ambush a TA.





 
Lab 2 Outline
Introduction to Microsoft Word