![]() ![]() |
| |||||||||
| This page removed for FERPA compliance | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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.
- Open the new JES folder on your computer.
- Note: There is no installation process for JES.
- To run JES, double-click on the snake icon titled "JES". It may take a (possibly very long) minute for JES to get started.
Installing JES from the CD for Windows Users:
- Insert the software CD.
- Double-click "My Computer" or open it from the "Start" menu and open the CD drive (probably D:) by double-clicking it.
Quite often this isn't necessary with Windows XP as you will be prompted for what you want to do when you insert the CD. Just click the icon that looks like a folder when it asks you.- Double-click on the content folder to open it.
- Double-click on the JES Software folder to open it.
- Double-click on the Windows folder to open it.
For Mac users:
- You will want to use the online version as opposed to the book version. The online version is REMOVED up to date.
If you have problems, contact your TA or post your problem to the Lab Questions REMOVED.
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.
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? (REMOVEDnux, 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. # #REMOVEDne 1: #REMOVEDne 2: #REMOVEDne 3: #REMOVEDne 4: #REMOVEDne 5: #REMOVEDne 6: #REMOVEDne 7: #REMOVEDne 8: #REMOVEDne 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:
- Insert the CD, and then browse the folders. Locate the folder labeled "mediasources".
- Click on the Mediasources folder to select it, and then copy it by selecting Edit -> Copy.
- Now, locate the JES folder on your computer. Hopefully you remember where you put it from the first part of this lab.
- Paste the MediaSources folder into the JES directory by selecting Edit->Paste.
- To make this program work, we need to know the entire path name of the file waikiki.jpg. The path name of a file is like its address in the computer. Each part of the path name gives the computer a smaller, REMOVED defined place to look for that file. Every drive, directory, and folder must be noted in the correct order and format for the computer to locate the file. Replace 'waikiki.jpg' with the full path and filename. If you are unsure how to do this, here's a trick:
- In the bottom portion of JES (where you see the >>> thingy) type this:
...and then press Enter. That will bring up a window that'll let you browse the folders on your computer (it should start out by showing you the contents of the JES folder). Find where you placed MediaSources and then locate waikiki.jpg. Select it and press open. If all went well, you'll notice that the contents of the bottom portion of JES has changed. It now shows the full path of the file you selected surrounded by single-quotes. Copy and paste this and replace the 'waikiki.jpg' in the code with it. If you're using Windows, you may notice that instead of the typical backslash delimiting folder names, there are two backslashes instead. Those are important, so leave them there. We'll talk about why they're there later. pickAFile()
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!
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:
- Copy and paste example1() into the space below the line that says
# Add example2() here:
- Change the name of the function to example2().
- Then replace '..\\JES\\MediaSources\\waikiki.jpg' in your new program with pickAFile(). Your function will now look like this:
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)
- Since we have made a change to our lab2.py file, we need to load again to save the changes to the file.
There is one REMOVED 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 REMOVED line of code to our program.
- At the very end of the function and at the same indentation as the repaint(picture) command we want to add the command writePictureTo().
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.
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 # #REMOVEDne 1: does cool stuff #REMOVEDne 2: does even cooler stuff #REMOVEDne 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.
| Student3129 | Using Microsoft Word |