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


This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2004 Homework 2 Questions

Ask questions about your collages here!

When turning my second picture to grayscale, i typed, px=getPixel(bill2,sourceX,sourceY)[Enter] cx=getPixel(canvas,targetX,targetY)[Enter]setColor(cx,getColor(px)).... Jes says there's an error becuase it's out of bounds, but it says the error is in the cx=getPixel...line??!!


Do we make the fuction call hw2() or makeCollage()...the directions for hw 2 seems to give a mix signal.
makeCollage(), it's fixed. Student56

i can get one part of my function to work, but when i try to scale down the image so that it lies on top of the original copy(only smaller) i get this message:

I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 22 of C:\...

When you get that error, it means that your X or Y has gone beyond the edge of the picture. For example, if you're referencing X position 513 and the width of the picture is only 512, you'll get this error. You'll have to trace your code and figure out where you're going too far. Is the line referencing your source or target? If the target, there's an easy solution – use a bigger canvas! Mark Guzdial


I am trying to use the WritePictureTo function, but it isn't working. There aren't any error messages, but when I look for my collage on my computer, it isn't there.



What exactly are you typing? Did you look in the media folder and in the JES folder – those are the two places where writePictureTo might write the picture, if you don't give it a complete path. Mark Guzdial


I've been trying to submit HW2 and the program doesn't ever actually submit.. the hourglass just keeps spinning..

I tried to write my picture to a specific folder, but it isn't working either. I tried both:
writePictureTo(canvas,"rC:\Documents and Settings\Owner\My Documents\classes\cs1315\JES.4\JES\MediaSources\canvas1.jpg")
and
writePictureTo(canvas,"C:\Documents and Settings\Owner\My Documents\classes\cs1315\JES.4\JES\MediaSources\canvas1.jpg")

    the 'r' has to be outside of the quotation marks. -Student1680

Have you returned your canvas in the program? And are you sure that your final collage is still being refered to as "canvas"? Student117

I typed writePictureTo(canvas,r"C:\Documents and Settings\Owner\My Documents\JES\canvas.jpg"). I also have return(canvas) in my program, and I did a search for canvas on my computer, and it isn't anywhere.



Make sure that you are writing the picture before you return then, because once you return, the program is finished, so it's probably not even doing that last step. And once you get it to work, remember to take out the complete path name, because it needs to work on everyone's computer! Student117

I tried to create a canvas by typing canvasf=getMediaPath("7inX95in.jpg") and all it does is say that it can't find a file with that name on it under C://JES. It appears that it wants to look for an existing picture, but I need it to create a mediapath for my canvas. What am I doing wrong?

Is our collage required to fill the entire blank canvas? REMOVED

It is an existing picture. It is in your mediasources folder. Make sure that when you "set the media path" you point it toward the MediaSources folder not JES. Lauren Walker

Nope, there can be some white space. Lauren Walker

how do you make a function work inside a function?

The rotate function given in the book only works for a blank canvas... How do I make a rotate function to work inside of my collage function so that my rotated picture will be w/ the rest of the pictures?? Every function I make just places the rotated picture on a different blank canvas.

If I want to mirror the resulting picture, where do i put the mirror function in relation to everything else.

Hey, do we have to do scaling, rotating, and cropping...or only one of the them???

3. You have a choice between like 6 options of this to do: scaling, cropping, rotating, shifting/altering color, or making it darker/lighter. So yes, those are three different options. 2. You want to mirror after you have made all your other additions to the canvas. 1. And I'm not sure what you mean about the rotating? You can scale the picture if you want it to fill the canvas... Student117

Someone tell me if I am wrong: first of all, must we initially copy the original pic to the canvas, then write the makeCollage() function, and then the function to mirror the whole thing?

The makeCollage() function should do most everything. Make sure that your TA just has to run the makeCollage() function to produce your collage. Maybe you should copy the pic to the canvas IN your makeCollage() function? Just a thought....Lauren Walker

A function doesn't really "work" inside another function, it is called by the function. Check out page 227 for an example. Lauren Walker

You can rotate a pic on an existing canvas...look and see how many times you are creating/calling a canvas. Lauren Walker

Don't forget that we give you a complete, working collage recipe on page 96 in the book. This works, but doesn't (a) take a single image and make four copies (it only does a couple copies) and (b) doesn't mirror. But other than that, it works. Start from there! Mark Guzdial


we don't have to upload our pictures to the gallery, correct? it is just optional?

From the assignment: "Please share your results by uploading the image to the Fall 2004 HW2 Collages gallery. (This isn't a requirement, but we'd love to see them!)" So it is optional but it may break our hearts if you don't.Bill Leahy

i can't figure out how to mirror the whole canvas. it keeps saying i am out of the bounds- do we still mirror with the same size canvas, or can we use the bigger one?

Yes, you mirror with the same size canvas. Remember there is a lower bound (1) and an upper bound (getWidth or getHeight). You can't go outside those bounds or you will get an error.Bil Leahy

Pictures can overlap right? They don't all have to show completely?
Yes.Bill Leahy

Is it ok to leave show(canvas) inside the function, or do we need to get rid of that for the TAs grading it?

You should do what it says in the asignment. this asignment says something to the effect of your TA should tpe makeCollage() and see a collage generated. This means that not only is it ok to leave show(canvas) in your function, you are supposed to leave it in. Note, this is not always the case. Side effects (show, writePictureTo, print, etc) are good in some situations and bad in others, so you should always default to what the asignment says. Student1594


Ok, so the collage example on p.96 uses functions such as clearBlue(picture), decreaseRed(picture), etc. To use one of those functions, will we already have to have a clearBlue function previously defined in the program area?, or does the code following each take care of it?

Any function that you plan to use, other than those defined in JES, you need to define in the program area. clearBlue, and decreaseRed are not defined in JES, so you will need to define them yourself. I'm not sure what you mean about the code following it, but if you're refering to where in the command area you define your functions, I don't beleive it matters which function you define first, but you can always try it and see. Student1594

for the altering of colors, are we allowed to use negatives and grayScale?
Yes. That is considered a color alteration. However, it is NOT scaling,cropping,rotating or mirroring just to be clear. Student1594

I don't really understand the directions in the assignment. I'm not sure how and where we are supposed to turn in the original image and resulting image. How can we make sure that the ta can access the original image? Also, do we need to attach the resulting image into attached media files? I haven't been able to get the writePictureTo function to work.
You are going to be turning in your asignment through JES. On the asigment turning portion of JES, there's an area where you can attach other files to your submission. Here is where you attach your original and resultant image. As for writePictureTo, how are you calling it? Are you writing the write picture file? Are you specifying an entire path (i.e r"C\.... and not just "collage.jpg)? If you do not speficy the whole path, look for your picture in the JES folder. It may be there. If that did not help, find a TA at office hours on Monday (I'm there 11-12 in the CoC) and they should be able to help you with REMOVED specific problems. Student1594

Do we leave the writePictureTo function in the code that we turn into the ta?
No. This will most likely cause your program to crash when your TA runs it. If you're writing it to C\mypictures and your TA does not have such a folder at the same place on his computer, JES will error. So for this asignment, do take that out before turnin. As a note, with your new knowledge of getMediaPath() you could get writePictureTo to not fail no matter which computer you run it on, but that's a separate issue, and you should leave writePictureTo() out of your turned in code. Student1594

I used the writePictureTo function after I did return(canvas), and it still isn't working
THis is becuase once you type return, the function will return and do no REMOVED. Return to the computer means exit the program and leave whatever I'm returning available, so your writePictureTo function is never being run. Try putting it before your return call. Return should in almost all cases be the last line on your function. Student1594

can we use multiple pictures or only one orriginal image?
You can as many multiple images as you would like, however one image must show up 4 times in 4 different ways, 1 of which must be either scaling,cropping,or rotating. Student1594

If my 4 pictures take up my entire canvas, do i need to resize them all do be able to mirror the canvas? is there a way to scale them all down together??

There are lots of ways to do this: You could resize the basic picture before you even start or you can do it as part of the construction of the collage. On pages 104-106 of the text there are sample programs that rescale pictures. Let us know if you need REMOVED info.Bill Leahy

My code looks correct but everytime i try to run it, i get a message:"Picture, filename C:\JES\MediaSources\Bunny.jpg height 107 width 94
Picture, filename C:\JES\MediaSources\7inX95in.jpg height 684 width 504" It's giving me my files height and width and i don't know why?? Obviously my picture is not big so i don't thing it is overlapping or anything like that.

Are you printing the picture? i.e. print pic That might do that. Email me your code.Student1821

I was able to get the homework done, and everything works fine, however I am unable to attach the image to the webpage. I enter my gtg number and password, and it will not accept me. I know what the password would be if I set it up, so what is the problem here? Thanks

Use username:attach password:carmenBill Leahy

This is also the second question on the FAQ page. Mark Guzdial


Someone has already posted this problem, but with no answer. I've tried submitting mine but it never finishes, the hour glass just keeps spinning. I tried submitting twice Thursday, and I let it sit there for over an hour the second time. When I tried today it is still not working correctly.
You are trying to submit your HW2 asignment through JES and it's not working? I can't find the original post you refer to so this is what I'm assuming your problem is. There are many reasons this could be happening. Is your internet connection fully functional (i.e. not going in and out) Have you previously been able to submit through JES before? You should let your TA know directly that you are having this problem so that he may be able to check and make sure there isn't a problem in the turnin system. Also, if you are still not able to submit through JES, look up the instructions from Lab1 on how to attach to the Coweb, and submit that way. Student1594

Ha, well I suppose I missed that. Thanks.

Every time I try to run my program, it gets hung up for the 3rd pic. The 1st is the original, 2nd a rotation, & the 3rd alters color. The first line of code for the 3rd pic is simply decreaseRed(flower1). This is the line it highlights for an error & tells me that an attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer. I don't get it. I have the actual code to decrease the red after the makeCollage function.

Has anyone else had trouble submitting? Anonymous poster, please email your TA and/or your Instructor so that your name can be checked in the turnin pages (e.g., to make sure that JES is trying to do the right thing with it.
How is your decreaseRed defined? My guess is that it's defined with NO input, but you're handing it a picture as input, so that's a mismatch between types for the parameter. Mark Guzdial


If i already did the writeToPicture function on my college, but I need to resize the pictures, how can I get a blank 7X95 inch canvas?

The blank 7X95 inch canvas is a .jpg file in media sources. You can make as many pictures from it as you want.Bill Leahy

well, i did the writeToPicture function to the 7X95inch canvas file, therefore I no longer get the blank canvas but now I see my collage that i need to fix.

Never do that! You will need to get a new blank 7X95inch file from either your CD or you can re-download the media tools. In general, you should save files with different names than files you might want to keep.Bill Leahy

i am only using one picture for my collage. i would like to scale it 4 times, in four regions of the canvas. i can copy it four times, unscaled, to the regions i would like - but i cannot copy all of the scaled images four times. it will scale the image to the top right of the canvas, but doesn't scale or copy the image to the top left, bottom right, and bottom left regions of the canvas. do i need to distinguish the new canvas with the scaled image 1 from the original canvas defined at the beginning of the code?

n/m,i figure it out (in reply to above post about scaling)

Every time I run the program, the end result is a picture that I cannot see the entirety of. It looks as though the rest is below the screen. REMOVEDly, something is wrong, but I don't get what. If that doesn't make sense, it's like I could see the rest if I were able to scroll down the page.

Generally this means that you have the kind of error where you are drawing off of the picture. One thing to try is to pretend you are the computer and go through enough of your code writing down what each variable contains as the code executes. You may also want to get a hold of your TA or instructor and email or show them your codeBill Leahy

does flipping (vs. rotating) fulfill the scaling, cropping, rotating requirement?
I suppose flipping can be considered a sort of rotationBill Leahy

Even though my mediasources is in the JES folder, JES says it couldn't find the image in the JES folder. HOw can this be?
Well, for starters, an image file is in some folder. If the image file is in the media sources folder then it's not in the JES folder. JES is only going to look in the folder specified. It won't search through folders withing that folder.Bill Leahy

will our TA do setMediaPath() before running our program, so that all we need in our program is getMediaPath() (NOT setMediaPath())? because I assume we cannot set our own path since our TAs path will be different on their computer.
Yes, absolutely. That is why it's provided.Bill Leahy

I have my pictures in a column in the canvas and I mirrored them over to the middle of the canvas. Then I mirrored the middle column to the right side. The instructions say to mirror the ENTIRE canvas. Does this fulfill the requirement since I mirror all the images twice??
You need to mirror the entire canvasBill Leahy

Our code should take 3 previously altered images, and the original picture, and make them into a collage, right? OR...is it suppoded to alter the imgames, AND put them into the collage? Thanks
Your code is supposed to take a picture, and alter the image, place the altered forms (4 total, one of which CAN be the original) on the 7inX95in.jpg canvas. The images must be altered in your code, NOT previously altered!! Student1594

When I run my program, an error comes up saying that "7inX95in.jpg" isnt a valid picture file even after I have made it.

You shouldn't be making 7inx95in.jpg – it's in your mediasources, from the CD. We care about the end result – alter them in the collage or before. Mark Guzdial


i have been trying to submit my hw2 for the past 1 min. and all it says is "submitting assignment..." is it supposed to take so long?

15 min. sorry
No, it shouldn't take 15 minutes. If you are connected to the internet and you have been able to submit before you should email your TA and tell them of your problem. You can also use the alternate turnin method described in Lab 1.Bill Leahy

I am sorry it's kind of a last minute question: How do we combine different functions into one function called makeCollage()?

Start by looking at the example on pages 99-101 of your textbook.Bill Leahy

I am trying to Write yy canvas to the mediasources folder, and I have the path laid out exaclty, but I keep getting error messages. What could I be doing wrong?

What's the error message? Student56

I figured it out actully, but now I have another ?...Why is it only mirroring half of my canvas? Thanks
    When your program is half done with copying the pixels from one half to the other, they're exact mirror images of each other. The pixels that you were expecting to be written from the 2nd half onto the first half have been overwritten. One way to get around this is to create a separate canvas to copy your collage to. -Student1680

Hokay... so... I am writing this massive collage function in the book practically word for word into JES (except, of course, with my file name and my modifications to the original picture).

Yet when I go to load all of this, I get an error on the line where return(canvas) is, saying it is illegal Jython. It's the last line of my makeCollage() function, before all of the mumbo jumbo about the specific functions within the collage itself. I've tried placing this at the end of everything, but to no avail. Any idea what's going on?

    It's extremely hard to say what's wrong with your code without actually seeing it. But when it says that your code is illegal Jython the culprits usually are:
  • Indention errors
  • Missing a closing parenthesis somewhere
  • Missing a colon somewhere
Double check the code that you copied from the book. -Student1680

i'm having a problem with finicky code... it says there is a "spacing error" in one of the lines - my 'increment' line where I add 0.5 to the value of the thingy for the for loop - it works fine in my first function, the one that copies the picture to the canvas, but it has the same spacing on the second function (the one to scale it up and copy it again) and it is saying there is an error. I try moving it all around and it still says the same thing... i'm confused! email me gtg894w thanks
    Sometimes when JES says there's a spacing error, the actual error is generated in the line directly before where it says the error is. -Student1680

hi. i put in the log in name and password to upload my picture, but it isn't showing up...?
What log in name did you use? What is the name of the file you tried to upload? Your filename shouldn't contain any spaces!Bill Leahy

When I try to submit, the process never ends...the hourglass has been turning for 20 minutes now.
Try submitting it by uploading it directly to the Coweb. Student1594

how do i start the code to mirror the entire images. i have all four pics altered already i just dont know how to start the code, what is the collage called in the function for mirroring
Your four altered pictures should be placed on the 7inX95in.jpg canvas in your code. So whatever you call this in your code, (it's called canvas in all the book examples), this is what you want to mirror. Look in the book for two examples of code that mirrors a canvas, and at the end of your makeCollage() function, add a call to your mirror canvas function using your collage. Student1594


how do i direct the program towards mediasources and not jes?|

what time is the homework due
and is there someone you cant tell me how to see if my program works
how do you correctly mirror this stuff? i'm having trouble specifying where to mirror it (i'm trying to do it vertically). i put in what i thought seemed to be a code that worked, using the Temple example in the book...but no such luck when i tried to apply it to my collage.
You should be mirroring at the end of the code, after all of your other alterations to the collage have been made. Student1594


i am trying to rotate for one of my variations in the picture and i put rotateBrideSideways(bride) into the program under the last line of the second picture and it says An attempt was made to call a function with a parameter of an invalid type. this means that you did something such as trying to pass a string to a method that is expecting an integer. what do i do?

i'm having trouble rotating/scaling. how do you change the function to make it work for a collage?

That is dependant on how you've written your code, and is difficult to answer without seeing all of the code Student1594


you need to setMediaPath() in the command area.
hwk is due at 7:00
email your ta or every ta/post questions here
are you calling the mirroring function in your program?
Lauren Walker

Ok, i keep having the same error occur over and over again with this particular part of the recipe:

1. def createCollage():
2. Calo d'ascolto=makePicture(getMediaPath("Edoardo Belinci, Calo 3. d'ascolto.jpg"))
4. print Calo d'ascolto
5. Creation=makePicture(getMediaPath("Bev Hodson, Creation.jpg"))
6. print Creation
7. canvas=makePicture(getMediaPath("640x480.jpg"))
8. print canvas
9. #First picture, at left edge
10. targetX=1
11. for sourceX in range(1,getWidth(Calo d'ascolto)):
12. targetY=getHeight(canvas)-getHeight(Calo d'ascolto)-5
13. for sourceY in range(1,getHeight(Calo d'ascolto)):
14. px=getPixel(Calo d'ascolto,sourceX,sourceY)
15. cx=getPixel(canvas,targetX,targetY)
16. setColor(cx,getColor(px))
17. targetY=targetY + 1
18. targetX=targetX + 1

and in the command are, when i load the recipe, it says, ">>> There was a spacing error in the program.
It might be from a previous line, but I think the error is in line 11"

What is going on here that i can't seem to understand?

every time i try to load my function it says i am using a jython keyword as a function? What am I doing wrong?

Try using one word as the variable for your picture. The program doesn't recognize spaces as part of a name. I would suggest just naming your variable picture or something else that is one word. Do this where you first choose your picture and replace all instances of Calo d'ascolto with your new (ONE WORD) variable Student1919



Link to this Page