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

Fall 2006 Homework 6 questions page

Post Homework 6 Questions here:

def chromakey(canvas, sprite):

  chromacolor=makeColor(24,244,18)

  for p in getPixels(sprite):
    spritecolor=getColor(p)
    spritex=getX(p)
    spritey=getY(p)
    
    if distance(spritecolor,chromacolor)>10:
      canvaspixel=getPixel(canvas,spritex,spritey)
      setColor(canvaspixel,spritecolor)

  return canvas



I have a question with the above code: it is plainly clear what is going on, but it simply won't work. I've spent too long on this problem.
Can anyone help me?



sprite[0]=makePicture(dir+"//1.gif")


this gives me an error. why can't i put the picture object into a list? :(
do i need an object-friendly list?
please answer
ok, so not to pick on you are anything but we (TA's) are students too, so please be patient. Now to answer your question - a few things to help you out are as follows:
-remember when you learned about lists you were also learning about strings? So, in a way you can only have a list of strings, but before you think, "Oh, crap!" or , "BS! *", think about the process you go through to make a picture:
-1. define the location of the picture:
- ex:
dir+"//1.gif"

-2. Make the actual picture
- ex:
makePicture(partfromstepone)

- ok so making the list more "object friendly", which of the steps above is the proper input for a list (ie which one is a string)

Now the other problem you need to correct is the whole making the empty list business. I'm not gonna tell you exactly how to do it, but I will tell you that you are doing it wrong. Also, for guidance refer to the readings/slides for strings and lists - how does that code make an empty list and add stuff to it?
* BS = Barbara Streisand Toni Walden |


thanks toni walden you are F****** sexy
* F = fancifully


iMovie Ken Burns all the photos when I drag the folder into it. ImageReady is probably better/simpler even though it's slow on Intel Macs. Robby Thrash

How do you recycle sprites through a list?
There's a nifty little operator called "mod" (represented with a "%") in JES that returns the remainder. for example, if I typed 4%5, it would return 4, and if I typed 11%5 it would return 1. This is VERY helpful when cycling through a list...especially if you are doing it where its dependent on something like...i dunno...frames? hinthint ;p Toni Walden

can JES recognize picture files other than .jpg, or do we need to convert .gif and .png files to .jpg?
JES can recognize .gif, .png, and .jpg Toni Walden

when using the sample code to copy background, i get this error message:

"x_end = getWidth(pic) - w"
getWidth(picture): Input is not a picture.
An error occurred attempting to pass an argument to a function.

How would I fix this?

Well, JES is telling you that there is a problem with "getWidth(pic)", right? So, if JES says the input is not a picture....then fix it by making the input a picture. Toni Walden

but I am putting in a picture file as an input.
I wrote a function called scrolly(pic,w,h)
and in the main function movieFun, I named a picture marioWorld and put in scrolly(marioWorld,400,300).
This is where I'm having trouble.
Remember, a picture is not the same thing as a file. Use makePicture to get the picture from the file. Colin Potts

I have a question. will the TA's be using their own background and sprites to test our code? or do we have to send our files their way for them to test? Im guessing its the latter.
You would guess right :) Toni Walden

Does the function really needto make the background white if you're going to cover it up with a panoramic picture? If I don't need it, I don't want to make JES do more than neccessary
The part about making the background white is and example showing you how to change the color of the entire canvas. In terms of this assignment, think chromakey (which is required) Toni Walden

okay so basically my question is, if I write
bg = makePicture("C:\Documents and Settings\Kiddo\My Documents\CS1315\JES\My Images HW6\super mario for hw6.jpg")
one = makePicture("C:\Documents and Settings\Kiddo\My Documents\CS1315\JES\\My Images HW6\mariowalking1.jpg")
when I turn in my code, how will my TA be able to access my photos? what should I do about that?
See above, and Bobby's comment below Toni Walden

is the media path the input directory? the directions don't say the TAs will be using setMediaPath. OR do we have to put setMediaPath in our function?
Don't use mediapath at all. Use the directory parameter for everything. It'll look something like this.
pic = makePicture(directory + "//pic1.jpg")
.....
.....
.....
writePicture(canvas, directory + "//frame" + str(frame) + ".jpg")
- Bobby Mathew

if int(frame)%(2) = 1:

whats wrong with this line?
There should be 2 = signs since your checking for equality. - Bobby Mathew

Bah...I see contradictions!!1!!11 Toni says use getMediaPath, but Bobby says don't use mediapath at all! Help ma!
Sorry, I made a whoops! Go with Bobby's :) Toni Walden

thanks for the clarification.

It doesn't really matter whether you use mediapath or not. We've allowed both in the past and that still stands. I think it would be easier to just use the directory parameter for everything. You can use media path if you really want to. - Bobby Mathew

so regardless of if we use mediapath or not we are still turning in our code with the sprites and background we used right?
Right Toni Walden

Um I don't want to buy quicktime pro and Movie Maker keeps giving me errors and the link on t

if we used sprites from the folder should we resubmit them?
For some reason i'm only getting one line of pixels on the left side of my frames. I think i've made an error in my function, but i'm not sure where to edit it. If there are any suggestions, I would greatly appreciated it. thank you!
 def makeBackground(canvas,bg,start):
  bgX=1
  for x in range(1, getWidth(canvas) + 1):
    for y in range(1, getHeight(canvas) + 1):
      bgY=1
      for y in range(1, getHeight(canvas) + 1): 
        if bgX < getWidth(bg) and bgY < getHeight(bg): 
          pixelOne=getPixel(canvas,x,y)
          pixelTwo=getPixel(bg,bgX,bgY)
          color=getColor(pixelTwo)
          setColor(pixelOne,color)
        bgY +=1
      bgX +=1
    return canvas

The first thing that occurs to me, without inspecting or testing your code closely, is that the return is inside the inner loop. If you remove both levels of indentation from the return, it will not occur until after both loops have completed. Colin Potts

If we used sprite's from the folder should we still submit the ones we used?

I just can't get the chromakey to work...either it keeps all the green pixels, or it ends up not copying other parts. I use the distance thing, as well as just checking for green and blue...but for all the things i've tried, it just produces one of those two results. Fyi, I'm using the Yakko walk images and the mario background.
def sprite(canvas,sprite):
  for p in getPixels(sprite):
    scolor=getColor(p)
    sx=getX(p)
    sy=getY(p)
    if distance(scolor,makeColor(0,255,0)>10:
      setColor(getPixel(canvas,39+sx,152+sy),scolor)

I added the extra close parenthesis in the distance function so that this code now works. Then I tested it with flower.jpg as the sprite on santa.jpg as the canvas. Since the flower has a white background rather than green, I changed your 0,255,0 to 255,255,255. So the logic of your code is unchanged; I just made these changes to see whether you chromakey works with other images....... And it does. Perhaps you just need to tweak the numbers?! Is the Yakko background really within 10 of 0,255,0? Colin Potts

My code comes back with an error when I try to run it, saying "I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured" I really don't know how to fix this. The line that is highlighted is the the line with pixBack= . It's not that the background isn't a picture, since I define that earlier in the code. And... yeah. I feel stuck.
def addSprite(sprite,backround,x,y):
  for p in getPixels(sprite):
    x=x+getX(p)
    y=y+getY(p)
    pixBack=getPixel(backround,x,y)
    color=getColor(p)
    if distance(color,makeColor(0,255,0))>0:
      setColor(pixBack,color)

The problem is with the values of x and y that you are giving when you call addSprite. You are trying to add the sprite outside one of the edges of the picture. Make sure that x > 0 and x getWidth(pic) before you call addSprite (and similarly for y and getHeight). Colin Potts



My code works, however my frames load into my directory very slowly(one every 11 seconds).

Is this normal? If not, how fast should they load?
That's reasonable. When testing your program you can either just generate the first three or four frames by editing the range you put in the range for loop. Or you can leave the code unchanged, twiddle your thumbs for a an estimated one minute, and stop the program. It should have generated five or six files by then, which is enough to judge whether it is working. (If you change the range statement, remember to change it back to the full value before submitting!) Colin Potts

how do we organize our sprites? for now I have 7 animations for my sprite and the first one is sprite=makePicture(getMediaPath('whatever.jpg')
and the following sprite animations are sprite=makePicture(getMediaPath('somethingnew.jpg') so what do I do with they sprites what does a list look like?

I'm having the same problem with the OutOfBounds error (java.lang.ArrayIndexOutOfBoundsException has occured). Here is my code...


def putSprite(background,sprite,x,y):
for p in getPixels(sprite):
x=x+getX(p)
y=y+getY(p)
p2=getPixel(background,x,y)
color=getColor(p)
if distance(color,getColor(getPixel(sprite,1,1)))>=15:
setColor(p2,color)

There error is the line p2=getPixel(background,x,y)
I think I'm confused on what I need to do to fix this. Help please!!
You're trying to access a pixel that doesn't exist, because your x or y value (or both) is too large. So the real error is somewhere else, either the preceding two lines where you increment x and y in the loop, or in the calling function that passes in x and y values. Work out what values you think x and y should have and test to see what they really are by inserting a printNow line inside the loop or by using the watcher. Colin Potts

im having the same problem as the other tow people. When i try to run i get the 'The error java.lang.ArrayIndexOutOfBoundsException has occured' i understand what your saying about out of the edges of the pic but ive tryed to change it and it still won't work. How do i know what the imputs should be.
def copy(bg, src, x, y):
  for p in getPixels(src):
    tx= getX(p) + x 
    ty= getY(p) + y 
    if 1 <= tx <= getWidth(bg):
      if 1 <= ty <= getHeight(bg):
        tp= getPixel(bg, tx, ty)
        color= getColor(p)
        if distance(color, white) > 0:
          setColor(tp, color)

then i call it as
copy(bg, mariobackground, 10 - frame2, 10)




How do I convert the .wmv file to a .mov file to put it in the gallery?
That's fine. Upload the wmv file and we can view that. Colin Potts

Kind of a creative question, do we have to have the background moving in ALL the frames? For example, I wanted to have a character stand and do something first before heading off to wherever.
That sounds cool. In the interest of Art, bend the rules. Colin Potts

How exactly is the distance function working to set the threshold for the green values of the sprite? I try all sorts of values for the distance from the sprite color value and the threshold, but the picture ends up not using the chromakey, or it copies everything but the white.
I suspect that the background of the sprite that you are using isn't really green (i.e. 0,255,0). Say the sprite picture object is called sprite; type 'print getColor(getPixel(sprite, 1,1)) in the command area to get the color of the top-left pixel of the sprite. It will probably have a bizarre value such as 30,230,40. That color looks green to humans but is more than five color values distant from 0,255,0. Use whatever that combination of RGB values is in your chromakey code as the target color. Colin Potts

it is ok to use getMediaPath() right? Im sure u TAs won't mind doing >>>setMediaPath(), before dir=pickAFolder() and movieFun(dir)...surely u TAs don't mind that extra step right? >_'

def putSprite(sprites,canvas,x,y):
for p in getPixels(sprites):
color=getColor(p)
p2=getPixel(canvas,39+x,152+y)
if distance(color,makeColor(255,0,255))>10:
setColor(p2,color)

When i run movieFun(directory), it says the error is where getPixel is and input is not a picture.

but, I already said canvas=makePicture(getMediaPath("mariobg.jpg")), so what else could cause this problem???
Send me your code. Let's see if we can't get this fixed well before midnight. Colin Potts

and also...getPixel(canvas,39+x, 152+y), what do 39 and 152 mean exactly?
I don't know. These are magic numbers copied from example code. They are x and y offsets representing the size of a sprite, but the sprite you are using may be bigger or smaller. It would be safer to add getWidth(sprite) and getHeight(sprite) Colin Potts

should we include the background picture?

should we include the background picture?
Yes, the assignment isn't clear about this. Just don't include the movie or generated frames. Colin Potts

yeah, i have the same problem with my chromakey function. it keeps saying that the input isn't a picture even though i've already said it's a picture AND copied it as a picture!
Send me your code. Let's see if we can't get this fixed well before midnight. Colin Potts

k1=makePicture(getMediaPath("knuckles1.jpg"))
. . .
for i in range(1,10):
slide=makeFrame()
y=15i
copyMeBG(bg,slide,1000,y)
copyMeSprite(k1,slide,)
chromakey(k1,slide,bg,i)
writePictureTo(slide,directory+"/frame00"+str(i)+".jpg")

def chromakey(pic,slide,bg,i):
sprite=makePicture(pic)
for x in range(50, 50+getWidth(sprite)):
for y in range(15, 15+getHeight(sprite)):
p=getPixel(slide,x,y)
color=getColor(getPixel(bg,x+1000,(15i)+y))
if (getRed(p)+getGreen(p)getBlue(p)):
setColor(p,color)
return slide

hmm, i think it may be because the computer i'm using took all the pic files from my jump drive and made them "photo album 6 photos" instead of keeping them jpegs. i'll switch computers and see if that works.

how do you make your frames into a movie??
The cheapest way is to use MovieMaker. You can download it from the CoWeb software site. Wait.... didn't you have to do this for your movie homework?? Colin Potts

YAY!! SWITCHING COMPUTERS HELPED!!!
Kudos to you for thinking outside the box and fixing this yourself! Colin Potts

java.lang.ArrayIndexOutOfBoundsException...I cannot seem to fix this, someone please help.

I'm having the same problem "the error java.lang.ArrayIndexOutOfBoundsException has occured" I know its been touched on above....but I can't seem do figure out how to fix it..please help :(
This is almost certainly happening because the x and y values you are providing to a picture function such as getPixel are bigger than the bounds of the picture so JES is trying to obtain a pixel that doesn't exist. You will have to work out how big the picture is and make sure that the x and y are no bigger than the width and height respectively. This has been "touched on" many times over the past few weeks ;) Colin Potts

no, we didn't have to use moviemaker for the other homework. we just had to turn in all the slides that the program produced. i'm trying to use moviemaker right now but every time i put a picture in the storyboard it thinks it's a clip and makes each one stay there for 10 seconds.
OK. OK. I'm not sure what Storyboard you are referring to. (Is this a similarly named commercial product??) With Moviemaker as downloaded from the Coweb (software page) do the following. You should already have a folder containing your frames as jpgs. The files should have been named by your program so that the alphabetic ordering of the file names corresponds to the ordering of the frames in the movie. Run Moviemaker and tell it which of the frames is the first and then which is the last. These are two fields in the same dialog box. Then tell it where the movie file should go. Add the .mov extension. Finally, when prompted, you need to tell it the frame rate. 16 is a good choice. If you double-click on the resulting .mov file, it should open in your default movie viewer (e.g. Quicktime). BTW, you don't need to make the movie for this homework either. This is for extra credit. Colin Potts
An additional hurdle for Mac users: the Mac version of Moviemaker won't run by double clicking on its icon. Instead, open the terminal application (in the applications/utilities folder). Suppose you downloaded Moviemaker onto the desktop. There should be a folder there called MovieMaker. In the terminal window type the following:
cd Desktop/MovieMaker
and then run Moviemaker by typing (punctuation and all):
/.MovieMaker
Colin Potts|

yea...if anyone figures it out, please help your fellow classmates...

windows movie maker is stupid. the help thing doesn't even help at all. :( i am saddened.

When I run my code, the only think that shows is the top of the background and a tiny-tiny green pixel. Any idea as to what may be happening?

yup...still cant figure it out the error java.lang.ArrayIndexOutOfBoundsException...still trying though

gah! i finally got it to semi work, but it's taking forever to load to the gallery page!!!

How did you do it? could u share maybe just ur scrolly function?

for the error java.lang.ArrayIndexOutOfBoundsException I tried getWidth(canvas)-x and the same for y and it got rid of the error message...but my code still is not working!:(

yeah, i went into the properties or something and changed the picture view time to the lowest it would let me put, and did the automovie thing.

could u explain a bit more, like where exactly to use getWidth(canvas)-x and getHeight(canvas)-y?

colin–i think a lot of us have been using windows movie maker, which sucks. i'm on a library computer (arch library, actually) and only downloaded JES on here, none of the extra stuff.
Ah. Well, the course program also known as MovieMaker should be identical – once it starts running – for both Windows and Mac since it is written in Java. But if you don't have that on a library computer, why don't you take a break and do this with your own software somewhere else tomorrow? We can still view your art on the gallery even if you upload that late. Just make sure you submit the required code and sprite/background files tonight. Colin Potts

def scrolly(pic, destination, tx, ty, frame):
  targetX = tx
  for x in range(frame*5+1, frame*5+200):
    targetY = ty
    for y in range(1,getHeight(pic)+1):
      source = getColor(getPixel(pic, x, y))
      dest = getPixel(destination, targetX, targetY)
      if distance(source, makeColor(255,0,255)) > 50:
        setColor(dest, source)
      targetY+=1
    targetX+=1
  return(destination)


it keeps saying the error occurs where dest = getPixel(destination, targetX, targetY). What exactly is wrong?
You're incrementing targetX and targetY in the loop, and eventually one of them must be getting larger than getWidth(destination) or getHeight(destination). You could guard against this happening by putting inside an if block the three lines that start with the one with the call to getPixel. The if should be 'if targetX < getWidth(destination) and targetY <getHeight(destination). This probably will not make your code work correctly but since the results will now be visible, you will be better able to work out why the x and y values are wrong. Colin Potts


Folks, there is a program called "Windows Movie Maker" that is free from Microsoft and available on new computers. That's what we mean by "Movie Maker." The one which is one your CD is flakey. For Mac users, I recommend either buying Apple QuickTime Pro, which can turn any image sequence into a movie, or using iMovie. Mark Guzdial


ok thank you, I finally figured out my error.

Can someone please explain to me why I am getting the following error message: An error occurred attempting to pass an argument to a function.
Please check line 5 of C:\Documents and Settings\Owner\My Documents\hw6.py.

Here is a piece of my code (line 5 is the oxford = ... line)

def movieFun (directory):
  for frame in range (1,101):
    canvas=makeEmptyPicture (400,300)
    addRectFilled (canvas,1,1,400,300,white)
    oxford = makePicture (getMediaPath ("OxfordPanorama2.jpg"))


Thanks!
If you have setMediaPath incorrectly so that the directory doesn't contain OxfordPanorama2.jpg, the call to makePicture on that line would give this error. Above the "An error occurred" line in the same error message, you should also see "There is no file at..." Colin Potts

I have the setMediaPath to the JES Media Sources file where I saved the picture. I tried saving the pic to a different file but still same result. Not sure what the problem is...

different directory, not different file...
OK then. Strategy A: Just cut and paste the entire path name into the makePicture call and get your animation working. Worry about the path problem later. (Not too much later....) Strategy B: Get to the bottom of this. If you have set the media path correctly, you should be able to replace "OxfordPanorama2.jpg" with "santa.jpg" or some such. Does that work? Strategy C: Set media path again. You never know. Colin Potts



Link to this Page