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

Spring 2005 Homework 5 Questions

Ask questions about Homework 5 here.



.announce.

Could you give me an idea of what we need to put in the command area after we type the program def, what is an example of a directory? sarah c.
Make a folder to put the frames in and put the path to that folder as input to your function:

myMovie(r"C:\something or other\some folder you made")

it saids that there should be three things in motion, but all the sample movies only have two. for example, the tiger wood movie only has tiger wood's head and the text message moving around. where is the third motion picture? thanks.
The requirements back in Fall of 2003 only called for 2 objects in motion.

how do i move a picture from left to right on the canvas?

When a picture is moving from left to right, it's x coordinates will increase. So when you copy your picture onto the canvas, for each successive canvas, you would want to increase the starting x coordinate of where you place the picture. Student1594

Is there anyway the due date for HW 5 be moved to Monday?

Not officially. If you need an extension, speak with your professor. Student1594

What does it mean that we have to have a subfunction? What kind of addtional function do we need besides makeMovie?
REMOVEDbfunction == additonal function
You need three things in motion. So one approach could be to have 3 other functions that each added a moving object to a frame. Or perhaps you could have one function that copies a specified picture to a frame at a specified location that you would call 2 different ways. Plenty of other ways to do it, too.

I've ran my .py file which makes the 99 frames, but when I open moviemaker.exe and choose the start file and the end file I end up with a memoryerror in the executable window. How do I run moviemaker to work without erroring as a memoryerror? Any help would greatly be appreciated.

Same problem here. Mine says memory error also.
Some computers just have issues with moviemaker. You could try reducing the number of frames your program generates or you could try restarting your computer. If that doesn't help, try it on a friend's computer who's gotten it to work previously.

I'm a little confused, what is our myMovie function supposed to look like?
Your myMovie function is supposed to generate the 30+ frames for your movie. Typically, it'll be a for loop for all the frames with a writePictureTo at the end of the loop.


I ran movieMaker now how do I run the movie? Where does it save it? What's the file name?

It save it in the directory where movieMaker is. And it calls it whatever you specified for a name. It sould end in .mov Student1594

I am having a spacing error and i dont know why...it is when i am doing this..
sourceX = 45
    for target in range(frame*3,frame*3+((200-45)/2)):
      sourceY = 25
      for targetY in range(frame*3,frame*3+((200-25)/2)):
         color = getColor(getPixels(me, int(sourceX), int(sourceY))))
         setColor(getPixels(canvas,targetX,targetY), color)
         sourceY = sourceY + 2
      sourceX = sourceX + 2

it says that i have a spacing error on the line with sourceX = sourceX+2...where is the error?

oh, it doesnt show the indentions on my code...i guess that would make it hard to figure out where the error is...i'll just e-mail a TA...thanks anyways!
Fixed. REMOVED the color = ... line. You've got too many closing parenthesis.

My program will load correctly, but when i try to run it, it tells me "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." on this line........color = getColor(getPixels(me, int(sourceX), int(sourceY))).......what is wrong?
getPixels??? getPixel!

I am getting an "Array out of bounds error" but I do not know why. Can anyone help me? Thanks!
sourceX = 0
    for target in range(frame*3, frame*3+((105-0)/2)):
      sourceY = 5
      for targetY in range(frame*3, frame*3+((85-5)/2)):
         color = getColor(getPixel(me, int(sourceX), int(sourceY)))
         setColor(getPixel(canvas,targetX,targetY), color)
         sourceY = sourceY + 2
      sourceX = sourceX + 2


Sorry, the error is coming up on the line color = getColor(getPixel(...)))
You're starting sourceX off at 0. That column doesn't exist, it starts off at 1. I would STRONGLY suggest writing your loops so that the for loops auto-increment the source variables and that the target variables are incremented by the targetX = targetX + 1 type of stuff with an if block checking to make sure the target pixel exists before you write to it. That way an out of bounds type of error will be impossible.

I'm trying to get the examples of the red rectangle and tickertape moving to run on my computer. I'm copying the code straight from the powerpoint slides and loading it, but it's not working. What else do I need to do?
Can't exactly say without reading the code. What might have happened is that things like quotation marks and apostrophes got replaced with formatted curved appostrophes by powerpoint or a space got dropped or the code you pasted used a variable that you weren't. Like I said, I can't really say without REMOVED information.

i keep getting a java.lange.outofmemoryerror after I put in my first and last frame in moviemaker???
Moviemaker won't work on all computers. Try restarting your computer and running it with no other programs running, and with fewer frames. If it still doesn't work, try using someone else's computer. Also, if you cannot get it working, remember that it is not necessary to create a movie for the assignment. As long as all the frames are generated from the code, all you need to turn in is the code. Student1594

I am working with code that we went over in breakout this code is supposed to help us create a directory with one hundred jpegs or frames in it, i am getting a problem with the 3rd line of my code which is the first step under a for loop. the second and third lines are
for i in range(1, 21):
targetX=int(i +0.0)/20 (getWidth(target)-getWidth(source)):

btw i have tried a lot of variations on the parentheses and that doesn't seem to have any effect, the error i keep getting is that i have a syntax error, the error is on line 3 (i have also tried to look at line 2 to fix it..)
It seems like you are trying to multiply the difference in the widths by i/20 and then make that an integer. To do this, one you aren't multiplying and that would cause a syntax error. Also, the int should be around the entire expression, not just i + 0.0 Making that an int effectively does nothing since i was already an int. Student1594


how can we see the movie once we run the function? It creates 3 final frames in the directory, is that what it's supposed to do?
That depends on what your code looks like. How many frames is your code supposed to create? The line for frames in range(i,j) (You should have a line similar to this in your code) Whatever j-i equals is basically how many frames should be created. Student1594


Yea, sorry, I meant 99 frames, since it was range(1,100)
So how can I see the movie?
You have 3 options. You can generate the movie with movie maker, or you can click on a few images individually to see if it's kind of doing what you want it to. However, if you're on windows XP, here's a cheap trick: you can view the folder contents so that all the folder icons are thumbnails and they're all in a single row (I think the option for it is called "filmstrip"). Click the first image and hold down the right arrow key, and it'll sort of give you an animated effect.

Could you explain to me in english what the line targetX=int((i+0.0)/20 * (getWidth(target)-getWidth(source))): means...is this establishing a starting point to copy the pictures or what?
Yay, someone that actually came to my breakout! i was the variable that I used for the frame number and 20 was the maximum number of frames. so that first part (i + 0.0)/20 is the percentage of the way through the movie this frame is, so it'll be a decimal number between 0 and 1. If you just did i/20, then it would chop off the decimal places which is A Bad Thing, so that's what the 0.0 is for. Then we're multiplying that by the final x coordinate where we want our picture to end up by the end of the movie so that it makes it look like the picture is moving at a constant rate from the left side of the canvas to the right side of the canvas.

Can anyone tell me what I should do when I have "The error java.lang.ArrayIndexOutOfBoundsException has occured"

This means that you are trying to acess a pixel that is out of the range of pixels in the picture (For example trying to get/set to a pixel at x location 101 in a picture that is only 100 pixels wide) REMOVED your loops and your targt and source variables. Student1594

I'm having trouble with my program – it's telling me just to "check" a line...and I don't see anything wrong with it!

def myMovie(directory): bgf=getMediaPath("bg.jpg") bg = makePicture(bgf) pantherf=getMediaPath("panther.jpg") panther = makePicture(pantherf) titlef=getMediaPath("title.jpg") title = makePicture("title.jpg") for frame in range(1,15): canvas = makePicture(getMediaPath("title.jpg")) sourceX = 0 for targetX in range(640-(frame),445-(frame)): sourceY = 0 for targetY in range(480-(frame),226-(frame)): color=getColor(getPixel(panther,int(sourceX),int(sourceY))) setColor(getPixel(canvas,targetX,targetY), color) sourceY = sourceY + 2 sourceX = sourceX + 2 writeFrame(frame,directory,canvas) def writeFrame(num,directory,framepict): framenum=str(num) if num < 10: writePictureTo(framepict,directory+"//frame0"+framenum+".jpg") if num > 10: writePictureTo(framepict,directory+"//frame"+framenum+".jpg")

The first "writePictureTo" statement at the end was taken directly out of the book, but JES is saying that I need to "check" that line. Any ideas? Thanks!
All I can think of is that the directory possibly doesn't exist.

What do you mean by a composited image? Can it be a regular picture image from our MediaSources folder?
Composited image == any old JPEG

I can't turn in my work...JES isnt' listing any of the homeworks...under Assignments it just has one bullet saying "Assignments"...what should I do?
Make sure you start JES while you're connected to the internet. If that doesn't change anything, then try the crash and burn turnin method or contact a TA about it.

  for frame in range(1,100):
    printNow("Frame number:"+str(frame))
    sourceX=1
    for targetX in range(frame&#42;5-5, getWidth(turtle)+frame&#42;5-4):
       sourceY=1
       for targetY in range(frame&#42;5-5, getHeight(turtle)+frame&#42;5-4):
         if targetY < getHeight(canvas) and targetX < getWidth(canvas):
             color=getColor(getPixel(turtle,int(sourceX),int(sourceY)))
             setColor(getPixel(canvas, targetX, targetY), color) 
             sourceY=sourceY+1
       sourceX=sourceX+1


"The error java.lang.ArrayIndexOutOfBoundsException has occured"
it says it in "SetColor...", but I already included an if statement to make sure it won't go off boundaries ("if targetY getHeight(canvas) and targetX getWidth(canvas):")Why does it still say error?
You didn't check to make sure it didn't go off the top or the left. You need to have a 1 <= targetX, etc. in there.

  for frame in range(1,100):
    printNow("Frame number:"+str(frame))
    sourceX=1
    for targetX in range(frame&#042;5-5, getWidth(turtle)+frame&#042;5-4):
       sourceY=1
       for targetY in range(frame&#042;5-5, getHeight(turtle)+frame&#042;5-4):
         if targetY < getHeight(canvas) and targetX < getWidth(canvas):
            color=getColor(getPixel(turtle,int(sourceX),int(sourceY)))
            setColor(getPixel(canvas, targetX, targetY), color) 
            sourceY=sourceY+1
      sourceX=sourceX+1


It said there was a spacing error in the "sourcex=sourceX+1" line. How?
Count the spaces on that line. Compare it to the block of code it's supposed to be in.

how do we make a picture appear midway through the animation?
Take the code that puts your 3rd image on the canvas and put an if block around. Something like
if frame > 20:
  #code to place your moving object here...

I am trying to use moviemaker to see my movie, but it says the java.lang.OutOfMemoryError every time whether i restart my computer and have no other programs or if i use a lesser number of frames to see a part of the movie..any idea what's up?
Scroll up! ;)

my internet stopped working. is my only option to finish/turn in this assignment to download jes on someone else's computer? can i turn in assignments from jes if i have no connection?
You cannot turn in an assignment without an internet connection. You could work on it without an internet connection and then use the crash and burn method when you do happen to get to a computer with a connection that doesn't necessarily have JES on it, though (like the library).

i have my code written but i'm having trouble making/locating the directory with the frames in it.
What I would do is create a new folder on your desktop called something like "Movie Frames". Then in the command area, type...
>>> dir = pickAFolder()
Then pick that folder. Then to call your function...
>>> myMovie(dir)
Then if you did everything correctly, your frames will appear in that folder on your desktop.

you create it in the program right? then how do you find it?
No, you do not create the folder from inside the program.

I keep getting an error message: "writePictureTo(pict,filename): Path is not valid
An error occurred attempting to pass an argument to a function.
Please check line 42 of C:\Documents and Settings\Keyan\My Documents\mymovie.py"

it says the error is on this line and i can't figure out why:
writePictureTo(framepict,directory+"//frame"+framenum+".jpg")
I would try what I mentioned directoy above, that should fix this error.


If we use the function called writeFrame(num,dir,framepict) that was used in the powerpoint presentation, does that count as a subfunction for us? Also, how do we know how long our movie will be, and how do we choose the number of frames per second? I thought we only turn in the JES function, not an actual movie. Please help!
Yes, writeFrame(num, dir, framepict) can be your separate function. The minimum allowed framerate is 10 frames per second. So when we're grading these, we'll just be looking to see if your program generated atleast 30 frames. You don't have to actually generate the movie, just the frames. And yes, you only turn in your JES function (with the pictures you used to generate it, of course).

My first line is def myMovie(dir):
The second line is moto=makePicture(getMediaPath("ducati.jpg"))
In the command box, I set dir=r"C:\JES\JES\Homework5"
(My pictures are all in the Homework5 folder) When I try to run the program by typing myMovie(dir), it says "Note: There is no file at C:\JES\JES\ducati.jpg
makePicture(filename): There is no file at C:\JES\JES\ducati.jpg
It keeps trying to access the folder before homework5, any ideas why??? When I put the pictures in C:\JES\JES, it works.
Are you sure you ran setMediaPath() on your Homwork5 folder first?

(Blake):
sourceX=1
    for targetX in range(frame&star;5-5, getWidth(turtle)+(frame&star;5)-4):
       sourceY=1
       for targetY in range(frame&star;5-5, getHeight(turtle)+(frame&star;5)-4):
         if targetY < getHeight(canvas) and targetX < getWidth(canvas):
            color=getColor(getPixel(turtle,int(sourceX),int(sourceY)))
        ->  setColor(getPixel(canvas, targetX, targetY), color) 
            sourceY=sourceY+1
       sourceX=sourceX+1


JES says there was an outofbounds error. How can I fix it?
Looks like targetX and targetY spilled off the edge of the canvas. You could surround this line with an if statement specifying that the coordinates (targetX, targetY) are actually on the canvas. Something like if 1 <= targetX <= getWidth(canvas): and the same goes for targetY.

I added the if statement, now the code looks like this:

    sourceX=1
    for targetX in range(frame*5-5, getWidth(turtle)+frame*5-4):
         sourceY=1
         for targetY in range(frame&star;5-5, getHeight(turtle)+(frame*5)-4):
           if 1 <= targetX <= getWidth(canvas) and 1 <= targetY <= getHeight(canvas):
              color=getColor(getPixel(turtle,int(sourceX),int(sourceY)))
              setColor(getPixel(canvas, targetX, targetY), color) 
              sourceY=sourceY+1
         sourceX=sourceX+1


But it still says the same error, even if I tried putting the targetY on the next line. Why?
You don't want the sourceY = sourceY + 1 to be conditional. unindent that once. Since you're using the target pointers as your auto-incremented variable by the for loop, then you need to add another check to make sure that the sourceX and sourceY are actually existant on the source canvas (although it would probably be better to logically reason this out with your equations involving frame)

since I can't create my movie (moviemaker doesn't work on my computer), how do I know if my pictures are in motion?

Pick out a few images and compare them.

I'm writing code for frames in range(1,46) to get 45 frames, and I included a printNow statement that displays the frame number as it executes the function, and it says that it went through all 45 frames - but then when I open my directory it only has frames "01 - 9" which is 19 frames - I copied the writeFrame function out of the book too - so the third anaimantion that comes in after frame 20 isn't ever appearing - any ideas on what is happening and/or how to fix it? (my computer is doing the same thing with just the simple movingRectangle function, and it's dong the same thing when I do it on my friend's computer - I can't get it to give me a frame # past 9!)

I did the >>>dir= thing earlier and I still cannot get past that error at writePictureTo.



Links to this Page