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 2005 Homework 3 questions page


Are you guys going to set the media path or is the directory supposed to be the path for the program to find our images? If so, how do I make the directory the path for my pictures??

we will setMediaPath (it will be a different place than the input)...the directory is going to be where we will 'write' your (awesome) movie to on our computer (big hint there). Student1919
We will set the media path to the directory where the source images are (the images that you submit with your assignment that will combine to make the frames) The directory that is inputted into the function is where you should write your frames to. Student1594

What constitutes the required "composited image"? Does this mean two images combined into one of which we make move across the screen. Please give some examples.
the homework says "a JPEG image that you scale (if necessary) and copy into the image", i'd go with that. Student1919
A composited image is any jpg image that you copy onto the canvas. In homework 2, the pictures you copied onto the background were composited images. Student1594

I put the following in, into my def function:
 framenum=str(frame)
    if frame < 10:
      writePictureTo(canvas,directory+"//frame0"+framenum+".jpg")
    if frame >= 10:
      writePictureTo(canvas,directory+"//frame"+framenum+".jpg")


I keep getting an error stating: 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 is wrong? This is on the lecture slides as well...

make sure you are taking in a string for the directory, and make sure the canvas is actually a picture. Student1919


I am getting this error statement -
I wasn't able to do what you wanted.
The error java.lang.UnsatisfiedLinkError has occured.

What does this mean??

What does your code look like that is producing the error? Student1594

when I did the writePictureTo part....only frame99 (the last frame) showed up in my directory. Any reason for this?

nevermind, it was a spacing problem.

isn't JES supposed to recognize the functions addRect, addOval, and addArc? its not highlighting in the program area for me when I type it.

it only recognizes addRect (not even addRectFilled)

Not every function in JES will turn color when you enter it. Try running your program. If you typed it correctly, it should work. Student1594

is our animation supposed to make sense? or can it just be a three things moving around?
It does not have to make sense... -Student2081

my program stops at the line that says:
addOvalFilled(canvas, 100, frame10, 50, 50, green)

it give me this error:
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.

Is addOvalFilled not an already defined function?
Based on the information you have given. JES cannot find frame10. I assume that what you wanted was
frame*10
that would work. -Student2081

i meant to type frame10....thats what i had in my function

frame10
frameX10

the asterick is not showing up after i add it to the page
Read the faq on how to type an asterick on the coweb. Or check the box in the edit window, which will show you as well. Student1594
Is canvas the name of your background picture? -Student2081

Does the code to our composite image need to be in the hw3.py code or do we make a composite image and then put it into hw3.py? If the later, how could you tell that we scaled an image? It sounds like I am answering my own question, but please clarify.

Your composite image does not need to be altered. You can copy it into your movie just as it is. The scale reference in the assignment is in case your picture is too large to copy into your picture. If that is the case, you can either scale it down and use the scaled image as your composite image and not include the scaling function in your hw3.py file, or scale it while you are copying it and then you would include the scale function in your hw3.py file. Either way is fine. Student1594

yes, canvas is the same name as my background picture

Would extra credit also be awarded if, instead of chromakey, the background is replaced with another image?
(this would save steps and time over achieving chromakey)
Background subtraction is also a viable candidate for extra credit if you do it properly. Student1594

I am getting the following error:
writePictureTo(pict,filename): Path is not valid
An error occurred attempting to pass an argument to a function.

writeFrame(frame, directory, canvas)

def writeFrame(num, directory, framepict):
framenum = str(num)
if num 10:
writePictureTo(framepict, directory+"//frame0"+framenum+".jpg") ERROR ON THIS LINE
if num >= 10:
writePictureTo(framepict, directory+"//frame"+framenum+".jpg

What are you sending in as your directory? Make sure it doesn't end with a / Student1594


what do I need to do to see the picture after I did chromakey or background suntraction? I could not find out how after I wrote the function
"def swapbg(person, bg, newbg):
for x in range(1,getWidth(person)):
for y in range(1,getHeight(person)):
personPixel = getPixel(person,x,y)
bgpx = getPixel(bg,x,y)
personColor= getColor(personPixel)
bgColor = getColor(bgpx)
if distance(personColor,bgColor) 10:
bgcolor = getColor(getPixel(newbg,x,y))
setColor(personPixel, bgcolor"

Try returing your person picture and then show it from the command area Student1594


When you get the out of bounds error? (error java.lang.ArrayIndexOutOfBoundsException)

What does that mean about the pictures you are using? Do you need larger pictures?
It means you are trying to access a pixel that is not in the picture. This can be because your for loop is too large and you are running off the edge of your source picture, or because your source picture is too large, or being put too far to the right or bottom of the background and you are running off the edge of it. To get any REMOVED specific, you'd have to show your code to a TA at office hours where they can better fix specific problems. Student1594


When i try to use MovieMaker, and hit create movie, this appears on the black window:
java.lang.OutOfMemoryError

???
Close JES and any other programs you're running. If that doesn't work, try restarting your computer and running movie maker fresh. If that doesn't work, then try it on someone else's computer. If that doesn't work, then it could be that your pictures are just way too big or there are too many of them. -Student1680

The only problem I am having is modifying the code below so that it copies my entire image onto the canvas. last time you defined the target as static and copied down, and the source could be defined from 1 to the other bound. This time I either get out of bounds exceptions or it doesn't copy the whole image. Any help?

sourceX = 1
    for targetX in range(frame*3,frame*3+((200-45)/2)):
      sourceY = 45
      for targetY in range(frame*3,frame*3+((200-25)/2)):
        color = getColor(getPixel(image2,int(sourceX),int(sourceY)))
        setColor(getPixel(canvas,targetX,targetY), color)
        
        sourceY = sourceY + 1
      sourceX = sourceX + 1

First make sure you're copying it to pixels that exist within the size of the canvas. Then get rid of all the 200-45/2 and 200-25/2 stuff and replace those with getWidth(image2) and getHeight(image2) -Student1680

I typed my code in like the one above and it keeps saying I have a spacing error for most of the lines. What am I doing wrong?
When it says "spacing error" there's a 90% chance that you dropped parenthesis somewhere. Can't tell you REMOVED than that without actually looking at your code. -Student1680

im working on a chromakey function and it runs and then when it is complete it says <media.Picture instance at 15092351>. what does that mean...(its not showing the picture or anything).
It means it worked. Try setting your call to chromakey equal to something and then show that. -Student1680

def logRect(fnum, canvas):
  addRectFilled(canvas, 3*fnum, int(290)* log(1+ fnum/100.0), 50,50, blue)
  return canvas


im trying to run the above function and Jes tells me that i got tried to call a function with a parameter of invalid type? but i cant see any errors. please help!
log returns a decimal. Attempting to get the pixel at decimal coordinates is Bad. Extend your int to the rest of your y coordinate expression. -Student1680

(code removeded)
this is my program that i wrote but i cannot figure out how i can incorporate the function moveahead, without the big function going through the frames 50 x 50 times, bc it goes though the big loop of fifty frames, and then it goes though another 50 loop for each frame?
You need to figure out how to factor out the common code between them and combine the "guts" of it under one for loop. I also removed your code. Please only post bits and pieces when you ask a question, but not the whole shebang. -Student1680

I was wondering if our third thing in our movie which can be our choice can be some type of text that goes across the screen or can it only be an image?

Text is fine. -Student1680

what does this mean?
Was unable to load the image in C:\Documents and Settings\mike buzaki\Desktop\ball.jpg
Make sure it's a valid image file.
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.

Do you actually have a file called "ball.jpg" on your Desktop? -Student1680
Yes, he did. came to office hours. it was a really odd error at first. but anyways, that part is fixed :) Student1919

I'm trying to copy an image onto a canvas, and I'm writing a function virtually verbatim from the book to do it, but I keep getting the same error message: – I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 11 of C:\Documents and Settings\Zhugs546\My Documents\hw3_5.py –

But line 11 is straight from pg. 83 in the book. What does this mean?
Are you using the same pictures that the book is? If not, check to make sure you're getting pixels on an area of the picture that actually exists Student1919

How can you write a function within a function? I wrote this function here to test it out, and nothing changes in the result.
"""def slowsunset(directory):
canvas=makePicture(getMediaPath("beach-smaller.jpg"))
for frame in range(1,100):
makeREMOVEDnset(canvas)
framenum=str(frame)
if frame 10:
writePictureTo(canvas,directory+"//frame0"+framenum+".jpg")
if frame >=10:
writePictureTo(canvas,directory+"//frame"+framenum+".jpg")
def makeREMOVEDnset(picture):
for p in getPixels(picture):
value=getBlue(p)
setBlue(p,value.95)
value=getGreen(p)
setGreen(p,value.95)"""

I don't understand your question. Looks like it should work fine, and you say it works fine? Student1919
Nothing is changing because you're only writing out one frame. You need to have your frames written out inside the frame for loop. Then you should notice the canvas getting sunset throughout the frames. Student1594


Where is the spacing error here?
 if framesDone < .4:
   x=getWidth(butterfly) * (.5-framesDone)
   y=getHeight(canvas)-(getHeight(butterfly)-2) 
   addText(x + 5, getHeight(butterfly) + 5, 'look at the butterfly')

it could be before this section of the code. It also might not even be a spacing error at all (JES is funny like that). Look at portions of your code before this and see if there are any errors. Student1919

How do we test our function/program to know that it actually works?
first, setMediaPath() in the bottom part to wherever all of your pictures that you use are. Then call hw3(r"c://amandascomputer/frames")...the input there is a directory where all of your frames will be written out to. Your code should then run and you can see all the frames in that folder you told JES to write to. Student1919

i'm getting really confused w/ all this directory talk..when you say "a directory where all of your frames will be written to", are we supposed to create a folder for the frames? also, i'm also having a problem w/ the following function:

framenum=str(num)
if num 10:
writePictureTo(framepict,directory+"//frame0"+framenum+".jpg")
if num >= 10:
writePictureTo(framepict,directory+"//frame"+framenum+".jpg")

I know they discussed this above, but mine is still giving me the same 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.) where in this whole function do we actually define the directory?
For the directory, yes you should create a folder to store your images in. The filepath to this folder, "C:\etc" should be the input to the function representing the directory. Your error message is telling you that one of your parameters is wrong. REMOVED num,framepict, and directory. In your code, what do these things mean? Try adding a print num,framepict,directory line in your code right before the framenum= line. See what these variables are representing. That should give you an idea as to what is going wrong in the code. Student1594

Can the hw3 function take in parameters in addition to a directory? REMOVEDch as a string for addText.
No, you should write the string inside the function. Your hw3 function should only take one input. Student1594

The instructions say to submit the assignment via JES. Should this read "via WebWork?"
Yes, you should submit via Webwork as you do for all your assignments. That's a typo from a previous semester. Sorry. Student1594

For my composite picture, I want it to come in at frame 21, so I set the range as range(21,41). At the end, when i do writePictureTo(), I put in my if frame<31 and if frame>=31. It's only giving me the first 10 frames. and my image isn't showing up on there. how can i fix this?
It's difficult to say without seeing the whole function you've written. You should email a TA or visit office hours where they can be REMOVED helpful. One thing that may be wrong: you should only have one loop that says for frame in range(1,41) and inside it you should have if statements to determine if a picture is added later, like if frame>20 or something. Student1594



that's my function i'm trying to write out.
i'm writing seperate functions and piecing them together at the end. do i need to combine it all into one?
Please do not post all of your code here. This can be discouraging to students who would like to not see the answer before they start coding. If you need a TA to look at all your code, go to office hours or send your TA and email about it. Student1594


Is it chill if we use .gif files or will they not work?
They will most likely not work. JES only works with .jpg files. Student1594


def hw3(r"C:\Documents and Settings\sunny\My Documents\My Pictures\hw3"):
for frame in range(1,41):
canvas=makePicture(getMediaPath("bluesun"))
is this right?
No, there should be a variable that is taken into the function, you don't actually want to hardcode a path in there. Then it won't work on our computers :) Student1919

I'm trying to make two objects move at once, and I'm following the book exactly except for the number of frames. Here's a snippet of my code:

    if frame >= 20:
      addRectFilled(canvas, (50-(frame-50))*10, (50-(frame-50))*5, 50, 50, white)
    blueX = 100+int(10*sin(frame))
    blueY = 4*frame+int(10cos(frame))
    addRectFilled(canavs,blueX,blueY, 50, 50, blue)


where the blueX and BlueY are all aligned with a different box from the first addRectFilled line - however I keep getting this error message:
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.

the page I'm looking at is 276.

How can I fix this?



I fixed it
Excellent Student1919


do i need to be writing this all as one function, or do it like the collage and make separate ones and then combine them?
Separate Student1919

I get that we have a seperate directory to put all our frames in...and I have folder on my destop, I just can't remeber how to set up the directory so to speak. Like, how do I get JES to recogize my filepath to my particular directory. What do I put in command area of JES to make it recognize my directory? Is there somewhere in the book I can find this, because I could not find any info under the "directory" pages from the index. THANKS!!!
assuming you're using windows, you will put in an r then quotes then your directory then close your quotes. Or, you can do what the below student said :) Student1919

im not a TA, but i would recommend doing something like this:

>>> directory = pickAFolder()
>>> hw3(directory)

Thanks. Student1919

For some reason my Movie Maker is not working, I've tried to use QuickTime but that won't work either. Any suggestions?
It's not too important to get movie maker to work. did your frames all write out and you can see them? If so, then no worries Student1919

The last line (line 14) of my program is:
writeFrame(frame,directory,framepic)
And I keep getting this error:
"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.
Please check line 14 of C:\Program Files\JES\experiment hw3"
What's wrong? "writeFrame" isn't in blue in the program area... does that mean it isn't recognized as a function by JES, which could explain the problem?
Never mind; I found the problem.

what does it mean if my moving image isn't showing up on the frames? i try to change variables, but i'm not sure which ones to change exactly
Change the x and/or y coordinates when you copy something over. Student1919

def copy(pic, bg, x, y):
    for p in getPixels(pic):
        color = getColor(p)
        setColor(getPixel(bg, x+getX(p),y+getY(p)),color)


It's giving me this message whenever I hit Load:
>>> There was a spacing error in the program.
It might be from a previous line, but I think the error is in line 16

What am I doing wrong?


Like the error says, it could be in an earlier line. REMOVED the function that calles this copy function and make sure you're calling it correctly. Student1919

here is my code, i keep getting an out of bounds exception:

for targetX in range(frame3,getWidth(guitar)):
sourceY = 25
for targetY in range(frame3,getHeight(guitar)):
color = getColor(getPixel(guitar,int(sourceX),int(sourceY))) this is the problem line
setColor(getPixel(canvas,targetX,targetY), color)
sourceY = sourceY + 1
sourceX = sourceX + 1

i know there was problem like this above, but i can't figure this out! help!
What is the error? I'm guessing you're getting an out of bounds error. Is "guitar" wider than the number of your frames x 3? Also, did you start your sourceX before the loop? That's very very very important. Student1919


I think I have a problem...JES keeps telling me that my code has a spacing error every time I try to load the function. But no matter how I move the code around, it says that the same line still has a spacing error. When I got mad and spaced the code wrong on purpose, JES didn't give me an error message until I tried to run the function, not when I tried to load it. What can I do? I feel it will not be in my best interest to turn in non-working code, even if the code seems right.
REMOVED and see if there's a syntax error or you've defined all of your variables. It might not be a spacing problem that is messing JES up. It gets confused sometimes. Student1919

I'm having the same problem as 2 questions above about the line

color=getColor(getPixel(cat,int(sourceX),int(sourceY)))

please help!
Tough to say w/out seeing the rest of your code. E-mail/IM a TA for REMOVED specific help. Student1919

When I run my program, i just get a list of all my frames 1-99, and I don't see any animation...what am I doing wrong?


does the last line of our function have to be "writeFrame(frame,directory,framepic)"?
also, should we use show(canvas) and return canvas?

I have tried several times to fix this code...
def hw3(folder):
  maxframes=100
  butterfly=makePicture(getMediaPath('butterfly.jpg'))
  canvas=makePicture(getMediaPath('blueShrub.jpg'))
  for frame in range (1, (maxframes + 1))
   framesDone=(0.0) + frame)/maxframes
   for x in range (1, getWidth(canvas))
    for y in range (1, getHeight(canvas))
     if framesDone < .4:
      x=getWidth(butterfly) * (.5-framesDone)
      y=getHeight(canvas)-(getHeight(butterfly)-2) 
      addText(x + 5, getHeight(butterfly) + 5, 'look at the butterfly')
    elif .4 <= framesDone >= .8:
      x=getWidth(butterfly) * (.9-framesDone)
      addText(x + 5, getHeight(butterfly) + 5, 'fly, butterfly, fly')
    elif framesDone > .8:
      x=getWidth(butterfly) * (1-(framesDone/2)
      addText(x + 5, getHeight(butterfly) + 5, 'poor butterfly')
    copy(butterfly, canvas, x, y)
    filename='frame' + '0' *(len(str(maxframes))-len(str(frame))) + str(frame)
    writePictureTo(canvas, folder + '//' + filename + '.jpg')


At first, JES says that there was a spacing error in line 8. Every time I moved the code, the next line would have a spacing error. After I took out all the spacing, it said that line 5 is not in legal jython. After a change that line, the spacing error comes back and the whole thing repeats. Can anyone tell me what is wrong with this code? I'm really confused....
Umm..I'm not a TA, but I noticed that {framesDone=(0.0) + frame)/maxframes} should look like this–> framesDone=((0.0+frame)/maxframes). Or couldn't you just have (frame/maxframes)? Why the 0.0? Also, make sure you put a semicolon after {for frame in range (1, (maxframes + 1))}. And then you lost me on all that other stuff...hope that helps! -Mary Beth

Are we supposed to be using MovieMaker somehow? I'm so lost.


– for targetX in range(frame, frame+((200-45)/2)):
sourceY = 25
for targetY in range(frame, frame+((200-25)/2)):
color = getColor(getPixel(bridge, int(sourceX), int(sourceY)))
setColor(getPixel(canvas, int(targetX), int(targetY)), color) Error: this should not happenError: this should not happenError: this should not happenError: this should not happenError: this should not happen–

Why do I keep getting an error from the denoted line (Error: this should not happenError: this should not happenError: this should not happen) saying that an "out-of-bounds error has occurred"?


Okay, just imagine that the above function snippet is spaced correctly in JES - as this page sort of threw it off.

My function works, but every time I run it, only frame 40 shows up in my directory. I believe the problem is that the frames are saving over each other so only frame 40 is left. How do I fix this problem?

I wrote this code:

def copy(fg, bg, tx, ty):
  tx=int(tx)
  ty=int(ty)
  bgcolor=getColor(getPixel(fg, 1, 1))
  target=getPixel(bg, getX(pixels) + tx, getY(p) + ty)
  for pixels in getPixels(fg):
    if distance(bgcolor, getColor(pixels)) > 20:
     setColor(target, getColor(pixels))


I get an error that says I used a variable before defining it. I thought all the variables were defined within the function.....I can't see what's wrong.

How long would it take for me to run this assignment on average? Some minutes? Some hours?

I dont think we have to use MovieMaker, the program is just so you can turn the frames you made into a quicktime file or etc...so that it can be watched in a media player