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 PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Homework 2 Questions- Spring 2008

Homework 2 questions? Post them here.


There is no Homework 2 up on T-Square yet.
There should be. You only need the T-square part to submit though, all the instructions are on the Coweb. Thanks! Brittany Duncan

May I use the French flag?
That is fine. Thanks! Brittany Duncan

ok so i was thinking of doing a Flag() function for Italy and then putting something like makeGreen, makeWhite, makeRed under it and then defining those as separate functions. when you say we can't have input parameters, you mean we can't put something like makeGreen(pic) right? we just have to say makeGreen(). also, I'm wondering how to copy everything. Like I know the copy function, but say I put it under makeRed(). so it'll copy that particular red picture onto a canvas, but how do I copy the other two to the same canvas if they're in different functions? do i have to make it all into one function, if so, how?
First, make sure that your function is "flag()". Capitalization counts. Second, try to be a bit more creative with your functions. For instance, instead of makeWhite, why not use negative() on a dark picture? Finally, you can have input parameters in helper functions, just not in the flag() function. Let me know if you have anymore questions or need more direction. Thanks! Brittany Duncan

Can I use the Irish flag?
Sure. Thanks! Brittany Duncan

Definitely, can we use the Irish flag? Why was the best flag left out?
It was unintentional I assure you. I chose random flags and figured people would ask for any others that they wanted. Thanks! Brittany Duncan

Could I use France's flag?
I believe that is the same as the French flag, so yes. ;-) (Please read other people's questions before posting your own.) Thanks! Brittany Duncan

How about the Iran flag?
I'm hesitant to approve that because I don't know how you would put the image in the center. E-mail me if you want to discuss this further. Thanks! Brittany Duncan

Sweden's flag?
Sure. ANY flag that is geometrically similar to the ones that we have posted (tricolor, Scandinavian crosses, etc.) are fine. If only the colors are different, you don't need to ask about those. And if you want to use a flag that has an emblem in it, you can just leave that out. If you do that, the Mexican and Italian flags are the same. Colin Potts

I'm using Italy's flag and 3 functions: one to saturate green, one to make a bright BW, and one to desaturate green&blue. Are these functions too similar? Or is this OK?
That should be fine. Thanks! Brittany Duncan

Russia's flag?
Already answered above. Colin Potts

Is the Columbian flag okay to do?
Please read the statement above by Brittany. 'ANY flag that is geometrically similar to the ones posted...is fine'. Chris Phillips

Why does writePictureTo not work if it follows the return command?
Nothing works after the return command. Colin Potts

On the homework is says that we can only use each modification once, so does that mean we can't modify the colors of more than one picture?
We would like you to be a little more creative than simply increasing or decreasing colors for all the pictures. Thanks! Brittany Duncan

how in the world are we supposed to make more than one function out of this? if we have three different transformations, how do we copy them all to the same canvas if they're not all in the same function?
I detailed that in the instructions. You could use a separate copy function for example. Thanks! Brittany Duncan

Is the scottish flag ok? I just want to make sure because it is geometrically different, but I found a way to work around the triangles.
If you have figured out how to do it, it will be neat. Thanks! Brittany Duncan

Do we have to use makeEmptyPicture? What if I want to copy two pictures on top of a third one? I have two pictures that are 133 px across, and I want to copy them on the left and right sides of a third picture that's 400 px across.
If you want to use a larger underlying picture as your canvas, that is fine. Colin Potts

Are we supposed to write our own transformation functions or do we have to use established ones like grayscale? I figure it's safer to ask than assume...
Either is fine, so long as they conform to the grading criteria, and don't do the same thing. Chris Phillips

ok, so my flag function is working but when I type in show(flag()) it gives me the error:
show(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

but it still shows my flag exactly as it should be. I looked at the previous semesters questions and the solution was to make sure "return picture" is at the end of the code but that gives me another error:
The error was:picture
Name not found globally.
A local or global name could not be found. You need to define the function or variable before you try to use it in any way.

and it still shows my flag. Help! Thanks!
The thing that you return using the return command has to be the picture representing the flag, and JES only knows what this is if you give it the correct name. I am guessing that you said something like picture=makeEmptyPicture(....) earlier in your code, but did not use the name "picture". Colin Potts

Ok that works but now its showing me my flag and a blank canvas with no funky errors. Should I leave it alone or is this extra blank canvas going to deduct from my final score?
If you put print/show/repaint statements in your code to debug your program as you go along (a really good idea, by the way), you should take them out before submitting. Think of them like scaffolding that builders take down once a building is complete. Colin Potts

Can I do the Zimbabwean flag?
Sure! I would not try to include the symbol (dove? and what is it sitting on?). Colin Potts
I'd be wary of picking that one, however. Note how the edge of the striping is diagonal. How are you going to copy things over in a diagonal fashion like that? It can be done...but it might be more then you want to do for the assignment. Chris Phillips

can we use pickAFile for the writePictureTo part?
No. Colin Potts
Sorry. I may have misunderstood your question. You can't use pickAFile inside your function to read the pictures – which is not what you were asking – but you CAN use it in the command area (which, of course, is not part of your turn-in) to help write the pictures out. However, BE CAREFUL. If you writePictureTo(flag(), pickAFile()), you will overwrite whatever was in the file that you pick with the flag that you are writing. JES will not say "Are you sure?" but will just do it. So you need to make some copies in Windows/Mac Finder, first, to make sure that you are not overwriting a file picture that you need later. If this second answer doesn't make sense to you, you definitely should not experiment with combining writePictureTo and pickAFile. Colin Potts

When using the writePictureTo, what input do I use for the canvas? for example writePictureTo(input, path) what do i put in place of input?
I think you may have forgotten that flag needs to return a picture so that you can say myFlag = flag() in the command area and then writePictureTo(myFlag, ....). Colin Potts

The function in the book says canvas=makePicture(getMediaPath("640x480")). Are we supposed to make and save the canvas or is there a way to make it in the function then reference it there?
The book was written before makeEmptyPicture was implemented. That is a better way to make a canvas. Either way, it should be in the flag function itself, because flag is not allowed to have any arguments. Colin Potts


In the example of a collage function in the book it uses a file for the canvas rather than creating one. for example canvas=makePicture(getmMediaPath("etc...") How do I turn it into the picture i created earlier in the function?
See previous answer. Colin Potts

Could I use the Irish flag??
Why ever not? We have said yes twice already. Colin Potts
I cant figure out how to use the writePictureTo function after i have created the flag. Can somebody please give me a good explanation?
First, make sure that the flag function returns the flag and doesn't just show it. Then, you can say something like myFlag=flag() in the command area. If you already have set the media path (and I posted instructions on this to the code/slides page) you can then just type writePictureTo(myFlag, getMediaPath("flag.jpg")) and your flag image will be written to the file flag.jpg in your media path folder. Colin Potts

Is there a function that we can use to crop pictures to make them fit on our canvas? Or has that already been explained to us?
(1) If you want to scale your image, the easiest thing to do is to prep your pictures in advance using an imaging tool like Photoshop, which is available on many lab/library computers. There is also a free ScaleTool on the downloads page. It's a bit flakey, but works. (2) If you just want to crop a big image (as opposed to scale it), you could again use a commercial imaging program or simply copy the part of the image that you want in your flag function. For example, instead of copying all of the pixels from your picture onto the flag, you just copy a vertical slice of them. Colin Potts
If you're using Windows, I'd recommend using Irfanview. It's a free photo editing tool, with a lot of interesting features (many of them even useful), and it's also fairly intuitive. I use it all the time. Chris Phillips

When I use the writePictureTo function as you explanied above after I think I've set the media path, I get this message:

Note: There is no file at C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\flag.jpg
The error was: C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\flag.jpg could not be opened. Check to see if you can write to the directory.
I wasn't able to do what you wanted.
The error java.io.IOException has occured

How can I fix this?
This is a configuration problem that some PC users have. We haven't been able to fix it properly, but there is a work-around. Write the file to the very top-level folder, like this: writePictureTo(picture, "C:\flag.jpg"). You will then have to move it where you really want it to be. Colin Potts
You might also need that little 'r' in there, and two slashes (in case your image name starts with a character that can be escaped). So writePictureTo(picture, r"C:\\flag.jpg"). I have yet to see that fail on a Windows computer. Chris Phillips
It always tells me that, but when I look, it has created a file. So check and make sure there really isn't a file there. Thanks! Brittany Duncan
may I use Iran's flag?
about iran's flag I mean just to collage(resemble) the colors not the image inside
Please read all questions and responses before posting a question. Thanks! Brittany Duncan
Hi, when I run my program I get this

>>> show(flag())
The error was:flag
Name not found globally.
A local or global name could not be found. You need to define the function or variable before you try to use it in any way.

what should i do?
and then sometimes it says this

>>> show(flag())
show(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

please help!
The first thing you should do is stop making random changes to your program. It should always do the same thing. Wrong is better than random. I'm guessing that what you didn't do the first time was load your program, and what you then did was take a return command out of flag(). Put it back and we'll solve the problem from there. Colin Potts
ps i have canvas = makeEmptyPicture(..)
and at the end of my code i have "return canvas"
And what error are you getting when you have these two lines in your flag function? (They are actually IN your flag function, aren't they? The return command should be at the end of flag, not necessarily the last line of code in your program.....) Colin Potts
I will put this in and it keeps giving me this error:

>>> newPic=flag()
getPixel(picture,x,y): y (= 451) is less than 1 or bigger than the height (= 450)
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 57 of /Users/soccermouse01/Documents/cs 1315/hw2.py

it is referring to a line in my code that looks like:
canvasPixel=getPixel(canvas,xOffset+x,yOffset+y)
and when I # out the function it is in, it then says the same error message (with different y coordinates) for a different function referring to a line in that function that looks like this:
canvasPixel=getPixel(canvas,x,yOffset+y)

I am pretty sure it has something to do with my pictures. I edited them at the library in photoshop and emailed them back to myself and dumped them on my desktop. when i refer to the old pictures the code works, but now with the new ones it doesn't =[
You're making your canvas with a height of 450, but you are trying to write to a pixel on row 451 - presumably because one of the Photoshopped images that you are attempting to copy is too tall. Colin Potts
Oh, wait. you're doing the Russian flag, aren't you? So your pictures are probably each 150 tall. If so, the problem is probably with the y offset that you are adding to the destination y values in the second and third pictures. The sum should never go to more than 300 (so there is room for the third picture of 150 pixels height, making a total of 450), but somehow you are adding too much of a y offset. You might be able to get this to work by using a ridiculously high canvas. Start at 600, instead of 450, and work upward until it "works". Then show the resulting flag and work out by how much your offset needs to be reduced. Colin Potts
This keeps happening, I have triend different combinations:

>>> myFlag = flag()
>>> writePictureTo(myFlag, "c:\\flag.jpg")
The error was: output == null!
I wasn't able to do what you wanted.
The error java.lang.IllegalArgumentException has occured
What happens when you show(myFlag) Colin Potts
it shows my flag correctly
It looks like you have a Windows weirdness and are not doing anything wrong. It would be nice to get this sorted before the movie homework, because there you will need to write multiple files. For now, just submit your code and starting images and email your TA that there is a problem with writePictureTo that we can't fix right now, and you'll get as much credit as if you had uploaded your flag. Colin Potts
when I try to finally load my program, I get this error
>>> flag()
Picture, filename None height 369 width 267

I'm not quite sure what I'm doing wrong, since when I run the copy code separate from the picture-changing codes they both work, and it's only when I do them at the same time that it errs.
That's not an error. You're returning the canvas/flag, but you're then throwing it away and not using it. Instead of flag(), type show(flag()) or coolFlag = flag() in the command area. Then you can show coolFlag later, save it to file.... Whatever Colin Potts
Also, I've written separate functions for my codes, so I use this to get them to work:
posterize(pic1)
darken(pic2)
bw(pic3)
copy()
I don't know if I should be inputting anything into the copy part, since it takes in all three pictures...
when i run my copy function it gives me this error: Picture, filename None height 200 width 300

what does this mean?

Pictures posted to this page will be removed. They belong in the gallery. The homework instructions are very clear. Colin Potts
Is it okay if I use copyInto(small, big, X, Y) for this homework?
That is fine, but you will need to know how to write a copy function for your next exam. Thanks! Brittany Duncan
what is the lock password for when we try to put our finished picture up in the gallery. i already got the password to coweb from the FAQs as username:attach and pasword: carmen, so what is the lock password?
There is no lock password on the gallery. Thanks! Brittany Duncan
So...would using a function to remove the red and green of the first picture, then using a function to increase the Yellow of the second picture, then using a function to simply make the third picture yellow considered the same thing?



Links to this Page