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

Spring 2005 Homework 2 Questions

Ask questions about Homework 2 here.



after we write functions for changing each of the 4 pictures(or 3 i should say), how do we put them next to each other on a 795in JPEG so that they become one picture for the mirroring process?
Luckily for you, that's exactly what Monday's (2/7) lecture covers, so be sure you're in class and awake. If you can't achieve either of those or just can't wait, take a look at the lecture slides in the course outline. Gabriel Halley


when i try to getmediapath("7inX95in.jpg"), it says that there is no file in my mediasources folder by that name. how can i fix this because i know there is no picture there, it's supposed to create a JPEG that size for me...

Did you "setMediaPath()" first? Greg Leo

yes, that should have been done in the command area correct?
Correct. Make sure that the *.jpg canvas is in the folder that you path to in setMediaPath(). You should be passing in the mediasources folder...that (blank) picture should be included in the folder pathed to! Amanda Bennett

when we make functions for changing our picture, should we put that before the copying stuff so that it is included in the general function?

It doesn't matter what order your def's are in as long as they're all not indented.

my function works for copying my original pic, but when i add the function for the second pic it says that i have not defined a part of my first function where i set the color to ((getPixel(canvas,targetX,targetY),color)..what could be the problem?
???

It's kind of hard to evaluate what's going wrong here without seeing your full code (please don't post that). First check your variable spellings where you call the function for the 2nd time and after that the best thing you can probably do is visit a TA's office hours or talk to someone in person who's already done this assignment who can trace your code to see what's up.

i have entered the correct functions for my 4 pictures and everything looks right but for some reason it wont let the fourth pic show up?
Are you sure you're repainting it at the end? If you are, then some other sources of the problem could be that you aren't incrementing one of your target variables and it's copying the picture but onto just one pixel so that it doesn't seem like it's doing anything.

Where should we write our functions, such as posterize or grayscale?
In the same .py file that your makeCollage() function is in. It doesn't matter if it comes before or after makeCollage() as long as it's there, but it can't be inside your makeCollage() function.

what does this mean—> "The error java.lang.ArrayIndexOutOfBoundsException has occured"
It means you tried to access a non-existant pixel. This could have been caused for a variety of reasons. For example, you tried to access pixel 0,0 somewhere in your code. Or perhaps the picture you tried to copy to the canvas spilled over the edge and you tried to access a pixel that was beyond the right or bottom edge of 7inX95.jpg

when i mirrored my picture(s), there is a large white space between them because they do not take up exactly half of the height of my canvas...any suggestions?
You could try some of the rescaling code from the slides, but whitespace is perfectly acceptable for this assignment.

How do I name the final and complete collage (in order to post onto the gallery)..I know you use the writePictureTo function, but it doesn't recognize it as a defined variable.
writePictureTo(whatever variable you used for your canvas, getMediaPath("preferably your gtnumber"))
Add that line to the end of your code. Since there'll be a zillion posts to the homework 2 gallery, if your file is named something unique, there isn't a chance that you'll overwrite someone else's submission, which would happen if everyone posted a "myCollage.jpg". Since there's a getMediaPath, then it'll write it to the directory that your images are in.

when Professor Sweat demostrated how to use the setMediaPath and getMediaPath functions, she used the barbara.jpg. the picture i wanted to use for my homework is also a jpg, but its name is Tank.JPG. does the capitalization matters? would others be able to load it when i transfer the picture file to their computers? if it does matter, how can i change it from capitalized to lower case? Thanks a lot.

Zhanxiang Liang gtg807x

Capitalization does matter. You could rename the file to "tank.jpg" but it would just be easier to call getMediaPath("Tank.JPG"). Once you turn in your homework, you need to attach Tank.JPG to your submission so that your TA can use it. When your TA grades, he or she will do setMediaPath to where ever your image is saved on their computer. (if I understand what you're asking)

Blake, you said that capitalization does matter, but no matter what i put into the getMediaPath() function, either Tank.jpg or Tank.JPG, the program runs perfectly and returns the result i wanted without me changing the file name or file type. i have tried the same thing with the canvas. even though it was originally named as "7inX95in.jpg", JES still ran my codes fine with the input of "7inX95in.JPG". well, how is this so and would the same codes run in other computers? i am a bit concern because if the same codes won't run in my TA's computer then i will get a big fat zero. thanks a lot.

Zhanxiang Liang, gtg807x

sorry, forgot to mention this, both of them have the file type of JPG File.

Zhanxiang Liang
I think you and Blake were talking about two different parts of the filename. If I understand correctly, you're asking whether there's any difference b/w ".jpg" and ".JPG". The answer is no, your computer understands both as the same file type. Your TA's computer probably does as well, so no need to worry. If it becomes an issue, I'm sure you can work it out with your TA. Gabriel Halley


After I've written all the code for copying and manipulating my four pictures, how or where should I type the code for mirroring all four of them?
You might want to define a function to mirror the canvas, and make sure that in your main function that mirror is the last picture manipulation that you do. It should look a lot like the other things that you've done to the picture, but now you're just going to mirror the canvas, it has nothing to do with the other picture. Amanda Bennett

I CANNOT FIGURE OUT HOW TO MIRROR MY ENTIRE CANVAS. FIRST IT SAID OUT OF BOUNDS, I FIXED THAT, BUT NOW ONLY THE ORIGINAL 4 PICS SHOW UP AND NOT THE MIRRORED IMAGES EVEN THOUGH MY MIRROR FUNCTION IS IN THERE–> I PUT THIS LAST RIGHT BEFORE SHOW AND RETURN.
It's hard to tell you what's going on without seeing your code. Check and make sure that your targetX and targetY are doing the correct thing. Make sure that you are copying below a mirrorpoint line too. If you can't trace through your code, IM a TA or take it to office hours or breakout and they will help you out. Amanda Bennett

do any TA'S have office hours today thursday the 10th, and when, cause I need help with my hw2
TA Contact Information has a nice chart with all the TAs office hours by day and time. Greg Leo



I do not fully understand when it indicates "mirror the ENTIRE canvas". The canvas is now 7inX9.5in... does that mean after I "mirror" the canvas across an imaginary horizontal line, then the new canvas should be 7in. X 19in.??? Or was I supposed to mirror the images across a line that is half the size of the canvas?

When you mirror the image, the resultant image will be the same size as the original. You will mirror across the center of the picture (either getHeight(pict)/2 or getWidth(pict)/2 or if you are daring, try mirroring along one of the diagonals) Kelly Lyons

I'm using the same picture for my entire collage, but once I pass a function (such as posterize or lineDraw) on the original picture, the next picture maintains that manipulation and adds on the next one. (I have a posterized line pic). This happens in the order that the pictures are listed. Does anyone know what's going on here???
yup. you are using the same variable for the picture each time you manipulate it. Try calling the picture you want to use one variable name, and each time you pass a function to it, name the picture something else. You will probably end up with 4 different picture variables, but that is okay. It will eliminate your problem. Amanda Bennett

both rotating examples in class and the book deal with rotatiing an image 90 degrees, can I have a little insight into how to rotate it once more so that it is upside down...thanks
well, you could rotate it the first time with that code, and then rotate once more with the same code (that would rotate 180 degrees) or you can figure out how you can change the code so that you will be copying pixels from the top left corner to the bottom right corner, etc, Amanda Bennett


Thank you so much!!! That fixed it! ;)

I've finally managed to get the canvas with the pictures on it to show up. However, for some reason the pictures are distorted into very long thin lines with giant white spaces inbetween. Do you have any idea what I might have done and if so, how do i fix it?
A long thin line representing your picture is generally becuase one of your loops didn't increment correctly. This is generally caused by forgetting to increment the targetX or targetY variable at the end of the loop. If the line is vertical, then this means your targetX is not incrementing because for every row it only copied one pixel. It the line is horizonal, this means that your loops only excecuted once for the y loop and that your targetY is not correctly incrementing. Kelly Lyons


How do I save my collage and attach it to turn in?
Use the writePictureTo function that you learned in Lab2 to save it to your computer. And then attach the copy you saved to your turn in. Kelly Lyons

Do we have to use the setMediaPath() and getMediaPath() functions? or can we go about doing the assignment using previous methods if we're more comfortable with that?
You MUST use the getMediaPath command. Since your function is going to internally create at least two pictures, and you do not know those pictures will be on your TAs computer, by using getMediaPath you don't have to worry about that becuase the TA will setMediaPath to wherever the pictures are. If you were to type an explicit path, then your TA would not be able to run your code. Also, if you used pickAFile() then the function would not run without the additional action of finding and getting the correct file. getMediaPath and setMediaPath solve this problem, and all you and your TA to use the same code on two different computers and still be able to run the function without having to pick the file. Kelly Lyons

when i try to load my recipe it says that there is a spacing area with my first targetY=1, even tho i indented it exactly like the book shows. what could my problem be?
Try looking at the indention of the lines surrounding the targetY=1 line. Sometimes JES will point you to the wrong line when telling you about an error. Kelly Lyons


When we mirror our canvas, where do we put in the function to mirror it? Does it go at the end after we've showed and returned the canvas?
You can put the function to mirror the canvas either after or before your main function. Just make sure that it isn't inside your main function. Then you will call the mirror function from within your main function. You should probably do this right before your show and return. Kelly Lyons


I'm having problems saving my final canvas. I used the writePictureTo(flower1.jpg,r"c:flower2.jpg). flower 1 being the original picture that i used to make the collage, and flower 2 the new name. is this correct?
Almost, but not quite. writePictureTo takes in the picture you want to save, and the path to save it to. Instead of "flower1.jpg" (The original), you need to have the variable that stores the collage (Because you don't want to write the original picture again). Then, "flower2" is just where you want to save the picture to. If you want it to be on the C: drive (Named how you have it there), you would have: r"C:\flower2.jpg" Alvin Yates

i asked the question about indentation 3 questions up, and i have tried many times to correct the whole recipe as far as indenting goes, and it still comes up the same line every time. i don't know what is wrong.
What exactly is the error that comes up? Does it come up when you try to load the program? Check through your code again to make sure every loop is indented correctly, and if you still can't find the problem, e-mail your TA or IM one or go to someone's office hours on monday for help. Amanda Bennett

i wrote my entire program and i'm pretty sure it will work, but when i try to test it, none of my pictures are in JES, but they are in my computer...is there a reason they are not showing up in JES?
You need to setMediaPath() to your mediasources folder. Amanda Bennett

My original collage is at the bottom of the canvas and I used the recipe to mirror it horizontally from the bottom up, but I get a white space between them.
White space is fine for this assignment. You can fix that by changing where the line is that you want to mirror across. trace through your code and see if you can figure out how to do that. Amanda Bennett

i am only able to get 2 pictures onto my canvas. How can I make my picture smaller so it will fit on the canvas?
Scale your pictures down. There are examples in the book on how to do this. Amanda Bennett



I started out fine, and when I loaded my canvas, my pictures all came back the same, with one blank spot. Now i have one picture that shows up, with something mirrored(but still right side up) and cropped, and nothing lese is showing up.
I don't quite understand your question, but it sounds to me like you are having copying issues. Make sure you keep your targetX and TargetY moving with the source pixels. You don't need to mirror anything until the very end. Amanda Bennett

When I use setMediaPath, I cannot find the Eiffel.jpg or the 7inx9in.jpg I need to use for this recipe. Only a few of the images I have in my MediaSources show up. What can I do to fix this?

hey, i asked before about none of my pictures are in JES, but they are in my computer...i had already done the setmediapath thing, but the pictures just do not show up for some reason...even if i click on my documents and my pictures, none of my pictures are there at all, but they are all on my computer...any suggestions?
Make sure that you put all of the pictures that you want to use in the same file together (my suggestion is the mediaSources folder). JES will look in the folder that you set as the media path when you call getMediaPath() in your recipes. You will not see the pictures when you setMediaPath(), you will just go to the folder that all of the pictures are in. Amanda Bennett


i just posetd right before this one and when i try to open the pictures just normally in JES, they were there, but when i setmediapath, they are not there for some reason...
What do you mean when you try to open the pictures normally in JES? Set the mediaPath to the folder where your pictures are and then use getMediaPath() to access them. Amanda Bennett

i am trying to scale my picture down, but the function is saying: The error java.lang.ArrayIndexOutOfBoundsException has occured. What does that mean? What am I doing wrong?
That means you are going trying to access a pixel that isn't there. Check out your sourceX and sourceY and make sure that they aren't going off the end of the picture, and check the targetX and targetY and make sure that they are on your canvas. Amanda Bennett

I can't mirror my collage. I got the 4 pictures, but I can't figure out how to mirror the entire canvas. I have to mirror funtion and call it right before show and return. Do I need to save the 4 pictures to something before mirroring it? What am I doing wrong?
You will be copying the 4 pictures to the canvas and modifying them as you copy. You do not need to save them at all. There are a lot of good examples in the book and in the class notes. Greg Leo


I can't get my 4th picture to move to the center of the canvas. The error java.lang.ArrayIndexOutOfBoundsException pops up. How do I get it to move?
Try throwing some print statements into your code to see where the error is occurring. You may also want to put a repaint() function within one of the for loops so you can watch as the code copies the picture. Might take a while, but you will get a good idea what is going on. Greg Leo

when i do the write picture to at the end of the recipe, do i do writepictureto(canvas, r"C....) or writepictureto(picture, r"C...) or writepictureto(butterflypic, r"C...)? butterlypic is the name of my picture that i am manipulating
Save the canvas. Greg Leo

in my mirror recipe, I was following the examples in the book and the slides, but the keyword "int" won't turn red or do anything. and Jes keeps saying that it isn't legal jython. I've tried re-typing it, or pushing return to try to make it turn red, but nothing is happening. Ian Williams
int is a function that takes in any number and returns just the integer part of it. For example int(1.6)-> 1. Make sure you are passing a number to the int() function. Greg Leo

i am having trouble writing my picture to my harddrive for some reason...i have writePictureTo(picture, r"C:\Documents and Settings....mypicture.jpg") but when i do that, it does not sendthe picture...i have that indented once from the very left, sotaht it is part of my createCollage recipe...is that right?

i cant save my collage....i have writePictureTo(canvas,r"C:gtg113y.jpg") but it won't save it, i have also tried doing it w/ getMediaPath(r"C:gtg113y.jpg") and it wont save and i've written the complete path (JES.4\\JES\\MediaSources\\MediaSources\\etc)and it won't save, what is wrong!

i'm having the same problem as the above people with saving the collage. I've tried it both ways as well (typing out the path, and trying the getMediaPath("gtg004a") method blake suggested.) But it seems as though nothing is happening, even though i'm nto getting any error message. Are we just missing a step? I have mine on teh very last line of my code, indented one in as well. Ian Williams



I'm having the exact same problem! I've tried saving it about 10 different ways and none of them work! How do I turn in my work if I can't save it? Jennifer Nichols

Make sure that you are not doing writePictureTo() after you do return. Once the return statement excecutes, the function ends and nothing after it is executed. Try doing the writePictureTo either in the command area, or before the return statement. Kelly Lyons

this site=bad

bill billy bill bob jones

i hate thy site of wich u speak


keely lyons wanna hook up (lol)



Links to this Page