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 3 Questions- Spring 2008

Post your Homework 3 Questions here.


So we can use any of the Sprites you listed as examples, right? We don't need to find our own? Thanks!
That is correct. Thanks! Brittany Duncan




How can getMediaPath() work without an input parameter?
You're absolutely right. I've emailed Brittany to have her look at it and figure out how she wants to change it; in the meantime though, what you can do, is -
directory = pickAFolder()
def movieFun(directory):
  ...
Which should work as you'd expect. Do take note, that when you do it that way, and then call directory later, you will need to specify the file name as "\\filename.jpg" (or "/filename.jpg" if on a Mac). You need the slashes to separate the file from the folder, as when you pick a folder, it doesn't append them at the end for you (and I used two because sometimes there's an error if you use just one. Try both if necessary). Chris Phillips
You can't use getMediaPath to work without an input parameter. I just expected you to figure out the correct input parameter. If you are going to use the pickAFolder() method, make sure that you input that on the command line and not inside your function. I thought that the get/setMediaPath() method would be easier because you have used it before. Either way will be fine. Thanks! Brittany Duncan

Can can the hw be more than 50 frames; would 52 frames be ok?
That's fine with me. Thanks! Brittany Duncan

When you say 2-3 sprites from the same group, do you mean that if one sprite (eg a cat) has 12 frames, we need to use at least 3 of them? Or do we need to get 2-3 totally different sprites, like a mouse and a cat?
Use all the sprites from 2-3 groups. The groups might be a cat walking, Homer Simpson crawling, etc. All of the files in a group should have similar names that differ only in a number (e.g. john_cleese_01.png.. john_cleese_12.png) Colin Potts

Regarding to the second question, doesn't pickAFile() only choose a specific file and not a folder. Yet directory needs to be assigned to a folder?

oh whoops! I didn't realize you said folder.

If we have one function that say makes and returns a canvas, how do we reuse that canvas file in another function? When I run the function for canvas within another function, it doesn't recognize the canvas file.
Please review what it means for a function to return a value and how to use that value elsewhere with a T.A. This is a basic topic that we have covered in class. It is illustrated in many of the posted code examples on the code/slides page. BTW, it may be easy to misunderstand your question because you are using terminology very loosely. I don't think that you are really talking about files, for example. Colin Potts

Colin, can you or one of the TA's please post how to run movie maker with a Mac? I know you went over it briefly in class, but if you could post the steps that would be great. Thank you.
I did.... A couple of weeks ago.... It's on the slides & code page ;) Colin Potts

I don't know what happened, but JES keeps saying that I have a syntax error and it won't highlight the line or tell me where the line is...so I have no clue what's wrong with my program right now...is there an option I can change so that it will start highlighting things again? Does it mean something specific if JES says I have a syntax error but isn't highlighting where it is?
You almost certainly have left out some open or close parentheses or mangled your indentation and have so confused JES that it doesn't know which line to complain about first. You should really construct programs piece by piece so that when this type of problem occurs, you always know that whatever you last changed must have introduced the problem. You have no alternative right now, unfortunately, to going through your code carefully line by line. As soon as you find something that needs correcting, fix it and try to load. You may at least get highlighting back for any subsequent errors. Colin Potts

ouch...
OK. I should have emphasized that it is probably a simple, silly error. Boring to find, but easy to fix. Colin Potts

My function works without having it take an input parameter. Everything is run using only getMediaPath() within the functions, and to run the function I just type in spriteMovie() into the command line and it works. Is that a problem?
Yes. (1) The function has the wrong name. (2) It doesn't take in a directory. If you're in my section, I'll show how to use the directory in class today. Colin Potts
That said, since Brittany is allowing you to use getMediaPath(), you can just change the spriteMovie() function to, A, have the right name, and B, take in a directory parameter. The TA will pass in a directory, but since we also have to use setMediaPath() to grade, the parameter never actually has to be referenced if you use getMediaPath() correctly. This way, though, you can reference the directory however you like, and in the future, it might change so it relies on the passed in directory only. Chris Phillips
Despite the promise, I didn't explain how to use the directory input in class today. Here are some hints:
  1. A directory is another word for a folder.
  2. Really, a directory/folder is just a text string representing the path to a file. It could be something like "/Users/potts/Documents/ed/1315/2008-Spring/Movies/" or "C:\Pictures\". This is what movieFun takes as its input. Make sure that the string you give movieFun when you test it ends with the symbol that your operating system uses as its directory/folder separator. On the Mac that is "/". On Windows, it is "\".
  3. Given that the directory is really just a text string, you can do anything with it that you can do with a string. For example, you can add another string (e.g. a file name) onto the end by using the plus operator. Say you have a variable fileName representing the file where you want to save a picture. It could have a value like "frame01.jpg". You can save a picture in that file by saying writePictureTo(picture, directory+fileName).Colin Potts

Which function do you chromakey in in order to have the little picture blend in to the background?
I posted an example of this ("Beam Me Up Scotty") to the Slides/Code page, which may help. Colin Potts

So we're supposed to upload ALL of our sprites individually?
Just the sprites that your code needs (and not the frames that are generated). Chris Phillips

I have code that looks like this in order to write my frames to My Documents:
if frameNum<10:
  writePictureTo(frame, directory+"\\frame0"+frameName+".jpg")
if frameNum>=10:
  writePictureTo(frame, directory+"\\frame"+frameName+".jpg")

The directory is defined as "C:\Documents and Settings\[my name]\My Documents".
Whenever JES goes to write my frames to My Documents, it gives me an error that says:
"The error was: C:\Documents and Settings\[my name]\My Documents\frame01.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"
I don't know what's going on. Can anyone help?
The first thing to do is to put code tags around your code here so that it is correctly indented and people can read it. (I did it for you this time.) I'm surprised that you're encountering this error for the first time, since if this is happening to you now it should also have happened when writing your flag in homework 2. I assume that you collaborated with someone on that one and never saved the flag on your PC. There is a work-around. It is explained on the homework 2 questions page. Colin Potts

Ok, so I have the program working but with one small glitch. I have a chromakey function that can work one of two ways: The first way is wrong. It basically copies one pixel from the background and then makes the "green screen" part of my foreground picture into that color. The second way is right. It copies ALL the pixels behind my fg picture and replaces the green screen part with those. However, the first one only takes about 1 or 2 minutes to complete the entire program, whereas the second one takes a very, very long time (like 15 minutes), to copy one frame out of 100. I think it's because it's cycling through every pixel behind my fg picture, whereas the other version is only picking one pixel. How do I make things go faster, is there an alternative?
You're on the right track. Without looking at your code, it's impossible to say exactly what is wrong, but I think it's very likely that your "correct" chromakey function has an unnecessary nested loop, so it is doing the right thing repeatedly. Here's what to do: look at each loop and ask how many times it repeats (if it has a range, the answer is easy to obtain; if it is doing getPixels, the answer is getWidth() multiplied by getHeight()). If you have one loop inside another, multiply the answer you get for the inner loop by the answer you get for the outer loop. Now ask how many pixels you really wanted to set and I think you will find that you are doing the chromakey setting of colors far too many times. Colin Potts

The sprites are supposed to avoid an obstacle in the background, but since the background is still, what is an example of something they have to avoid. I am using a background of a planet surface that goes well with the sprites but other than some mountains in the background there isn't anything for the sprites to avoid and i'm wondering if i need to change my background.
Also i was wondering if we could use sprites from the same group multiple times as long as they appear in the movie at the same time.
If the mountains are too far off, they could avoid each other. Having multiple instances of the same sprite will work. Colin Potts

I added a rectangle to my frames to act as a wall for my sprites to move around, is that ok?
Excellent! Colin Potts

How can chroma key be adjusted to work with a sprite that has a purple background? My function is running properly, but the sprites still have backgrounds.
Find out what the background color is and use that as your reference instead of green. (Hint: openPictureTool should help.) Colin Potts

My movie function correctly chromakeys the sprite onto the background picture and the sprite moves though all of its frames like it is walking. However, as it moves through its motions its not going across the screen. So in essence it is walking in place instead of across the background. How do i fix this?
Look at the x and y values you are giving to the chromakey function. If they are the same on every frame, the sprite won't move. Work out how fast and in what direction you want the sprite to move as a function of the frame number. Look at the other posted movie code examples not involving chromakey, like the pool table (and those that do, like the silly walk) for examples. Colin Potts

1. if we use getMediaPath, the directory doesn't seem to be doing much. should i be doing something different, or is it just supposed to be able to run with movieFun(directory)?
The directory is where you have to save the frames. See the green posting above for hints. Colin Potts
2. my sprites are numbered "01, 02,....010, 011, 012, etc." it works when i run it on my computer, but will it get screwed up when i turn it in?
Actually, I don't think it does work, but the extra flickering caused by ten frames of the first 100 out of correct sequence probably isn't very noticeable. It's not hard to add a second leading zero for the first ten frames – just a couple of lines of code. There is an example in the writeFrame function of the sillyWalk program posted on the slides and code page. Colin Potts

The sprite webpage is not working anymore ... it says under construction
I just tried it, and downloaded all the sprites again. It's not a page, btw; it's a zip file that should download automatically when you click on the link. Colin Potts

no, i went through it frame by frame, and they are in order. my frames are numbered with leading zeros (correctly), my sprites are out of order. the sprites are showing up in my finder window in the correct order, but not when i list them in terminal. the numbering doesn't seem to matter, but i just want to make sure that it will still work if its graded on a different operating system.
OK. Go for it. You could always try this out during a TA's office hours tomorrow. Either bring your laptop or a USB drive. Colin Potts

I have one sprite running from another sprite...does that count as an obstacle?

Do I have to change my generated frames from "aladdinrunning01.jpg" to be named "frame001.jpg"?
Why is it so hard to follow instructions? ;) Colin Potts

Ok, how about those sprites running from each other, does that count as obstacles?
Sure, Sure. If they're big and mean. Colin Potts

how do i offset one of the sprites so it starts farther from the left than the other sprite? Im having one sprite chase the other so i need one sprite to start further from the left than the other one. Suggestions please. Thanks!
Oh, come on, this is simple arithmetic! Take a deep breath and the answer will seem obvious... Further to the left means having an x value that is smaller. So subtract the offset. Make sure that the smaller value doesn't become smaller than zero, though, or the leftmost sprite will be off the picture and you will get an error when you try to get one of its pixels. Colin Potts

I have a sprite that I want to jump up and just come right down, but I can't figure out how to make it only go up and down and not travel side to side as well. How can i do that?
Look at the falling weight part of the sillyWalk example. The weight just moves down without moving from side to side. Colin Potts

JES is giving me a syntax error for code that is syntactically correct. I N E E D H E L P .
def chromakey(source, bg, X, Y):
  for x in range(1, getWidth(source)+1):
    for y in range(1, getHeight(source)+1):
      p = getPixel(source, x, y)
        if (getRed(p)>=255 and getBlue(p)>=255):
          setColor(p, getColor(getPixel(bg, X, Y)))
  return source 


Oops, i forgot the mention that the syntax error is on line 5 of this code
I N D E N T A T I O N . Lose the extra tab on the if statement and your syntactically correct code will be syntactically correct. ;) Colin Potts


Do you want us to include the play movie function in our code or will the TAs do that themselves?
No. Don't use that function. Colin Potts

When you turn in your homework through T-square, is it alright if you attach each individual sprite, your background, and your code?
Yes. Thanks! Brittany Duncan

How do you comment out a large block of code?
There's no direct way to do this in Python (unlike some programming languages.... which, I think may have motivated your question); you just have to comment each line. Colin Potts

This error message is highlighting when I try to make a picture from a file that I just retrieved using getMediaPath. I can't see what I'm doing wrong and this message is not very descriptive:

The error was:java.lang.StackOverflowError
I wasn't able to do what you wanted.
The error java.lang.StackOverflowError has occured
Please check line 43
Send me your code, and I'll have a look. Colin Potts

I keep getting this;


>>> movieFun(directory)
The error was:movieFun() too many arguments; expected 0 got 1
Inappropriate argument type.
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 looked through my code and can't tell what is wrong.
Your definition of movieFun must start like this:
def movieFun():

Where is the parameter??
Colin Potts

how do you find the frames that you have to put into the movie maker? i don't understand how you transfer the information from jes to movie maker. and when you type directory(), what file are you supposed to choose?
It's great that you want to make an actual movie from the frames you generated, but I just want to make sure you are aware that it is not part of your assignment. If after checking out the tutorial on movie maker, you still don't understand how it works, feel free to come to a TAs office hours. Also, by typing directory() I presume you are referring to directory = pickAFolder(), in which case you would select whatever file you want to write all your frames to (it can even be the same as the folder you picked for setMediaPath(). Hope this helps! Let me know if any thing is unclear! Toni Walden

"Couldn’t open the file. It may be corrupt or a file format that Preview doesn’t recognize" get this error message when i try to open my written frames. tried to open them with other programs as well but to no avail. any advice?

Make sure your file extension was done correctly. I believe you may get this error if you have a typo like "frame01.jgp" or if you just leave the extension off completely ("frame01"). Try either catching someone on AIM or e-mailing your code to someone if you check those things and it's not the problem. Toni Walden

when we set the directory is it supposed to write the frames to a completely different folder then where our images are found in setMediaPath?

We don't specify it in the directions, so do whichever you would prefer. Toni Walden

should we put our sprites in a folder to upload, or do them all separately?
Please upload them all separately Toni Walden

My canvas size is 640X480. My background image is 750X504. Whenever I choose the starting x and y location of my sprites, I get an out of range error. If I want the 2 sprites on the bottom of the canvas, one on top of the other what x and y's should I use
The out of bounds error you are getting is probably because your background image is larger than your canvas size. As far as what x's and y's you should use for your sprites, I can't tell you considering you gave me no information about them. Just try to do the math! For example, for the first sprite (the one for the very bottom) figure out the height of your canvas and then subtract the height of that sprite, and viola! you have your y-value. Apply the same logic to the rest. Toni Walden




Link to this Page