 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Fall 2003 Homework 2
Got a question on HW2? Put it here!
Check back often to see others' questions and answers.
How do I mirror the entire image vertically? I chose getWidth(source) as my mirrorpoint, is that right?
| Normally, we stick new questions at the bottom. To mirror the image vertically, the whole thing, you want your mirrorpoint to be getWidth/2. Mark Guzdial |
First, when I try to manipulate my image, each manipulation will affect the previous results. So if I greyscale my image, and then call a negative on it, it'll negative the greyscale, instead of the original. As a workaround, I can get it to process the original by redefining it after each each manipulation. Is this acceptable? Second, my collage takes up only about half of the canvas. Would it be acceptable to crop the blank portion out of the image?
| Everything is fair here – reload your image as often as you need to. Crop whatever you want from your source, but leave the canvas alone. (You can't change its size, anyway. Mark Guzdial |
Quick question: it's ok to take copyrighted images from websites for homework, right? As long as you don't publish them or whatever?
Should my program have the writePictureTo function in it? It's what I used within to save my collage, but I don't necessarily want my TA to have it saved to his hard drive.
There's no requirement in the homework assignment that your hw2() function write your picture to a file. It would be convenient for us TAs to see your image when it's done being computed (i.e. including a show(picture) command inside your function would be nice) and you could also consider returning the picture that you create at the end of your function so that you have an easy way to write that picture to a file:
>> myCollage = hw2()
>> writePictureTo(myCollage, "collage.jpg") Stephen Voida |
For turnin - the TAs will already have the blank picture, so we just need to send our source pictures, correct?
| Turn in ALL the pictures your TA needs to grade the assignment. Student56 |
I lost my CD with the media sources folder and I cannot find where it saved on my hard drive. Can I get another copy from someone?
| You can download it (have a fast network connection!) from this zip file. I don't have any more CD's, but you can borrow one from someone in the class, or maybe your TA. Mark Guzdial |
How would you go about turning a picture less than 90 degrees? Would the code have to call upon geometry training? Student636
| It's actually more trignometry than geometry. Think about rotating each point, using sine and cosine. Mark Guzdial |
My question is much more elementary than the others. I need some guidance in getting started with the functions within functions, like if I wanted to negate my picture or clear the Blue. These two functions were examples in the powerpoint createCollage() function, but they must have been predefined. How do you change colors, etc.
| Take a look at the book – it shows the WHOLE file for the collage function, including where the other functions were in the file. Mark Guzdial |
sourceX = 1
for targetX in range(1,(getWidth(firstcassy)*2)):
sourceY = 1
for targetY in range(1,(getHeight(firstcassy)*2)):
color = getColor(getPixel(firstcassy,int(sourceX),int(sourceY)))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY = sourceY + (0.5)
sourceX = sourceX + (0.5)
This is one section of my hw2 function where I am trying to double the size of the photo and copy it onto my canvas. I keep getting the following error for the "color = getColor..." line:
I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 36 of C:\JES\Functions\Labs and Homeworks\hw2
| It means that your sourceX and sourceY have gone beyond the edge of the firstcassy picture. The problem here is that the width and the height are actually one MORE than the actual number of pixels in the image. Try changing your targetX and targetY loops like this: |
for targetX in range(1,(getWidth(firstcassy)-1)*2):
...
for targetY in range(1,(getHeight(firstcassy)-1)*2):
Mark Guzdial
happy=makePicture(getMediaPath("boyd_bonnie2.jpg"))
print happy
canvas=makePicture(getMediaPath("640x480.jpg"))
print canvas
#first pic
targetX=1
for sourceX in range(1,getWidth(happy)):
targetY=getHeight(canvas)-getHeight(happy)-5
for SourceY in range(1,getHeight(happy)):
color=getColor(getPixel(happy,int(sourceX),int(sourceY)))
setColor(getPixel(canvas,targetX,targetY),color)
tagertY=targetY + 1
targetX=targetX + 1
show(happy)
show(canvas)
return canvas
i cant seem to get this to load i cant load the line with color=getcolor
it tells me that 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.
| Look at the line above getColor(getPixel...). What is the difference between 'SourceY' and the value you are using in the getPixel command? That might solve your problem Keith McDermott |
I can't find the blank canvas on my JES folder. Where is it?
| It should be named '7inX95in.jpg' in your mediasources folder. Student56 |
ok so...how do i choose a mirrorpoint? just interpolate and find the write one? do i then need to have a different mirrorpoint for each of my 5 pictures? Ashley Coker
| Look at the mirrorpoints on the exam review question about the temple, and then look at the size of the temple picture (pixels by pixels). Think about how those numbers are related to the number of pixels (vertically and horizontally) and how you could simialrly change your picture. |
how do you mirror horizontally? it's not in the book
Just switch x and y, it's not hard - and it's on the lecture slides
# cropping, resizing, and copying fourthcassy to canvas
sourceX = 1
for targetX in range(1,((72-32)*(3/4))):
sourceY = 32
for targetY in range(getHeight(fourthcassy,((180-1)*(3/4)))):
color = getColor(getPixel(fourthcassy,int(sourceX),int(sourceY))))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY = sourceY + (4/3)
sourceX = sourceX + (4/3)
I keep getting the following error: There was a spacing error in the program.It might be from a previous line, but I think the error is in line 83. Line 83 is the last line of code I pasted. I really don't understand, because all the other images I have copied to the canvas have had the same spacing. #12
| Look at the other lines before that line 83 too. Rememberm, JES said it might be before line 83. Make sure your spacing, however you do it, is continuous on every line. |
| Which is line 83? It's not evident from this. From what's here, it looks like the FOR targetX is indented past the sourceX = 1 line, which is wrong – they should match. BTW, remember to add ".0" to some of those numbers if you wnat to get decimal values. Mark Guzdial |
Are we supposed to turn in the file created by the writePictureTo command?
#Second picture, puppy negated
negative(puppy)
targetX=254
for sourceX in range(1,getWidth(puppy)):
targetY=getHeight(canvas)-getHeight(puppy)-5
for sourceY in range(1,getHeight(puppy)):
px=getPixel(puppy,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
When running this part of my code I get this warning from jes,
I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 23 of C:\JES\hy2.py
It is referring to this line "cx=getPixel(canvas,targetX,targetY)"
Any idea what is wrong?.. I got this line straight out of the book..
| It means that targetX or targetY have gone beyond the width or height of the canvas. The book can't guarantee that that line will always work. You're incrementing targetY (but note: Not targetX. That's a bug) for the height of the "puppy". Mark Guzdial |
Ok, I figured it out, I resized my picture and got the program to run.. But I have one question in my code I have directions for four pictures when I run the program the original picture gets negated, removes blue, and decreases red, but for some reason shows nothing for the original picture.. Heres my code..
def hw2():
puppy=makePicture(getMediaPath("puppy.jpg"))
print puppy
canvas=makePicture(getMediaPath("7inX95in.jpg"))
print canvas
#First picture, at left edge
targetX=1
for sourceX in range(1,getWidth(puppy)):
targetY=getHeight(canvas)-getHeight(puppy)-5
for sourceY in range(1,getHeight(puppy)):
px=getPixel(puppy,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
Also, the images show up on the bottom of my canvas instead of the top any suggestions?
| Please read the FAQ on how to upload code to the CoWeb so that it's readable. (I just fixed it up.) This loop should copy the puppy into the canvas. Are you perhaps overwriting this picture in the next loop? If you're using the same targetX and targetY, you're copying one picture right smack on top of the previous one. The pictures are showing up at the bottom of the canvas because that's where you're putting them – look at how you're setting targetY. Mark Guzdial |
i have a quick question. i can't get the media path set correctly. whenever i try to set the media path the media sources, media sources comes up but all the picture files are not in there. so when i set that media path, i can't get to any of my pictures. however, when i just do pickAFile to get to the pictures it works. what's going on? and can i not set a media path for this hw?
| Certainly you can, but remember what setMediaPath and getMediaPath do. getMediaPath just takes the directory that you identified in setMediaPath and sticks it at the front of the filename that you input to getMediaPath. If your file is in a subdirectory, or not IN the media directory, it won't work. Mark Guzdial |
def hw2():
sunset= makePicture(getMediaPath("iceberg sunset.jpg"))
print sunset
canvas= makePicture(getMediaPath("640x480.jpg"))
print canvas
#Copy Image
targetX= 1
for sourceX in range(1,getWidth(sunset)):
targetY= getHeight(canvas)-getHeight(sunset)-5
for sourceY in range(1,getHeight(sunset)):
px= getPixel(sunset,sourceX,sourceY)
cx= getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
show(canvas)
return(canvas)
I am just trying to copy this image to the canvas and I keep getting this error, load image failed.
Picture, filename C:\JES\mediasources\640x480.jpg height -1 width -1
I wasn't able to do what you wanted.
The error java.lang.NullPointerException has occured
Please check line 12 of C:\JES\PY\hw2.py
| Try another picture, but it looks like you haven't run JES on this computer before, and that you have an old version of Java installed. Mark Guzdial |
Can anybody tell me what this error message means:
The error java.lang.NullPointerException has occured
| It's a low-level error inside of Java meaning that something seriously wrong has happened that shouldn't ever happen. Mark Guzdial |
def scale(pic, factor):
canvas = makePicture(getMediaPath("7inX95in.jpg"))
sourcex = 1
for targetx in range(1,int((getWidth(pic)-1)*factor)):
sourcey = 1
for targety in range(1,int((getHeight(pic)-1)*factor)):
color = getColor(getPixel(pic,sourcex,sourcey))
setColor(getPixel(canvas,targetx,targety), color)
sourcey = sourcey + (1/factor)
sourcex = sourcex + (1/facor)
show(pic)
show(canvas)
return canvas
Two problems.
1) run it by scale(pic, .5)
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.
Please check line 7 of C:\Documents and Settings\Sosebee\Desktop\CS1315\scale.py
2) run using scale(pic, 2)
error:
I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 8 of C:\Documents and Settings\Sosebee\Desktop\CS1315\scale.py
problem 2 I think it is because it is running out of bounds, but I tried teh -1 thing and it didnt work (same error) so I dont know how to fix it.
problem 1: I have no clue, the code is the same as it is in the lecture slides.
Student479
change color = getColor(getPixel(pic,sourcex,sourcey)) to color = getColor(getPixel(pic,int(sourcex),int(sourcey))) . That should solve both problems. Student480 |
def hw2():
pic = makePicture(getMediaPath("nemo.jpg"))
canvas = makePicture(getMediaPath("7inX95in.jpg"))
pic3=pic
negative(pic3)
show(pic3)
pic4=pic
greyscale(pic4)
show(pic4)
pic5=pic
sunset(pic5)
show(pic5)
pic6=pic
darker(pic6)
show(pic6)
def negative(pic3):
for p in getPixels(pic3):
r=getRed(p)
g=getGreen(p)
b=getBlue(p)
setRed(p, 255-r)
setBlue(p, 255-b)
setGreen(p, 255-g)
return pic3
def greyscale(pic4):
for p in getPixels(pic4):
r = getRed(p) * 0.299
g = getGreen(p) * 0.587
b = getBlue(p) * 0.114
lum = r+g+b
setColor(p,makeColor(lum,lum,lum))
return pic4
def sunset(pic5):
for px in getPixels(pic5):
gr = getGreen(px)
setGreen(px, gr * 0.7)
bl = getBlue(px)
setBlue(px, bl * 0.7)
return pic5
def darker(pic6):
for pix in getPixels(pic6):
color = getColor(pix)
makeDarker(color)
makeDarker(color)
setColor(pix,color)
return pic6
Alright, when this is run...First off you only see one picture at a time, if you want to see the others, you have to delete the show(pic#) of teh previous def. But my BIG question is...why when I run the program does it take the negative, then take the greyscale of that negative, then take the sunset of that greyscaled negative, then make that sunset darker.
note: I havnt put them on a canvas yet.
Student479
| You can only show a picture once. Renaming it doesn't change the base picture. That's why you can only see one at a time. If you did repaint() instead of show(), you'd see each update. (If you did makePicture repeatedly, you'd have different pictures.) Yes, you're doing the functions to the same picture. Mark Guzdial |
the "leftover" white area after a picture is sclaed...is there any way that I can remove that white area so that the picture only remains?
Student479
| You only see the white area because you haven't put anything else there. Check out the collages at Fall2003 HW2 Collages – you can see scaling without white areas. Just position the pictures where you want them. Don't want white there? Put something else there! Mark Guzdial |
i had a question before and you told me to try another picture and that I had not used JES on this computer before, but this is the computer that I have been using all along. I tried another picture but it still didn't work and I installed a new Java and it still didn't work I got the same error, I wasn't able to do what you wanted.
The error java.lang.NullPointerException has occured
Please check line 12 of C:\JES\PY\hw2.py
| Could you send me your code, please? What's going on on line 12? Mark Guzdial |
here is the code
def hw2():
sunset= makePicture(getMediaPath("iceberg sunset.jpg"))
print sunset
canvas= makePicture(getMediaPath("640x480.jpg"))
print canvas
#Copy Image
targetX= 1
for sourceX in range(1,getWidth(sunset)):
targetY= getHeight(canvas)-getHeight(sunset)-5
for sourceY in range(1,getHeight(sunset)):
px= getPixel(sunset,sourceX,sourceY)
cx= getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
show(canvas)
return(canvas)
| This might be wrong, but could the space in the file name (iceberg sunset.jpg) be the problem? Lauren Biddle |
I had asked a question earlier about why 3 of my 4 pictures where showing up but not my original picture and u said to see if the target x and target y were different.. well here is my first 2 sections of code.. could u hint at whats wrong.. I can't get the original puppy to show up.. it just has a blank space where it should be.
def hw2():
puppy=makePicture(getMediaPath("puppy.jpg"))
print puppy
canvas=makePicture(getMediaPath("7inX95in.jpg"))
print canvas
#First picture, at left edge
targetX=1
for sourceX in range(1,getWidth(puppy)):
targetY=getHeight(canvas)-getHeight(puppy)-5
for sourceY in range(1,getHeight(puppy)):
px=getPixel(puppy,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#Second picture, puppy negated
negative(puppy)
targetX=122
for sourceX in range(1,getWidth(puppy)):
targetY=getHeight(canvas)-getHeight(puppy)-5
for sourceY in range(1,getHeight(puppy)):
px=getPixel(puppy,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
i named the file iceberg sunset with a space in it.
| Look at your indentation – you're running the second set of copies inside the loop of the first set of copies. targetX and targetY are getting incremented at all kinds of weird places. Shift the second copy set of loops to the left two spaces. Mark Guzdial |
Are you allowed to use more than one image when making the collage?
| ABSOLUTELY! We say that in the directions – use as many images as you'd like! Mark Guzdial |
for targetX in range(45,(getHeight(pict)-1)2):
sourceY=1
for targetY in range(45,(getWidth(pict)-1)2):
color=getColor(getPixel(pict,int(sourceX),int(sourceY)))
ok i tried all of the other solutions on this page but my code still won't work i am getting an error on the color=getColor line:
color=getColor(getPixel(pict,int(sourceX),int(sourceY)))
i tried this - for targetX in range(1,(getWidth(pict)-1)2):
but it still didnt work. actually, it did work until i got all the way to -50, and then it only returned a portion of the picture... what do i do?
| What's the error? What the error SAYS is really important. In the current version of JES (what you have), getWidth is 1 MORE than the actual width. So it's possible to go one over. Mark Guzdial |
My program creates the collage, but I can not get a mirror of the image. I put the mirror function at the end like my other functions for changing the picture. Does anybody have any suggestions?
| What happens? What errors do you get? Do you call mirrorHorizontal() or mirrorVertical() on the canvas or on the input picture? You need to do it to the canvas AFTER you compose in the other pictures. Mark Guzdial |
The following code is the first part of my homework two. I keep getting the error message "I wasn't able to do what you wanted.
The error java.lang.NullPointerException has occured
Please check line 12 of C:\JES\HW2.py
Can you tell me why?
def HW2():
tiger=makePicture(getMediaPath("tiger i.jpg"))
print tiger
canvas=makePicture(getMediaPath("7inx95in.jpg"))
print canvas
#first tiger copy
targetX=50
for sourceX in range(1,getWidth(tiger)):
targetY=getHeight(canvas)-getHeight(tiger)-10
for sourceY in range(1,getHeight(tiger)):
tpx=getPixel(tiger,sourceX,sourceY)
cpx=getPixel(canvas,targetX,targetY)
setColor(cpx,getColor(tpx))
targetY=targetY + 1
targetX=targetX + 1
return canvas
| My guess is that targetX or targetY are wider or higher (respectively) than the canvas. What's the size of the tiger? Mark Guzdial |
I know we turn in ALL the images we haved used in our collage, but that does NOT include the "7inx95in.jpg", right?
When trying to find the height and width of the bank canvas all that is printed is:
Picture, filename C:\JES\7inx95in.jpg height -1 width -1
What does this mean and how do I find a place in the canvas to put my new picture?
| Hmm – sounds like your Java is screwed up. -1 height and width means that JES can't read the file. Try reinstalling JES or Java, or try a different machine. Mark Guzdial |
I can't get my collage to show. When I call the function in the command area, it begins working and NEVER stops. so i never get to see any kind of picture or the finished canvas returned to me. what am i doing wrong?
| Try using writePictureTo to save the picture to disk, then double-click on the picture. Maybe it's too big? Mark Guzdial |
The assignment says to turnin the resultant picture along with the code and other sources used. How do we turnin the resultant picture? Do we use writePictureTo?
How should I go about re-installing Java or Jes? The JES file is no longer on my CD. Do I need new one?
The file can't disappear from the CD – it has to still be there. Look in the "Win" directory. To reinstall Java, go to http://java.sun.com. But a couple things to try first:- Quit JES then restart it. Sometimes memory can get gunked up and quitting and restarting clears it out.
- Make SURE that you have a valid picture file.
Mark Guzdial |
Can I use the blank 640x480.jpg file as a canvas instead of the 7inX95in.jpg ? I have an idea for a collage that would work much better that way.
When I run my program, I create the four pictures (I haven't mirrored it yet), but the last one mirrors itself vertically. My program looks basically just like in the book, except with differnt things applied to the pictures. Any ideas of what could be causing this?
| Read your code. You're doing it – you should be able to trace your code and understand it well enough to figure out what you're doing. Remember that the book isn't making three copies of the same image, which is what you need to do for this assignment. Mark Guzdial |
def hw2():
beach=makePicture(getMediaPath("head_ocho.jpg"))
print beach
canvas=makePicture(getMediaPath("7inX95in.jpg"))
print canvas
#First picture, at left large
targetX=1
for sourceX in range(1, getWidth(beach)):
targetY=getHeight(canvas)-getHeight(beach)-5
for sourceY in range(1,getHeight(beach)):
px=getPixel(beach,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
#Second picture, beach rotated
targetX=100
for sourceX in range (1,getHeight(beach)):
targetY=getHeight(canvas)-getHeight(beach)-5
for sourceY in range(1,getHeight(beach)):
px=getColor(getPixel(beach,sourceX,sourceY))
cx=getPixel(cavas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
#Third picture, beach negated
negative(beach)
targetX=200
for sourceX in range(1,getWidth(beach)):
targetY=getHeight(canvas)-getHeight(beach)-5
for sourceY in range(1,getHeight(beach)):
px=getPixel(beach,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
#Fourth picture lighten the beach
lighten(beach)
targetX=300
for sourceX in range(1,getWidth(beach)):
targetY=getHeight(canvas)-getHeight(beach)-5
for sourceY in range(1,getHeight(beach)):
px=getPixel(beach,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
show(canvas)
return(canvas)
def mirrorVertical(beach):
mirrorpoint=int(getWidth(beach)/2)
for y in range(1,getHeight(beach)):
for x in range(1,mirrorpoint):
p=getPixel(source,x+mirrorpoint,y)
p2=getPixel(beach,mirrorpoint-x,y)
setColor(p,makeColor(getRed(p2),getGreen(p2),getBlue(p2)))
def negative(beach):
for px in getPixels(beach):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red,255-green,255-blue)
setColor(px,negColor)
def lighten(beach):
for px in getPixels(beach):
color=getColor(px)
makeLighter(color)
setColor(px,color)
i keep getting error with this, it actually highlights my canvas line
i dont see anything at all and i dont know what i did wrong
| WHICH canvas line is being highlighted? And what error message do you get? Your comment messages don't match your code, e.g., you say that you're rotating when you're not. Mark Guzdial |
Figured out the nullPointerException
If you're getting a Java nullPointerException, you're manipulating something that is NOT a picture. I just generated it myself, by opening a WAV file as a picture:
>>> badpicture = makePicture(getMediaPath("Elliot-hello.wav"))
>>> show(badpicture)
I wasn't able to do what you wanted.
The error java.lang.NullPointerException has occured
If you're getting that error, you're not actually manipulating a picture.
Figuring out hard errors
If you can't figure out your errors, you might want to go to "Options" in the "Edit" menu and choose "Expert" mode. That gives you longer, more detailed error messages.
Mark Guzdial
i cannot get my images to mirror horizontally. i mirrorhorizontal(canvas) just before i showed it. i defined mirrorhorizontal below my other functions. why will it not mirror?
| I don't know. Try using your mirrorhorizontal by itself from the command area. Does it work? Now trying showing the picture before the mirrorhorizontal – does that work? Put a show() inside of mirrorhorizontal – did that work? Track the problem down. Mark Guzdial |
Everytime that I try to run the program, I'm told to check line two that reads...
bug=makePicture(getMediaPath("insect.jpg"))
What am I doing wrong? Am I not setting up the media path right? What is the right way?
| You should setMediaPath() and then it opens a window. Make sure you go into the Mediasources folder and click on any of the files within the folder; then the window should close itself (kinda like when you do pickAFile()). Chack and make sure that is the way you are doing it. |
I have defined the negative () program below my hw2(), but when I run the entire program I get two copies of my original image. What are some possible solutions?
| Nothing to do with your negative(). Check where you're doing your copies. Mark Guzdial |
canvasf=getMediaPath("7inx95in.jpg")
canvas=makePicture(canvasf)
targetX=1
for sourceX in range(1,(getWidth(picture)-1)*2):
targetY=getHeight(canvas)-getHeight(picture)
for sourceY in range(1,(getHeight(picture)-1)*2):
color = getColor(getPixel(picture,int(targetx),int(targety)))
setColor(getPixel(canvas,sourcex,sourcey), color)
targetY=targetY+(1/2)
targetX=targetX+(1/2)
show(canvas)
return(canvas)
when i type this in, it says the line
color = getColor(getPixel(picture,int(targetx),int(targety)))
isn't defined...
can anyone tell me what's wrong?
| REMOVEDre: targetX is not the same as targetx. Capitalization counts in Python. Mark Guzdial |
Read the FAQ for how to get the spacing right - you have to use <html> and <pre> tags
def copytocanvas(pic,canvas,startx,starty):
sourcex = 1
for target x in range(startx,getWidth(pic)+1+startx):
sourcey = 1
for targety in range(starty,getHeight(pic)+1+starty):
color = getColor(getPixel(pic,sourcex,sourcey)
setColor(getPixel(canvas, targetx, targety),color)
sourcey = sourcey + 1
sourcex = sourcex + 1
show(canvas)
return canvas
Error:
There is something wrong with the text of the file you had me try to load. You may have not have as many closing parenthesis as opening parenthesis, or you may have tried to use a jython keyword (if, def, etc...) as a function. This cannot be done.
All I did was take out repaint pic on all of the defs except the last one and it gave me that error, it worked just fine beforehand.
Student479
| Geoff, please don't dump all your code up here! Send it to me or a TA via email. Your error is in the line color = in this function – you're missing a closing right paren ")". There is also an error in the FOR loop two lines above "For target x" should be "for targetx". Mark Guzdial |
In your code, how would you make sure that you are making changes to the original picture each time, rather than change upon change etc.? I have been refering to the code in the book and am not sure what exactly I need to add to it/change to make sure that it's changing the original each time. Thanks.
I am not positive, but I am pretty sure that you would do something like
def hw2()
pic = makepicture(getMediaPath("yourpic.jpg"))
sunsetpic = sunset(pic)
| That's right. If you want the original picture, use makePicture again to get a new copy. Mark Guzdial |
I am getting one of those:
the error java.lang.ArrayIndexOutOfBoundsException has occured
on line 72 (color = getColor...) of the above program of mine.
I know why it is doing it, it is trying to go outside of the possible "window" of my pic. But how do I get it to stop that. Can I do soemthing like:
for sourcex in range (1,getWidth(pic)+1):
for targetx in range (startx,getWidth(pic)+1+startx):
.....
Student479
| Yes you can do that if getWidth(canvas) getWidth(pic)+1+startx. Mark Guzdial |
targetX=200
for sourceX in range(1,getWidth(roomies)):
targetY=getHeight(canvas)-getHeight(roomies)-5
for sourceY in range(1,getHeight(roomies)):
px=getPixel(roomies,sourceX,sourceY)
line35 cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
It gives me The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 35 of C:\Documents and Settings\gte171v\My Documents\HW2
I tried subtracting one from my source x and source y and it still did not work..what should I do?
ashley
| You might want to open up the watcher in JES and then tell it to watch sourceX, sourceY, targetX and targetY. You can see if those values make sense to you. Odds are though that whatever picture it is that you are calling "roomies" is way too big to fit on the canvas Student189 |
So where exactly in your code would you insert makePicture again to get a new copy of the original? (After which line....)
ok i have a question
my code is all finished and works perfectly EXCEPT it wont return the picture to me (ahh, the frustration!)
its such a pain because i put...
show(canvas)
return canvas
...at the end of my code and it shows it but then if i try to pull up canvas again it doesnt exist. why isnt it returning properly?! thanks
| You might want to check to see if return need parenthesis or not Student189 |
| Did you give the return value a name? mycanvas = hw2() and then use mycanvas? Try printing what hw2() returns – is it a picture? Mark Guzdial |
| you can insert it wherever you like. |
def hw2() :
picfile = getMediaPath("yourpic.jpg")
pic1 = makePicture(picfile)
pic2 = makepicture(picfile)
and so on and so forth until you have as many as you need/want. So you would put it anywhere after you named your picture file. (like above) Student479|
ok i added in canvas = hw2() and then return canvas
now it is running the program infinitely and i had to close the program to make it stop
when i put in print hw2() it runs the program and then prints the file path of canvas with the height and width and all taht so its a picture it just isnt returning it
return (canvas) doesnt do anything different
| If you're setting canvas=hw2() in the Command Area, what does that have to do with returning canvas in the program? You might want to show your code to me (via email) or TA. I can't figure out what you're doing. Mark Guzdial |
i also have a quick question about the requirements
i took an original picture, reduced the red and blue in it, took the negative of it, and then changed a portion of it from the color orange to the color purple. is that good enough or since i altered the colors twice i need to do something else?
| As long as there are at least four pictures (one original and three mods), and it's mirrored, you're okay. Mark Guzdial |
How can I arrange my pictures to go vertically instead of across the page?
OHHHHHH (lightbulb flickers)
i put in canvas=hw2() as a part of my recipe i never thought of putting in in the command area !!! ok that worked just fine i uploaded my pic now to the collage gallery ty very much
I am having a trouble mirroring like alot of other people.. The original four pics come out with no problem.. but it does not mirror.. I get no error messages when i try to load the program.. I am trying to mirror bottom to top. Heres a sample of my code. Do i need to specify a location on the canvas to mirror onto?.. and how do i do that.. I Just assumed it would mirror along the mirrorpoint automatically.
#Fifth picture, mirroring
mirrorHorizontal(puppy)
show(canvas)
return(canvas)
and my mirror definition
def mirrorHorizontal(picture):
mirrorpoint=int(getHeight(picture)/2)
for y in range(1,mirrorpoint):
for x in range(1,getWidth(picture)):
p=getPixel(picture,x,y+mirrorpoint)
p2=getPixel(picture,x,mirrorpoint-y)
setColor(p2,getColor(p2))
Does the whole canvas need to be mirrored or just a picture on the canvas?
When I run the code I get the following error message...{Picture, filename C:\JES\mediasources\Molly'spics\insect.jpg height 199 width 300
Picture, filename C:\JES\mediasources\Molly'spics\7inx95in.jpg height 684 width 504
A local name was used before it was created. You need to define the method or variable before you try to use it} with the negative(insect) line highlighted.
What does this mean? What am i doing wrong?
| The two pictures aren't part of the error messages – you have print statements. The line in question is probably your hw1(insect) line. You don't have a function named hw1 anywhere in your file. Mark Guzdial |
| DO NOT DUMP YOUR ENTIRE CODE UP HERE! Come on, folks. Use email to your TA's and me, don't just dump your entire program here. Mark Guzdial |
How do I mirror the entire canvas when it is done? do I need to use writePictureTo("endcanvas.jpg") and then mirrorVertical(endcanvas)? i'm confused
| Why would you think that writePictureTo would do any mirroring? The way we wrote mirrorVertical was to take a picture, not a file, so why would you think that you need to write it to a file first? Mark Guzdial |
What to do when you get NullExceptionPointer errors
One thing to do is to check your pictures, perhaps downloading new copies of the canvas or getting one from a friend or getting a new one off the CD. I just was sent one student's code that was getting the error, but it worked fine for me – it was a bad 640x480.jpg canvas file. Mark Guzdial
K, finally got my canvas to mirror.. But now I have my original 4 images mirrored top to bottom but there is a large gap between them on the canvas?.. any clues to why this is happening.?. Heres my mirror code and the code I used for my first picture. Thanks for the help.
#First picture, at left edge
targetX=1
for sourceX in range(1,getWidth(puppy)):
targetY=getHeight(canvas)-getHeight(puppy)-5
for sourceY in range(1,getHeight(puppy)):
px=getPixel(puppy,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
def mirrorHorizontal(picture):
mirrorpoint=int(getHeight(picture)/2)
for y in range(1,mirrorpoint):
for x in range(1,getWidth(picture)):
p=getPixel(picture,x,y+mirrorpoint)
p2=getPixel(picture,x,mirrorpoint-y)
setColor(p2,getColor(p))
| Because of how you computed targetY. Do the math – you left a big gap with how you placed things. Mark Guzdial |
It's because you're using the mirrorpoint of the canvas. You can define your range so that it mirrors from the end of the pictures.
DO NOT DUMP ALL YOUR CODE UP HERE!
| Send it to your TA or to me, but don't just dump 100 lines of broken code up here. Mark Guzdial |
it don't work like i think it should
| I just gave a whole lecture on design and debugging. Work it through. Mark Guzdial |
this is one of my definitions and i am getting an error in the line with a "" to the left of it. i'm not sure why. please help me because it won't even load the program right now. thanks.
pre
def increaseBlue():
for x in range(1,getWidth(picture)):
for y in range(1,getHeight(picture)):* px=getPixel(picture,x,y)
value=getBlue(px)
setBlue(px,value1.3)
ok... that notation didn't come up, but it is the line: px=getPixel(picture,x,y)
| You didn't space over. After a "FOR", you MUST add more indentation. You didn't. (The * didn't come up because it's a * – read the FAQ on putting code in the CoWeb.) Mark Guzdial |
alright, here's the thing. at recitations, we went through my code and couldn't find any reason why it wouldn't work. When I got back to my dorm, I found the missing parenthesis, but when I run the program,the canvas doesnt come up, even though I have
return(canvas)
show(canvas)
at the end of my code(indented properly). So the program runs, and at the bottom says "" or at some other number. How do I get my canvas to come up? what's going on?
| First of all, please read earlier – RETURN MUST BE THE LAST LINE IN YOUR FUNCTION! That's why the Show isn't working. Second, say something like "test = hw2()" in the COmmand Area, then "show(test)". You'll see your picture, and be able to write it out from "test". Mark Guzdial |
in the ""'s of hte last entry it should say
media.Picture instance at
sorry.
when i try to load it says: There was a spacing error in the program. It might be from a previous line, but I think the error is in line 11
I have rechecked and rechecked everyline, but i can't find the problem.
| Use the blue boxes to make sure that the lines are indented as they should be. Mark Guzdial |
Is greyscaling a picture acceptable?
| yes, that would be considered as "altering colors on the image." Student56 |
No matter what I do and what picture I use, JES insists on telling me I am out of the boundaries for the canvas. This is illogical as my mirror along a horizontal axis is of a picture 100x100 and thus shouldnt be any larger than 200 tall and 400 wide when done. Is there any tell tale sign I am doing something wrong because it gives me the error in my definition of horizontalmirror
def mirrorHoriz(picture):
mirrorpoint=getHeight(picture)+1
for x in range(1,getWidth(picture)):
for y in range(1,getHeight(picture)):
p=getPixel(picture,x,mirrorpoint-y)
p2=getPixel(picture,x,mirrorpoint+y)
setColor(p2,getColor(p2))
my picture i used originally was 100x100....is there any help you can give me because I have worked on this problem for over 3 hours.
the spacing above didnt work right but nonetheless that is my def of mirrorHoriz and it is spaced correctly in JES
| You're setting a mirrorpoint of the height of the picture, and the y offset is going from 1 to the height of the picture. Of COURSE you'll be out of bounds. At the final value of Y, you're going to be copying from mirrorpoint (getHeight+1) + getHeight to getHeight+1-getHeight. How can you access a point at getHeight + getHeight and not be out of bounds? Maybe you mean the mirrorPoint to be getHeight/2? Mark Guzdial |
do we need to mirror whole picture?
or half of picture is fine?
| Yeah, I guess so, as long as you mirror your four images based on the single picture. Mark Guzdial |
I have finished my entire program and my collage comes back to me perfectly, but I am trying to writePictureTo to be able to save my new collage to turn it in and it's not working. Can someone give me step by step instructions on this? Or is there something else I can use to save my collage?
In the command area type something like: file = hw2() Next, you should type : writePictureTo(file,"C:\MyFiles\temp.jpg") Student189 |
I typed this exact thing into my command area and the collage was returned, just like it did to begin with, but I get this error message when I do the following writePictureTo suggestion....please help!
writePictureTo(file,"C:\MyFiles\temp.jpg")
I wasn't able to do what you wanted.
The error java.lang.IllegalArgumentException has occured
| Are you actually returning the picture at the end of hw2(). Is there a line at the end that says return(canvas). (canvas is just the name of your completed picture). Keith McDermott |
I just tried it on mine and it worked. In the Command area, first type file=hw2() then hit return. Your program should run and return the collage on the canvas. Then type writePictureTo(file,"C:\JES\collage.jpg") in the command area and it should save the image in your JES folder. Remember to include the quotations. Hope this works for you as well.
I do have the return(canvas) line at the end and the program is returning my canvas and all its changes....however, I tried writePictureTo(file,"C:\JES\collage.jpg") and it is still not working and giving me the same error message. I want to turn it in but it is not saving my collage. Is there anything else I can try to save it?
You might not have the folder in the same place - do getMediaPath or something to figure out exactly where you want to put it.
I've tried it all! It's still not working. Is it acceptable for full credit to just turn in the working program and the input picture?
Try writePictureTo(nameOfYourPicHERE,"C:\collage.jpg"). Then goto MyComputer and then the C: drive... The resultant image is required. "Turn in your code, your original image (or images), and your resultant image as "hw2"." Student189 |
you stated in the directions that "IT IS PERFECTLY OKAY FOR HW2() TO USE OTHER FUNCTIONS!" Is it perfectly okay for it NOT to use other functions? will i get counted off because my function is doing more than 1 thing? just wondering, thanks.
| you can separate functions or you can leave it all as one giant block of code either will be graded equally Student189 |
For writePictureTo, Remember: If you're using Windows, you can't use the '\' character inside double quotes without doubling it up. Either use "c:\\MyFiles\\mypic.jpg" or r"c:\MyFiles\mypic.jpg" Actually, I think you can even use a forward-slash '/' "c:/MyFiles/mypic.jpg", and python will convert that to whatever the directory separator on your platform is. Student57
Are the TAs going to analyze my code? (do I need comments?)
| Yes they will analyze your code (esp. if it doesnt work) and it NEVER HURTS to comment code Student189 |
It hurt me once. I broke my finger on the '#' key. I have flashbacks whenever I comment now.
I have tried writing my picture 10 times and nothing works. My picture is the canvas(correct?), so I type writePictureTo(canvas,r"c:\collage.jpg") and this doesnt work. I need some input and help soon as the error it tells me is canvas is a name error and I am leaving to go out of town tomorrow.
Nope, your picture might be your canvas but youre not gonna be able to write that too easily. What you probably need is to say: MYCOLLAGE = hw2()
writePictureTo(MYCOLLAGE,"c:\mycollage.jpg") Student189 |
The mirror of the pictures dont have to be perfect looking like the ones on the website right? they can be anywhere on the canvas as long as its understandable right?
| For those still having trouble writing out their pictures, don't forget the r"C:\...". For example, the person with the filename "C:\MyFiles\temp.jpg" – that won't work without the "r" (We'll be talking about why next week.) Mark Guzdial |
| For those still having trouble writing out their pictures, don't forget the r"C:\...". For example, the person with the filename "C:\MyFiles\temp.jpg" – that won't work without the "r" (We'll be talking about why next week.) Mark Guzdial |
OK I am having a out of bounds error that keeps coming up. It's coming from this line of code:
cx=getPixel(canvas,targetX,targetY)
the section of code is:
MY turn in is not posting on the website. What should i do. I am using the same computer that i successfully used to turn in the last assignment. There is no error when i attempt to turn it in but it's just not showing on the web however it is showing that i am attemtping to properly send it once i click on the history link of the page.
| Try again and if you're still have a problem email me with your name and gt# at aliang@cc.gatech.edu. Student56 |
QUESTION ABOUT UPLOADING TO THE GALLERY:
I'm all done and everything is turned in. But I am still confused. I've saved my collage to the JES folder on my C drive and would like to add it to the gallery. But... umm. I don't know how. When I try to 'attach', it won't let me log in (access denied, incorrect username and password). And when I try to 'edit', the resultant gallery page says something like 'missing file at...'.
Hmm.
| As always, the username is "attach" and the password is "carmen". |
for sourceY in range(1,getHeight(aish)):
px=getPixel(aish,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
The error:java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
Please check line 32 of C:\Documents and Settings\Salman REMOVED\Desktop\hwb....what do i do?
| Which line is line 32? Once you find that, take a look at the code and see why it's going out of bounds. I can't really tell from this section of code. Student56 |
My original picture was to large to fit the canvas, so i scaled it down, but now i'm lost as to how to copy the scaled picture. Oh, but is it required that the original picture be part of the canvas?
| The directions say one of the four CAN be the original picture, so you should be fine just using the scaled one (especially since the original won't fit. To re-use the scaled picture, name it as a variable whhen you alter it, and then rather than calling the original picture name, you can call the variable name. (Ie. if your picture was called "pic1.jpg" rename the scaled one "pic2.jpg" and use that for all your other alterations.) Student117 | |
I don't understand!!!
Link to this Page