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

Summer 2004 Homework 5 Questions

Questions on building your animations?


Could you define what a composited image is exactly?
A composite image is "a photograph or other image that is created by a combination of multiple images on a single sheet." Nicole Seekely
Just be sure to include all the images you used in any way shape or form in the turnin (do NOT give us the frames. Your program will kindly do that for us with the base images you provide us.) -Blake O'Hare

I have written code for a tickertape and I have also made the canvas. I am trying to look at the animation. Where do I write in the specific directory and string? I tried in the programming area usind this { def tickertape("C:\Documents and Settings\Lindsey\Desktop\HW5Folder","Welcome to Paradise!"):}This says that there is a syntax error.
I also tried in the command area. There it is saying that a local or global name could not be found.Could you please help me fix this?
Well, when you're defining your variables, you do that in the command area when you want to run your program. Does your function have inputs where you typed it in in the program area? I think the book gives an example like
def tickertape(directory,string):
Nicole Seekely

The book says that you must save the file as a movie(.mov) in order to view it in movieMaker. Is there a special way to do this?
When you generate your movie from the series of JPG imgeas you have using a program such as QuickTime or MediaTools, you should save it as a .mov file so that you can view it. Nicole Seekely
To create a .mov file from your frames, use the MovieMaker application found at http://coweb.cc.gatech.edu/cs1315/847 There's a great tutorial there on how to use it too. Dannon Baker

Instructions say that we must have three images. The book does an example of a sunset, does this count?
Not three images, but three animated objects. If you wanted to animate your sunset, sure, that'd count for one (still need two more). If it is a still background, and not animated (you DO need a background, don't leave it plain white), then it will take care of that requirement, but you would still need 3 animated objects. Dannon Baker


On page 269 in the book, there is an example where a picture is moved across the screen. Could someone please tell me line by line what this section of code is doing?
sourceX = 45
for targetX in range(frame*3, frame*3+((200-25)/2)):
    sourceY = 25
    for targetY in range(frame*3, frame*3+((200-25)/2)):    
   

I want to move a 45x98 picture across the bottom of the canvas640x480,from left to right. How can I convert the above program to reflect what I want to do?
Something important you left out was the for loop before that which was
for frame in range(1,100):
The source/target X and Y's are doing the same thing as when you simply copied a pic or sound. The only thing that changes is that you're going to copy the picture 99 different times, each in a slightly different spot. For example, the first time the picture is copied, the frame number is 1. Therefore it is copied to the target in the X range of (3,90) and Y range of (3,90). Then it goes through the for loop again, except this time the frame number is 2. Now the picture is going to be copied in the X range of (6, 93) and Y range of (6,93). This will continue on until the frame number gets to 100 which it won't copy anymore. Now, once you compile all those 99 images you just created in a movie, it will look as though the picture is moving across the screen. The important thing to note here is the use of the variable "frame" in the range. That's what will make the range change everytime you go through the for loop. Nicole Seekely

I have used the tickertape function as my outside function:
def hw5(directory):
  
  flower=makePicture(getMediaPath('flower1.jpg'))
  tickertape('Flowers!!')
  for frame in range(1, 50):
.
.
.
def tickertape(string):
 for frame in range(25,50):
    canvas=makePicture(getMediaPath('pansies2.jpg'))
    addText(canvas,600-(frame*10),100,string)


The program runs, however i cannot find my string in the movie, the background very dark, so it may be hard to see. Can I change the color of the text, and am I doing something wrong because I should still be able to see it but i cannot find the string in my movie.
I'm not exactly sure what's wrong, but I think it may do with how you have the two functions set up. If you want, you can e-mail me all of your code and I'll look at it for you. Nicole Seekely
For those that are having problems with using tickertape or any other function, be sure to watch out for what inputs you need to include. It may require more than just a directory as input. Also, in the code above, the functions are writing to two separate canvases. An additional input may be required for tickertape so that you can use the canvas that you're working with in the hw5 function. Nicole Seekely

how do you adjust frame rate?...or is it predetermined somewhere, somehow?
I believe you adjust the frame rate when you actually make the movie with MovieMaker or QuickTime. The program will prompt you to enter in the frame rate. Nicole Seekely

I can't get my frame filenames to copy right. I have the "frame00"+framenum+".jpg" in the writeTo part but it just won't save as frame001.jpg, frame002.jpg, and so on. It just keps saving as frame01.jpg...Help?
Do you also have the if statements included with that so that it will change if the framenum is less than 10? Nicole Seekely
If you are using 1, 2, and 3 digit numbers, each kind has to be handled differently... it sounds like you understood that since you show a double zero after the word frame. Have you saved and pressed 'load' in JES since you made the code handle 3 digit frame numbers? -K.K. Lamberty
regarding the framenum and saving the frames, I copied the code straight from the book...it does it correctly for the 10>= ftrames but i don't know why it doesn't do it for the 10< frames...i have the other if statments for frames>=10 and frames<100 in there also...i had the third if statement in there for frames>=100 in there too...but i decreased my frames to 50 instead of 100...i'll try taking the third if statement out and running it...

the code from the slides are wrong...
def writeFrame(num,directory,framepict):
    # Have to deal with single digit vs. double digit frame numbers differently
    framenum=str(num)
    if num < 10:
      writePictureTo(framepict,directory+"//frame00"+framenum+".jpg")
    if num >= 10 and num<100:
      writePictureTo(framepict,directory+"//frame0"+framenum+".jpg")
    if num >= 100:
      writePictureTo(framepict,directory+"//frame0"+framenum+".jpg")

if frames are >=100, there shouldn't be a 0 in front of the 100+ frame numbers, should there?
Thanks for catching that error. You are correct, there is no need for the 0 in that case. -K.K. Lamberty

if frame >=10 and frame<=76:
      sourceX = 1
      for targetX in range(1, frame*3+((200-25)/2)):
        sourceY = 1
        for targetY in range(100, frame*2+50):
          flower = makePicture(getMediaPath("flower.jpg"))
          color = getColor(getPixel(flower,sourceX,sourceY))
          setColor((canvas, targetX, targetY), color))
          sourceY = sourceY + 2
        sourceX = sourceX + 2


This code is straight out of the book. Why is it telling me, on the line color=... that there is an undefined local or global name. The same code is also used when copying pics to normal canvases. Don't know why it wont work

Sometimes it gets the line wrong. Do you have canvas defined somewhere? You can also turn the debug mode to Expert (under Options in the Edit menu) to find out which name it can't find. Mark Guzdial

i used a picture that i cropped in photoshop b/c i was trying to cut out the shape, not just shrink/blow up the image. I saved it as a jpeg, but when I add it to the background and move it, it leaves a white track that blocks out all of the area it covers throughout its full range of motion...is there anything i could do to fix that?

Are we supposed to turn in the movie too??

Turn in your program and the composited image(s) (any images that you copied INTO your frames) via JES as "hw5". (You do not have to attach all your frames!) Your file must be named "hw5.py" and your function must be named "hw5" and accept a directory as input where the frames should be stored... So, no, you don't turn in the movie. However, please feel free to post your movie to the CoWeb to share with everyone. -K.K. Lamberty


Does the tickertape count as something drawn?
No, I don't think that would count. The tickertape is more like the rectangles where you don't have to specify anything about pixels (like you would if you use an image). Any input from the TAs on this? -K.K. Lamberty
Ack! Here's what the homework page says...You must use at least one composited image (a JPEG image that you scale (if necesary) and copy into the image), one drawn image (a rectangle or line or text or oval or arc – anything that you draw), and a third image of your choice. So, the tickertape is text and counts as a drawn image, but you still need a jpeg. -K.K. Lamberty

hmmm, i can do all the functions separately but can't get them to work together... any suggestions?
Try to think carefully about how each frame is drawn. Are you drawing on one canvas or are you accidentally redrawing the canvas and covering up what you just drew? Hope this helps. What, specifically, is happening? How does what you're seeing compare to what you think you should be seeing? -K.K. Lamberty

So should our homework generate a movie, or should it just generate the images to make a movie?
The homework should generate the frames so that your TA can use MovieMaker to put the movie together... someone else want to verify this? -K.K. Lamberty
K.K.'s right, your homework SHOULD generate the frames, but you SHOULD NOT attach the frames when submitting it... we'll generate the frames ourselves when the program runs. So even if you're having problems with your program, make sure it works even if it doesn't meet all requirements. Oh, and be sure to attach the .jpg images that you use in your movie. Nicole Seekely

ok...so does the "composite" image that has to be included, and animated have to be made from more than one image?? it cant just be another jpg?
The composite image is really just another .jpg. The instructions use the term "composite" to differentiate the image from a JES drawn image. Nicole Seekely




def hw5(directory):
  endframe=100
  picture=makePicture(directory +"//negrilbeach.jpg")
  for frame in range(1,endframe): #99 frames
    printNow("Frame number: "+str(frame))
    canvas = makePicture(getMediaPath("640x480.jpg"))
    # Now, do the actual copying
    sourceX = 1
    for targetX in range(1,getWidth(picture)):
      sourceY = 1
      for targetY in range(1,getWidth(picture)):
        color = getColor(getPixel(picture,sourceX,sourceY))
        setColor(getPixel(canvas,targetX,targetY), color)
        sourceY = sourceY + 1
      sourceX = sourceX + 1

This runs until the sourceY = 295? or so and the returns the error message (in Expert mode)
>>> hw5("C:\\Documents and Settings\\James Skinner\\Desktop\\exam2")
Frame number: 1
I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
in file C:\Documents and Settings\James Skinner\Desktop\JES\Sources\JESDebugger.py, on line 142, in function run
in file C:\JES-SA1a\jython\Lib\bdb.py, on line 351, in function run
in file <"input">, on line 1, in function ?
in file C:\Documents and Settings\James Skinner\Desktop\JES\hw5.py, on line 12, in function hw5
in file C:\Documents and Settings\James Skinner\Desktop\JES\Sources\media.py, on line 825, in function getPixel
in file C:\Documents and Settings\James Skinner\Desktop\JES\Sources\media.py, on line 491, in function getPixel
in file C:\Documents and Settings\James Skinner\Desktop\JES\Sources\media.py, on line 571, in function __init__
java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
Please check line 12 of C:\Documents and Settings\James Skinner\Desktop\JES\hw5.py

The source pic is exactly 640x480...what's going wrong here?



nevermind..I had to change it to this.
for targetY in range(1,getHeight(picture)):

I have written my program, run it in jes, and made it into a movie with movie maker... but when I try to play it with JES it won't work. This is what I'm typing into JES:

openMovie(pickAFile())

Then I am choosing my '.mov' file and this is the error message I'm getting:

I wasn't able to do what you wanted.
The error java.lang.NoClassDefFoundError has occured
in file C:\Documents and Settings\Natalie\Desktop\JES\Sources\media.py, on line 1029, in function openMovie
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError

Do you know why this is happening??

ignore that last question! i figured it out! :)

ok could some one please explain when it says 45 frames with 15fps, in the book they have used 99 frames by going from range 1 to 100 so for hw 5 you want us to go a minimum of range 1 to 46. What I am cofused is when I write the program how saying the range to go from 1 to 46 how will I know that they are going exactly 15 per second.
You won't actually set the frame rate until you create the movie with a program like MovieMaker. That program will prompt you for the frame rate which you should enter a minimum of 11 fps. Nicole Seekely

changing text color???? how is it done...i think it tells you on page 311, but i can't make it work...
Okay, manipulating the text is not so bad. Here's what you do (found on page 311). There are two methods regarding text:
.addText(color,x,y,string)
and
.addTextWithStyle(color,x,y,string,style)
style can be created from
makeStyle(font,emphasis,size)
The font is sansSerif,serif, or mono. The emphasis is italic, bold or plain or the sum of them (e.g. italic+bold) and size is a point size. Here's an example
canvas=makePicture("toads.jpg")
canvas.addText(green,400-(frame*10), 200, "Hello there!")
canvas.addTextWithStyle(white,300, 100+(frame*25), "Hello again", makeStyle(sansSerif,bold,26)

This help any or are you still having trouble? Nicole Seekely

two questions 1. can we have more than three things in motion in our mov.
Sure!
2. I took barbara's picture and made some changes to it by adding text around her (I did this in paint) and remaned it as another jpg picture. Does this count as the third jpg of our choice.
Yes.
3. My movies runs fine but the problem is how do you make one object occur in the movie and let it stay there for the rest of the movie ( I mean I don't want my first jpg to just go away) how do I make it stay in the picutre while other jpg and text are coming in the following frames?
You may need to use if statements in your for loop so that some pictures are only included in part of the animation. So, if you have something like
for frame in range(1,100):
you could include an if statement such as
 if frame>20 and frame<80:
so that you can have text and other jpgs come and go. Nicole Seekely


Changing TExt color and font how do you do it?
See above! Nicole Seekely

ok...let me just double check to be sure: We only turn in our hw5.py and the images we used to create our frames, though we do not have to include the .mov file we created with MovieMaker. Correct?
Correcto.

I keep on getting this error: "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." When trying to make the writeFrame function work, it's always that first writePictureTo line. What's wrong with that line, or the function?(I got it straight from the book)
def writeFrame(num,dir,framepict):
  framenum=str(num)
  if num<10:
    writePictureTo(framepict,dir+"//frame00"+framenum+".jpg")
  if num>=10 and num<100:
    writePictureTo(framepict,dir+"//frame0"+framenum+".jpg")


Never mind my error's gone (above) for some reason my computer didn't like setMediaPath, but when I manually typed in the dir, it was fine.

Is it alright if our program takes forever to run, but it does what it's supposed to do?

my pictures all leave a trail as they move across the screen. here is some of my code. what's going on?

for frame in range(1,100):
sourceX = 1
for targetX in range(frame3,frame3+53):
sourceY = 1
for targetY in range(frame3,frame3+45):
color = getColor(getPixel(cat,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY = sourceY + 1
sourceX = sourceX + 1

I'm having the same problem as above,in that I can't save the frames. I've done show(canvas)and know thry're being generated. Did you type in something like
>>> directory=" C:\AnnElla\CS1315\hw5\" into the command area or where or what? Please help! gtg486k

i am not a hundred percent sure, but this was my problem. you need to have canvas = ... after the for frame in range(1,100): because doing this will reset the canvas for each frame, currently you are saving all of your frames on top of what was done to the fram the last time the for loop was run. i am not sure if that helps.

Link to this Page