 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Spring 2004 Homework 2 Questions
i am still trying to save the picture but i cant figure it out...how do i get the picture's name after running the program. the program is working well., but i've been here more than an hour trying to figure out how to save the final picture, could anybody help me please?
i still cant save the picture: i know that i have to do: writePictureTo(picture, path). how do i know the name of the picture?
| At the end of your function hw2, put in the line return canvas. In your command area, run the program as pict=hw2(). Then do writePictureTo(pict,"Mycollage.jpg"). The picture will be in your media folder. Mark Guzdial |
what is going on here? this definition is at the end of my program, and I copied it straight from the book. any ideas of why it would send me this error report? Student1156
def increaseBlue(picture):
for p in getPixels(picture):
setBlue(p, getBlue(p)*1.2))
..."There was a spacing error in the program.
It might be from a previous line, but I think the error is in line 74."
| Looks fine to me – must be somewhere else in your program. Mark Guzdial |
how do i save the final picture so i can turn it in?
help! my canvas is only copying a little slither of my picture! i know i need to change a target/source x,y but i dont know which or what to change it to! Student1053
| Go to breakout or your TA's office hours (or any TA's office hours) with a printout of your program. The most common cause for only copying a sliver of your picture is not incrementing sourceX, sourceY, targetX, and targetY correctly. Mark Guzdial |
The starting picture for hw2 need to be copied and placed next to itself to have four different images. Should we make the combined 4 picture in photoshop and then have the prgram change a quarter at a time, or shold the hw2 just take one image from the start.
| HW2 takes one image at the start and ends with four images that are slightly different, as per your directions in your code. Ashley Coker |
| Yes, you have to do all manipulations from the base images in your code. This is a Photoshop-free zone :-) You can use Photoshop to set up your base image, if you want: scaling, cropping. But from the base image to the multiple copies in the collages, it's got to be just your program code. Mark Guzdial |
Does the image have to be a certain size, ie like 240x90 pixels to get the images to display right in the 7x9.5 empty file. i wrote the program but the image doesnt look right, you only see part of the copies.
| You'll probably have to scale the image down to get it to fit. It's okay to crop and only show part of an image in the collage, but you still have to have the multiple copies of the base image. Mark Guzdial |
How do you scale the image down in JES?
| You will eventually learn in class how to use JES to scale pictures. Until then, you can use a program like PhotoShop or Microsoft Photo Editor to do it. Student117 |
| But for HW2, you must do the scaling through Python code. Scaling starts at page 94 in the book. Mark Guzdial |
| Scaling is also covered in the lecture slides for Monday, this week. We didn't get that far in class, but will discuss scaling either in the breakouts or on Friday before we leave imaging and start on the topic of sound. There is also a revision question on scaling with input in the Sp2004 Midterm 1 Review that you can use to test your understanding. Colin Potts |
For the modified images, can each image be cropped or rotated... or does each image need to have a different manipulation ?
| Cropping and rotation are valid manipulations – they count as different ones. Mark Guzdial |
are we allowed to make our canvas a different color? or does it have to stay white...
| You need to have a different manipulation on each image, but if you want to do more than one manipulation on an imgae that's ok. Also, it should be fine to make the canvas a different color I suppose, just so long as it works and you fulfill all the actual critera! Student117 |
| Sure, change the color! One of the nicer collages from the first semester changed the whole canvas pink. Mark Guzdial |
| In fact, you might check out the Fall2003 HW2 Collages. Your homework requirements are different, so your collages will look different from the corresponding collages last semester. However, last semester's should inspire you to experiment. Colin Potts |
Note that the HW2 deadline is NEXT Thursday!
See Syllabus and Lecture Slides-Spring 2004 to confirm. Several people in my breakouts today thought that the deadline was Friday. It's not. It's been delayed so that you have time in breakout to ask about both the Midterm and HW2. Mark Guzdial
I wanted to test just the first part of my program, but apparently I have a syntax errror. My line 2 is: Goku1=makePicture(getMediaPath("Goku1.jpg")) Goku is the name of my picture. It is telling me that I have a syntax error and I do not know where it is. I checked the path to Goku and it is in mediasources in JES. Any help is appreciated. Thank You Student1056
| I don't think this is a syntax error. Do you get it when you load the function into the command area? If so, check the preceding line – which is probably your def of the function. Does it end in a colon? More probably, Python simply can't find your JPEG file when you run your function. You have to call setMediaPath() first – which, since your error is on line 2, you probably didn't do. Colin Potts |
why do we have to define our picture twice in the progrma area? For example, the slides have barbf and barb. Also, canvasf and canvas. When I load the program, JES is saying that I have an error with canvasf.
| You're not defining the picture twice. You're defining a SOURCE and a TARGET (the canvas, where you're going to write your pictures out). Mark Guzdial |
Is it okay if we make our collages from Barbara's pictures?
I don't know what I'm doing wrong with the first part of this homework. I'm trying to establish which pictures I'm using. I tried using setMediaPath() in the command area as well as the program area and followed with
def hw2():
picturef=getMediaPath("cmm2.jpg")
picture=makePicture(picturef)
canvasf=getMediaPath("7inX95in.jpg")
canvas=makePicture(canvasf)
When I load, it keeps saying "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."
What am I doing wrong?!
| Is the above the whole program area? The part you list looks okay. I'm guessing that farther down you have something like bad spacing or ()'s off, and that's what's keeping your program from loading. Mark Guzdial |
Thanks! I thought that was what I was messing up because it was the only part I wasn't sure how to use. Turns out I accidently missed a space towards the end of the program. Silly me. :-)
One more question, though. On the homework requirements, when it says we can change the original in any of the three ways, is it okay to change the color in different ways on each of them? (i.e. Make one all red, one all blue, and one all green.) Also, it says to negate half after we mirror it, but it only mentions right and left. Is it okay if we mirror top to bottom and then negate the bottom? Thanks so much!
| Yep, you can mirror vertically (left-right) or horizontally (top-bottom). Either is perfectly acceptable. And yes, you can change the color in different ways on each of them. Basically, each picture needs to be different from the previous one in some way. Ashley Coker |
When I try to use writePictureTo, I keep getting an error that says "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." Any idea what I'm doing wrong?
ok, I've tried everything I can think of to flip my one central picture over the middle from right to left:
def mirrorVertical(picture):
mirrorpoint = int(252)
for y in range (86,276):
for x in range (1,mirrorpoint):
p=getPixel(picture,x+mirrorpoint,y)
p2=getPixel(picture,mirrorpoint-x,y)
setColor(p2,makeColor(getRed(p), getGreen(p), getBlue(p)))
It says its out of bounds every time...HELP!
| What are the dimensions of the picture? Based on what you have here, it had better be at least 504 (252*2) pixels wide, because you're seeing your mirrorpoint at 252 and making your x offset go from 1 to 252, so at most, it'll be 252+252. Mark Guzdial |
I'm asssuming that the code is correctly indented (i.e. the last three lines are all part of the 'for x' block). First, what does "out of bounds" mean? What could possibly be out of bounds? You say that it says "out of bounds" every time, but does the program fail on the first time through the loop or only after several iterations? You need to work out when it is failing to work out why. Trace your code by hand first to find whether you could be trying to access a pixel that isn't in the picture. If that doesn't answer the question, try putting a print statement in the loop that prints out the values of x and y. The last one printed before the program fails will tell you why you're getting the error message. Colin Potts
I think my question got overlooked because of the following one... Could somebody answer this for me? :-)
When I try to use writePictureTo, I keep getting an error that says "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." Any idea what I'm doing wrong?
| What input are you giving writePictureTo? My guess is that you're specifying something that isn't a picture or isn't defined. Remember that the variables in your function are NOT defined in the command area. Mark Guzdial |
The turn-in instructions for hw2 say to also submit our resltant picture. I can't get this picture to save. Can anyone tell me how to save it so I can submit it?
| You'll need to use writePictureTo. Try using JES Help, too, to figure out how to use it, or ask in Breakout this week. Mark Guzdial |
Is it necessary to stay within the bounds of the 7x9.5 canvas or can we use a bigger one? The collages posted seem bigger than 7x9.5.
Student926
| Yes, Amanda, you can use a bigger canvas, but you'll have to create it for yourself. See makeEmptyPicture (bottom of page 96 in the book). Mark Guzdial |
ok, scaling is still messing with my head. this is my program, in which I am trying to scale a 50x76 pic by 1.5. The problem is that inside my canvas is a blue rectangle the size of my scaled pic, instead of the pic(and my spaces are right, it just doesn't show here):
def wolfBig():
wolf=makePicture(r"C:\\Documents and Settings\\Jenn\\My Documents\\My Pictures\\wolf_edited.jpg")
canvas=makePicture(r"C:\\Documents and Settings\\Jenn\\My Documents\\mediasources\\7inX95in.jpg")
sourceX=1
for targetX in range(17,(17+int(50*1.5))):
sourceY=1
for targetY in range(1,(1+int(76*1.5))):
color = getColor(getPixel(wolf,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY = sourceY + (2/3)
sourceX = sourceX + (2/3)
show(wolf)
show(canvas)
return canvas
Student1034
| Jenn, you need to add (2.0/3) or (2/3.0) to your sourceY and sourceX. 2/3 in Python is...zero! (Remember–integer arithmetic. See page 22 in the book.) Because you're adding zero to your source indices, they're not moving, so you're filling the whole rectangle with just the pixel at (1,1) in your source. Mark Guzdial |
unfortunatly, this only led to another problem. with everything the same as above, except(2.0/3) in place of (2/3), it says line 8 (the color= statement) has a parameter of an invalid type, that I might be trying to pass a string to a method that is expecting an integer. I thought we just gave it an integer! again...help..
Student1034
I can't figure out how to change the picture from barbara's to one of mine...please help!
How does setMediaPath work? It won't let me choose the picture I won't just the entire folder, so I moved the picture I am using to a new folder and did setMediaPath of the new folder. I still get an error message when I try to run hw2 saying that there is no file at what I enter after getMediaPath. I'm confused.
Student966
i'm having the same problem!
| setMediaPath() is supposed to choose a folder, that is correct. You need to do setMediaPath() in the command area of JES before running hw2() and choose the folder in which your picture is located, then in your program you should have getMediaPath("thenameofthepicture.jpg"). Student117 | |
thanks, so how do I set the media path for both my picture and the canvas at the same time?
Student966
For some reason this code is not working in JES and I got it directly from the notes and tweaked it to work for my picture. Something is wrong with the line that starts out with "color." 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.
Please check line 26 of C:\Documents and Settings\Tracy Lee\My Documents\School!\CS 1315\Homeworks\hw2
for sourceY in range (1,getHeight(art)):
color = getcolor(getPixel(art,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY),color)
targetY=targetY+1
| Case (as in lower case/upper case) is significant in Python. As the error message indicates, Python could not recognize the name of one of your functions. Colin Potts |
| Heather: You can only set one mediapath at a time. So, you need to put the canvas file and the source file in the same folder – or at least define the path to one of them relative to the folder of the other. Colin Potts |
Im having a problem taking the negative of only one half of the picture. I tried to copy the text out of the book but it keeps telling me that my variable for the values of the color are not defined. Also, I am trying to copy only up to the mirrorpoint. When I put in the following code:
def negative(source):
mirrorpoint=int(getWidth(source)/2)
for px in range(1,mirrorpoint):
redvalue=getRed(px)
greenvalue=getGreen(px)
bluevalue=getBlue(px)
negColor=makeColor(255-redvalue, 255-greenvalue, 255-bluevalue)
setColor(px,negColor)
I get this error:
An error occurred attempting to pass an argument to a function.
Please check line 120 of C:\Documents and Settings\Melanie Nelson.RAE2K\My Documents\hw2.py
Which refers to the negative color line. Any suggestions for how I can fix this? Thanks Student998
| Melanie, you have px as an INTEGER (not a PIXEL) between the range of 1..mirrorpoint. setColor takes a PIXEL as input. Here's a suggestion: use the variable pindex (pixel index) in the for loop, then on the first line of the loop, say px = getPixel(picture,pindex). Then everything should work. Mark Guzdial |
Before I can flip my image, do I need to write the image to the hardrive then input it in a mirror fuction, or is there some way to flip each individual picture. I am completely at a loss as to how to do this.
| No, you don't have to write the image to the disk first to do the mirroring. You are definitely NOT supposed to flip each individual picture. Compose (copy) the images onto the canvas, then mirror the WHOLE CANVAS. Mark Guzdial |
What does it mean if when I try to run a program that ran yesterday and press enter it simply gives me "..." and doesn't show that it is running anything but also doesnt show the error?
| If you get "..." it means that Python thinks that you're going to have to hit to enter something else to end the line. Try just hitting return, but more importantly, look at what you typed to look for unclosed () or "". Mark Guzdial |
Do we turn in(attach) our original images too, along with the resultant images?
| Absolutely! We have to run your program and we need your original images to do it. Student521 |
def negative(source):
for px in getPixels(source):
for x in range(1,getWidth(source)):
for y in range(54, 108):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(px,negColor)
this is my code for making it negative. i have a feeling this is completely wrong. can anyone point me in the right direction? how do i mirror the entire canvas?
| Your feelings are correct. You have two choices for any color manipulation, including making something negative: (a) do all the pixels with for px in getPixels(source): or (b) do just a range with nested loops. You chose to do BOTH!. Remove the for px... line (and shift everything back two spaces) and at the top of the main loop put px = getPixel(source,x,y), and I think you'll find that you're very close. Mark Guzdial |
for mirroring the entire canvas, change you input from "picture" to "canvas"..look in the book for the mirroring function
def mirrorVertical(canvas):
mirrorpoint = int(getWidth(canvas)/2)
for y in range(1,getHeight(canvas)):
for xOffset in range(1, mirrorpoint):
pright = getPixel(canvas, xOffset+mirrorpoint, y)
pleft = getPixel(canvas, mirrorpoint-xOffset,y)
c = getColor(pleft)
setColor(pright,c)
I do believe that this worked
| Huh? That doesn't make sense – changing the input variable name doesn't change anything. Mark Guzdial |
For the three manipulations, can we do ANY three of the ones listed in the bullets in the HW2 assignment page, or do we need to choose 1 from each bulleted line? Specifically, my three are scaling, rotating, and color alteration...is that ok? Student1207
| You can choose any three. Three different color alterations are fine, for example. Three different crops would also be okay. Mark Guzdial |
I cannot seem to access MediaSources from the JES CD provided in class through JES. When I setMediaPath, it does not allow me to use the jpg files in the media sources file on the CD. I can't even tell if my code is correct since I can't access these pictures. I tried to save them to my harddrive, yet they are saving as really big pictures, and they won't fit on the canvas. I tried to resize them, but I can't seem to do that either. Anyone have any advice?
| Try downloading the Mediasources that is on the CoWeb instead. I know these work, because they are what I have on my computer! They are located under Course Software (JES) on the homepage. Student117 |
Should the pictures take up all the space of the canvas (7x95 in) or can we have the four pictures on top but that they don't fulfill the whole canvas to the right and to the bottom? (I have blank space to the right of my pictures and towards the bottom of the canvas).
| Having blank space on the canvas is fine, when you crop your pictures and since everyone's will be different sizes, we don't expect every collage to take up exactly a 7x9.5 inch space! Student117 |
i'm having a problem when i try to see my original picture and my negative picture on the collage so far. for the negative picture, my code reads:
def negative(flower1):
for x in range(1,getWidth(flower1)):
red=getRed(px)
green=getGreen(px)
blue=getBlue(px)
negColor=makeColor(255-red,255-green,255-blue)
setColor(px,negColor)
targetX=500
for sourceX in range(1,getWidth(flower1)):
targetY=100
for sourceY in range(1,getHeight(flower1)):
px=getPixel(flower1,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
show(canvas)
return(canvas)
when i try to run it, i get an error reading:
I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 31 of C:\My Documents\hw2
Line 31 is "cx=getPixel(canvas,targetX,targetY)"
What am I doing wrong?
Student941
| How wide is your target, Marggee? Is it more than 600 pixels wide? Since you're starting with targetX = 500, and you're incrementing it while sourceX goes from 1 to getWidth(flower1), which I'm guess is around 100 pixels, you're going to be accessing up to x=600 in the canvas. If the canvas isn't that wide, you're going to get an ArrayIndexOutofBounds exception. Try lowering targetX to say 300 and see what happens. Mark Guzdial |
sorry, but the spacing of my code didnt show up right when i posted to the board...
Student941
| The FAQ can help you post code so that it's readable, Marggee. Mark Guzdial |
thanks, Mark. that worked much better. but now that my 2nd picture is showing up, nothing's happening to it. i even tried posterizing it because negating it didn't do anything, and still nothing's happening...2 pictures on my canvas just show up. was anything wrong with my negation code? any suggestions?Student941
| Yes, you reference a variable px, but it isn't defined anywhere there. You're going to need two loops, one for x and one for y, to negate within a range. Mark Guzdial |
I can't figure where to find out how many pixels my picture is. I tried using MediaTools but it didn't work. Also, do we half to make the negative half only or can we do this:
Picture (verticalMirror-Negative)
verticalmirror-neg from above pic: horizontalmirror-neg [so it's actually a positive)
Doing the steps clockwise staring with "picture," so that your negatives are diagonal?
| If you print the picture, you'll get the width and height. Or use getHeight(picture) and getWidth(picture). I can't figure out what you're trying to do – my suggestion is to get negating one-half to work, and then we can talk about negating in diagonals. Mark Guzdial |
What I was asking was if i have a picture in the upper left corner, can i mirrot it across the y-axis and make it negative, then mirror that over the x-axis and make it negative (so it is now positive), then mirror that over the y-axis and make it negative.
| Yeah, you can do that, but the assignment calls for half of the CANVAS to be negative, NOT negating any individual picture. I'm not convinced from your description that you're doing the same thing. Our point with the negative requirement is not to just get 1/2 of all the pixels in the canvas turned into negative, but to have you work through how you would negate HALF a canvas, not a whole picture. Doing it your way lets you get out of figuring that out. Mark Guzdial |
I just wanted to say you guys are great! Thanks for the help!
Blank
I want my collage to be in landscape format (9.5x7) so I called makeEmptyPicture(684,504) to do this. Is that ok or is there a prefered way to do this?
Student925
This is probably a silly question.....but for some reason I can't seem to use my picture tool. I did show(makePicture(pickAFile())), picked a file and then tried to select the picture tool but it keeps saying "there is no picture to examine". What am I doing wrong?
| You can only use picture tool on pictures STORED IN VARIABLES in the command area. Assign a name to the picture, don't just show it. Mark Guzdial |
The picture I am using is 500 pixels by 335 pixels. I used makeEmptyPicture to make a canvas that was 2100 by 800, but I still get an out of bounds error message on the third picture where the targetX is 1000. Did I do something wrong?
Student966
| You can get the out of bounds error on targetX OR targetY OR sourceX OR sourceY. Check all four. Mark Guzdial |
1. If I have the original picture, a scaled version of the original, a posterized scaled, and a change blue of the picture, then I have covered my 4 requirements there correct?
2. This function that I wrote is not general. My helper functions use specific pixel values and not "getHeight(pic)", so they will only work for the picture that I have chosen, is that alright?
3. If I name the same picture 3 separate things so that I can perform different programs on each, do I need to attach just one of these pictures or should I attach the same one 3 times?
| No, just attach it once. It's one filename, right? Then it doesn't matter how often your program reads it in. Mark Guzdial |
If my program is taking a very very very long time to run the negative feature, does that mean that I have something aligned wrong to make it work too hard or should this part take a while? My program is very similar to the negative program in the book, so I am assuming that the alignment is okay... guidance?
| The common problem I'm seeing on negative is having THREE loops. That would take a very long time to run. As long as you have the TWO loops (for x and for y), it should end in a reasonable amount of time. Mark Guzdial |
How do we enter muliple functions? I have the collage up and running with the four copies of one image. But when I add the function for darkening one of the images it says I have a syntax error. It is highlighting this line of code:
def darken(picture):
Could it be a problem with my indenting relative to the rest of the code?
| Probably. Any additional functions must have NO indentation on the def line. See pages 89-91 for an example. Mark Guzdial |
When I mirrored the canvas, the picture that I cropped had space in between becuase I mirrored it horizontally right below the base of other three pictures. Is this ok?
When I are writing my hw2 function and I need to call other functions to manipulate the base image, do I need to define these functions step by step(such as making a negative of an image) within the hw2 function? The example in the book just calls the funciton by name such as negative(picture)without showing the code to perform the function. Student1133
| Read one page farther, Matthew. REMOVED 87-88 does list the Collage code, calling negative(picture), but pages 89-91 shows the whole program area, which does include the def negative(pict): function definition. Mark Guzdial |
When I try to load my code, I get an error message that reads "There was a spacing error in the program.It might be from a previous line, but I think the error is in line 11." My code is listed below. Line 11 is the targetX=targetX + 1 line.
def hw2():
bush=makePicture(getMediaPath("bush.jpg"))
target=makePicture(getMediaPath("7inx95in.jpg"))
targetX=1
for sourceX in range(1,getWidth(bush)):
targetY=1
for sourceY in range(1,getHeight(bush)):
color=getColor(getPixel(bush,sourceX,sourceY))
setColor(getPixel(target,targetX,targetY), color))
targetY=targetY+1
targetX=targetX+1
show(bush)
show(target)
return target
| You have an extra ")" on the setColor line. Remove it. Mark Guzdial |
does it matter if my program takes a couple minutes to run ~2.5, even if it works in the end?
| The time it takes your program to run will vary depending on computer speed and the number of other programs you have running at the same time (ie. Internet Explorer, Instant Messenger, Word, etc.) You can't really affect the time it takes to run, so it's fine, and it may not even take as long on someone else's computer. Student117 |
def hw2():
volcano = makePicture (getMediaPath(r"goodday.jpg"))
print volcano
canvas = makeEmptyPicture (2500, 1000)
print canvas
#picture1
targetX = 1
for sourceX in range (1, getWidth (volcano)):
targetY= 1
for sourceY in range (1, getHeight (volcano)):
px = getPixel (volcano, sourceX, sourceY)
cx = getPixel (canvas, targetX, targetY)
setColor (cx, getColor (px))
targetY = targetY + 1
targetX = targetX + 1
#picture2, gray scale
grayscale (volcano)
targetX = 700
for sourceX in range (1, getWidth (volcano)):
targetY = 1
for sourceY in range (1, getHeight (volcano)):
px = getPixel (volcano, sourceX, sourceY)
cx = getPixel (canvas, targetX, targetY)
setColor (cx, getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#picture3, sepiatoned
sepiatone (volcano)
targetX = 1400
for sourceX in range (1, getWidth (volcano)):
targetY = 1
for sourceY in range (1, getHeight (volcano)):
px = getPixel (volcano, sourceX, sourceY)
cx = getPixel (canvas, targetX, targetY)
setColor (cx, getColor(px))
targetY = targetY + 1
targetX = targetX + 1
I've tried everything I can think of and I still get an out of bounds error. Right now targetY is set to one; it was set to getHeight of canvas minus getHeight of volcano. I got an out of bounds error then too. My picture is 500 pixels wide and 335 pixels high. What else should I try?
Student966
| Your last targetX=targetX + 1 is indented too far, so it's getting incremented everytime Y is, which is too much. Mark Guzdial |
Since I could not figure out why my picture tool wasn't working last night, I used getHeight and getWidth a lot instead of pixel values on the source and target.....as long as it works is it alright?
so, how can i make the negative use only 2 loops if i need on for the "for p in getPixels"? how can that be avoided?
| Use for x in range and for y in range and px = getPixel(picture,x,y). Mark Guzdial |
I am using the following code to alter the color of my pictures, but the change in color doens't happen. Four identical pictures show up, not the original and three altered ones. I modeled it after the one in the book, but it still doens't work. What am I supposed to do? Also, is it okay to use getMediaPath? Student1068
| Yes, you are REQUIRED to use getMediaPath. All your color functions are wrong. Why are you setting red in everyone of them? Why not change the color that the function name suggests that you're changing? Mark Guzdial |
def hw2():
#original picture
lukeschenscher = getMediaPath("Schenscher.jpg")
luke = makePicture(lukeschenscher)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
targetX = 1
for sourceX in range(1,getWidth(luke)):
targetY = 1
for sourceY in range(1,getHeight(luke)):
color = getColor(getPixel(luke,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY),color)
targetY = targetY + 1
targetX = targetX + 1
#red picture
increaseRed(luke)
targetX = 105
for sourceX in range(1,getWidth(luke)):
targetY=1
for sourceY in range(1,getHeight(luke)):
px=getPixel(luke,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#blue picture
increaseBlue(luke)
targetX = 209
for sourceX in range(1,getWidth(luke)):
targetY=1
for sourceY in range(1,getHeight(luke)):
px=getPixel(luke,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#green picture
increaseGreen(luke)
targetX = 313
for sourceX in range(1,getWidth(luke)):
targetY=1
for sourceY in range(1,getHeight(luke)):
px=getPixel(luke,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
show(canvas)
return(canvas)
def increaseRed(luke):
for p in getPixels(luke):
value=getRed(p)
setRed=(p,255)
repaint(luke)
def increaseBlue(luke):
for p in getPixels(luke):
value=getBlue(p)
setRed=(p,255)
repaint(luke)
def increaseGreen(luke):
for p in getPixels(luke):
value=getGreen(p)
setGreen=(p,255)
repaint(luke)
I know this question has been asked before, but I can't figure out how to use the writePictureTo command. In the command area I wrote, writePictureTo(picture,"C:\JES\MediaSources\motocollage.jpg")....but I keep getting the local or global name could not be found warning ( I would like to name the collage "motocollage" and write the picture to the MediaSources folder). How do I go about defining the final collage picture inside the command area?
| Make sure that your function hw2 RETURNs the canvas, then in the command area, say "picture=hw2()", and then you should be able to use writePictureTo(picture,"anyname.jpg"). Mark Guzdial |
How complex should our images be? By that, I mean the original image, because with larger images my computer slows to a crawl. Does the canvas have to be filled? As long as we have four different images and their mirrors will that be okay?
| As long as you meet the requirement, you're fine. Mark Guzdial |
I am having trouble with setting the media path, is the correct way to write it?
Student1215
def createCollage():
setMediaPath("/home/wazzles/jes-nc/mediasources/")
pic = makePicture(getMediaPath("homer.jpg"))
print pic
background = makePicture(getMediaPath("7inX95in.jpg"))
print background
| No, you NEVER setMediaPath inside your function – you ONLY do it from the Command Area. Mark Guzdial |
why is it that I can only use MediaSources to store my pictures? I'm trying to setMediaPath to another directory (e.g. floppy) and I keep getting "Note: there is no file in blah, blah..." The reason I'm doing this is bc I'm at school at the moment and I'm running the JES CD on the school computer. Is there any way I can get around this?
| No, you cannot writePictureTo if you're running JES from a CD. writePictureTo uses temporary space in the JES folder, and it can't if you're running from a CD. Mark Guzdial |
I'm getting an our of bounds error also...and it says that my problem is coming from this line:
color = getColor(getPixel(battlecat,sourceX,sourceY))
| That means that sourceX and sourceY are greater than the width and height of battlecat. Mark Guzdial |
I'm having a problem mirroring my canvas...i do mirror the entire canvas, right?? anyway, when i run this code, only my collage with my original picture and my 3 manipulated pictures show up, but nothing else. what can i do to make SOMETHING happen?! thanks :)
Student941
def mirrorHorizontal(canvas):
mirrorpoint=int(getHeight(canvas)/2)
for yOffset in range(1,mirrorpoint):
for x in range(1,getWidth(canvas)):
pbottom=getPixel(canvas,x,mirrorpoint-yOffset)
ptop=getPixel(canvas,x,mirrorpoint-yOffset)
setColor(pbottom,getColor(ptop))
| PLEASE, Marggee – read the FAQ on how to format your code! This code looks right for mirroring the canvas. Do you call it from within your HW2 function? You have to call it to get it to execute. Mark Guzdial |
It keeps telling me that I have an OutofBounds Error. my picture is 530 x 530. and it says that my error is in my "px=getPixel(battlecat,sourceX,sourceY)" line. I'm not even sure how that line causes an out of bounds error. ~help!
Student931
def battleCatSmaller():
battlecatf = getMediaPath("battlecat.jpg")
battlecat = makePicture(battlecatf)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
#Copying
sourceX = 1
for targetX in range(1, getWidth(battlecat)):
sourceY = 1
for targetY in range(1, getHeight(battlecat)):
px=getPixel(battlecat,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
sourceY = sourceY + 2
sourceX + 2
show(battlecat)
show(canvas)
return(canvas)
sorry..here it is again:
def battleCatSmaller():
battlecatf = getMediaPath("battlecat.jpg")
battlecat = makePicture(battlecatf)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
#Copying
sourceX = 1
for targetX in range(1, getWidth(battlecat)):
sourceY = 1
for targetY in range(1, getHeight(battlecat)):
px=getPixel(battlecat,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
sourceY = sourceY + 2
sourceX + 2
show(battlecat)
show(canvas)
return(canvas)
| Look at the line "sourceX + 2" Is that what you wanted? Perhaps you wanted "sourceX = sourceX + 2"? Mark Guzdial |
I am at the last step of the assignment...negating half of the picture. I know how to negate the entire canvas, but not just half of it. Can someone help me? Thank you so much for your time!
| Read the above comments – I've answered this several times now. Use two for loops, one for x and one for y. use getPixel to get each pixel. Mark Guzdial |
i also tried using a smaller picture...one that is 265 x 265. and i still get the same error....
Student931
| Your code is wrong, Susan – re-read it and notice the sourceX lines. Mark Guzdial |
I've never had problems in the past acccessing pictures, but now when I try to set the media path, it doesn't work. When I type in "setMediaPath()" in the command area, none of the pictures that I have in My Pictures come up. Only the JES file seems to have available pictures. I tried in the command area selecting some images from JES, and here is what I got:
setMediaPath()
New media folder: C:\Documents and Settings\Kati Lawrence\My Documents\Computer Science\JES\MediaSources\blowhole\
>>> getMediaPath("beach.jpg")
Note: There is no file at C:\Documents and Settings\Kati Lawrence\My Documents\Computer Science\JES\MediaSources\blowhole\beach.jpg
'C:\\Documents and Settings\\Kati Lawrence\\My Documents\\Computer Science\\JES\\MediaSources\\blowhole\\beach.jpg'
Thank you for your help!!!
#15
so here is my code, and I only want to increaseRed of the 5th picture, not the 6th too, but when I run it, it increases the Red of both the 5th and 6th picture. I do not understand why. Anyhelp is appreciated. Student1056
- Fifth Picture scaled down to bottom right corner
increaseRed(Goku)
sourceX=65
for targetX in range(316,316+((245-65)/2)):
sourceY=90
for targetY in range(432,432+((370-90)/2)):
color=getColor(getPixel(Goku,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY=sourceY +2
sourceX=sourceX + 2
#Sixth Picture scaled down to middle of image
sourceX=65
for targetX in range(210,210+((245-65)/2)):
sourceY=90
for targetY in range(265,265+((370-90)/2)):
color=getColor(getPixel(Goku,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY), color)
sourceY=sourceY +2
sourceX=sourceX + 2
show(canvas)
return canvas
def increaseRed(picture):
for p in getPixels(picture):
value=getRed(p)
setRed(p,value1.5)
| Jonathan, read your email – I just answered this question. Re-execute the makePicture to get a new copy of the Goku picture. And PLEASE, READ THE FAQ to format your code so that we can read it! Mark Guzdial |
sorry i was just about to format and put the code again Student1056
Maybe I should explain my problem better... when I do something like type in "pickAFile" in the command area, a window pops up that displays thumbnails of all the pictures I have in My Pictures and I can choose which one to use by double clicking on it. When I type in "setMediaPath," I a similar window pops up, but there are no pictures in it to choose from - just a blank screen. How can I find the pictures I need to set the media path?
#15
i'm having the same problem as ben, it says there is an error on the line that says cx=getPixel(canvas,targetX,targetY) ...which doesn't really make sense to me..
I keep getting the error "An error occurred attempting to pass an argument to a function.
Please check line 8 of C:\Documents and Settings\The Master Chief\My Documents\hw2.py" in my code at the 8th line.
def hw2():
sponge=makePicture(getMediaPath("spongebob.jpg"))
print sponge
canvas=makePicture(getMediaPath("7inx95in.jpg"))
print canvas
#First Image
targetX=1
for sourceX in range(1,getWidth(sponge)):
targetY=getHeight(canvas)-getHeight(sponge1)-5
for sourceY in range(1,getHeight(sponge1)):
p=getPixel(sponge1,sourceX,sourceY)
c=getPixel(canvas,targetX,targetY)
setColor(c,getColor(px))
targetY=targetY+1
targetX=targetX+1
Student1194
Hey Katie, setMediaPath just assigns a folder for your picture, you are not actually selecting anything when you setMediaPath. That just tells Jes where to look. getMediaPath is what tells JES to look where ever you setMediaPath. So its fine that there are not pictures in there. Before you do anything though, make sure the picture you are manipulating is in the folder you are going to setMediaPath. So, for example, if you have your picture in My Pictures, and then in a folder called CS1315. In the command area you would do setMediaPath()....Then it would show the thumbnails and ask you to select a folder. Pick the folder called CS1315. It returns the folder, and the last thing on the file name should be CS1315\....Now do getMediaPath("name of picture.jpg")...It will then return the path of your picture. If you are still unclear, top of page 80 may help. Student1056
mark, i am calling my function as mirrorHorizontal(canvas) within HW2 and it still does nothing-only my 4 pictures show up, but no mirroring. any other suggestions?
Student941
I am unable to turn in my homework. I've tried several times.Help!It says that an unexpected error has occurred in the turnin process.
Okay, I fixed my color functions and now the color changes, but for some reason, only three pictures show up. Can someone suggest why? Student1068
def hw2():
#original picture
lukeschenscher = getMediaPath("Schenscher.jpg")
luke = makePicture(lukeschenscher)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
targetX = 1
for sourceX in range(1,getWidth(luke)):
targetY = 1
for sourceY in range(1,getHeight(luke)):
color = getColor(getPixel(luke,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY),color)
targetY = targetY + 1
targetX = targetX + 1
#red picture
increaseRed(luke)
targetX = 105
for sourceX in range(1,getWidth(luke)):
targetY=1
for sourceY in range(1,getHeight(luke)):
px=getPixel(luke,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#blue picture
increaseBlue(luke)
targetX = 209
for sourceX in range(1,getWidth(luke)):
targetY=1
for sourceY in range(1,getHeight(luke)):
px=getPixel(luke,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#green picture
increaseGreen(luke)
targetX = 313
for sourceX in range(1,getWidth(luke)):
targetY=1
for sourceY in range(1,getHeight(luke)):
px=getPixel(luke,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
show(canvas)
return(canvas)
def increaseRed(luke):
for p in getPixels(luke):
value=getRed(p)
setRed(p,255)
repaint(luke)
def increaseBlue(luke):
for p in getPixels(luke):
value=getBlue(p)
setBlue(p,255)
repaint(luke)
def increaseGreen(luke):
for p in getPixels(luke):
value=getGreen(p)
setGreen(p,255)
repaint(luke)
when I type setMediaPath() at the command line JES tells me that "A local or global name could not be found"
Are we supposed to mirror the ENTIRE canvas...or can we just mirror half of our image on the canvas?
for anyone using linux, setMediaPath() at the command line did not work for me, consider trying setMediaFolder(), which works!
Student1215
no matter what I do to the beginning of my code it always says its out of bounds! Here it is so far:
def hw2():
#original picture
partyf = getMediaPath("cr.jpg")
party = makePicture(partyf)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
targetX = 1
for sourceX in range(1,getWidth(party)):
targetY = 1
for sourceY in range(1,getHeight(party)):
color = getColor(getPixel(party,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY),color)
targetY = targetY + 1
targetX = targetX + 1
show(canvas)
return(canvas)
Student1080
| Ben, how big is your picture "cr.jpg"? How wide is it? how tall is it? If it is larger than the canvas you are using (7inchesX9.5inches), then it's going to say out of bounds error. Ashley Coker |
my program is telling me that I have an "error java.lang.ArrayIndexOutOfBoundsException has occured" and I don't know why. the error highlights the line with the "###" what am I doing wrong?
def hw2():
#original picture(1,1)
battlecatf = getMediaPath("battlecatsm.jpg")
bcsm = makePicture(battlecatf)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
targetX = 1
for sourceX in range(1,getWidth(bcsm)):
targetY = 1
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
### cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 2
targetX = targetX + 2
#increase red for picture(133,1)
increaseRed(bcsm)
targetX = 133
for sourceX in range(1,getWidth(bcsm)):
targetY=1
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#increaae blue for picture(1,133)
increaseBlue(bcsm)
targetX = 1
for sourceX in range(1,getWidth(bcsm)):
targetY=133
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#increase green for picture(134,134)
increaseGreen(bcsm)
targetX = 134
for sourceX in range(1,getWidth(bcsm)):
targetY=134
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
show(canvas)
return(canvas)
def increaseRed(bcsm):
for px in getPixels(bcsm):
value=getRed(px)
setRed(px,200)
repaint(bcsm)
def increaseBlue(bcsm):
for px in getPixels(bcsm):
value=getBlue(px)
setBlue(px,200)
repaint(bcsm)
def increaseGreen(bcsm):
for px in getPixels(bcsm):
value=getGreen(px)
setGreen(px,200)
repaint(bcsm)
Susan Kommeth
| Susan this means you are trying to access or set a pixel which does not exist in one of your pictures. First thing I would recommend is trying to run your code with a very small source picture. See what the code is actually doing. You might find that it is not what you intended. Ie. putting pictures where you did not expect. Student549 |
I am having a problem setting my media path. Is it ok to set two different ones or do they have to com from the same location?
nevermind. Susan.
should the range be (1,getWidth(picture) or range(1,getWirth(picture)+1)
Stephen Rudolph
Just like Meghan (from above) my program is only painting 3 pictures with a gray square where the other one should appear.
why is this happening?
def hw2():
#original picture(1,1)
GToar = getMediaPath("GToar.jpg")
bcsm = makePicture(GToar)
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
#grayscale for picture (1,1)
grayScale(bcsm)
targetX = 1
for sourceX in range(1,getWidth(bcsm)):
targetY = 1
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#increase red for picture(112,1)
increaseRed(bcsm)
targetX = 112
for sourceX in range(1,getWidth(bcsm)):
targetY=1
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#increase blue for picture(1,111)
increaseBlue(bcsm)
targetX = 1
for sourceX in range(1,getWidth(bcsm)):
targetY=111
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
#increase green for picture(112,111)
increaseGreen(bcsm)
targetX = 112
for sourceX in range(1,getWidth(bcsm)):
targetY=111
for sourceY in range(1,getHeight(bcsm)):
px=getPixel(bcsm,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
show(canvas)
return(canvas)
def grayScale(bcsm):
for px in getPixels(bcsm):
newRed = getRed(px)*0.299
newGreen = getGreen(px)*0.587
newBlue = getBlue(px)*0.114
luminance = newRed+newGreen+newBlue
setColor(px,makeColor(luminance,luminance,luminance))
repaint(bcsm)
def increaseRed(bcsm):
for px in getPixels(bcsm):
value=getRed(px)
setRed(px,185)
repaint(bcsm)
def increaseBlue(bcsm):
for px in getPixels(bcsm):
value=getBlue(px)
setBlue(px,185)
repaint(bcsm)
def increaseGreen(bcsm):
for px in getPixels(bcsm):
value=getGreen(px)
setGreen(px,185)
repaint(bcsm)
| Because you're not using the value that you get from the pixel when you're setting them. Your increase functions are not working – you're setting all the pixels to the same value of red, green, or blue – 185. Why are you doing that? You know if the r, g, and b all equal the same thing, you get a shade of gray. That's why you end up with all gray, with all RGB values 185. Mark Guzdial |
I IMed a TA and found out the problem: the same picture gets reaoainted over and over, so the last one is almost white. You need to redefine each picture to be repainted seperately so that doesn't happen. Student1068
WritePictureTo command in the book and JES Help are not very explicit. The following instruction did not get me there either "Make sure that your function hw2 RETURNs the canvas, then in the command area, say "picture=hw2()", and then you should be able to use writePictureTo(picture,"anyname.jpg"). Mark Guzdial"
picture=hw2()in the command area resulted in my collage being displayed again. Also, the book and help tell you to put a path after picture,. I would appreciate a more detailed answer as to how to WritePictureTo. Perhaps an example where I have my picture displayed on my screen and I would like to save it on my desktop. Do I give the picture a name. I tried the following as one of many different attempts:
WritePictureTo(picture,"C:\Documents and Settings\Clarke\Desktop.jpg."
Your code contains at least one syntax error, meaning it is not legal jython.
Student1295
def collage():
art1=makePicture(getMediaPath("candy.jpg"))
art2=makePicture(getMediaPath("candy.jpg"))
canvas = makePicture(getMediaPath( "7inX95in.jpg"))
targetX=1
for sourceX in range (1,getWidth (art1)):
targetY=1
for sourceY in range (1,getHeight(art1)):
a=getPixel(art1, sourceX, sourceY)
c=getPixel(canvas, targetX, targetY)
color = getColor(getPixel(art1,sourceX,sourceY))
setColor(c, getColor(a))
targetY=targetY+1
targetX=targetX+1
clearRed(art2)
targetX =100
for sourceX in range (1,getWidth (art2)):
targetY=1
for sourceY in range (1,getHeight(art2)):
a=getPixel(art2, sourceX, sourceY)
c=getPixel(canvas, targetX, targetY)
color = getColor(getPixel(art2,sourceX,sourceY))
setColor(c, getColor(a))
targetY=targetY+1
targetX=targetX+1
clearBlue(art1)
targetX=200
for sourceX in range (1,getWidth (art1)):
targetY=1
for sourceY in range (1,getHeight(art1)):
a=getPixel(art1, sourceX, sourceY)
c=getPixel(canvas, targetX, targetY)
color = getColor(getPixel(art1,sourceX,sourceY))
setColor(c, getColor(a))
targetY=targetY+1
targetX=targetX+1
clearGreen(art2)
targetX=300
for sourceX in range (1,getWidth (art2)):
targetY=1
for sourceY in range (1,getHeight(art2)):
a=getPixel(art2, sourceX, sourceY)
c=getPixel(canvas, targetX, targetY)
color = getColor(getPixel(art2,sourceX,sourceY))
setColor(c, getColor(a))
targetY=targetY+1
targetX=targetX+1
mirrorhorizontal(canvas)
show(canvas)
return(canvas)
def mirrorhorizontal(pict):
canvas = makePicture(getMediaPath( "7inX95in.jpg"))
mirrorpoint=82
for y in range(1,82):
for x in range(1, 110):
ptop=getPixel(pict, x,82)
pbottom=getPixel(canvas, 110, 82)
setColor(pbottom, getColor(ptop))
def negative(pict):
for p in getPixels(pict):
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p, negColor)
Why isn't my set of pictures mirroring at all???????
Student967
| Tracy, please read the FAQ and format your code so that we can read it. You need to change the range of your mirroring. The way it's set up right now, you're not mirroring the whole canvas. Mark Guzdial |
Everything on my code is working fine except I can't figure out how to take the negative of the bottom half that has been mirrored. Suggestions? Lauren Patton
| As has been mentioned on this page several times before, you can't just do all the pixels with for p in getPixels(canvas). You need to use two loops, one for x and the other for y, and have them both work within a range of the rectangle of the picture that you want to turn negative. You'll have to use something like p = getPixel(canvas,x,y) to get each pixel before you try to turn it negative. Mark Guzdial |
Help! I cant get my negative code to work! Can someone tell me what I am doing wrong? Here is my code:
def negative(picture):
half=int(getHeight(picture)/2)
for x in range(1,int(getWidth(picture))):
for y in range(1,half):
p = getPixels(picture,x,y)
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(p,negColor)
the problem is with line"p=getPixels(picture,x,y)
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 84 of C:\Documents and Settings\kimberly\My Documents\hw2.py
>>>
REMOVEDberly Kessler
| REMOVEDberly, you wrote getPixels. The function you want is getPixel. Mark Guzdial |
I need help with WritePictueTo. The book and JES Help are not very explicit. The following response is not doing the trick for me either:
Make sure that your function hw2 RETURNs the canvas, then in the command area, say "picture=hw2()", and then you should be able to use writePictureTo(picture,"anyname.jpg"). Mark Guzdial
When I enter picture=hw2() in the command area. My program runs again and gives me a second copy of my completed picture. Perhaps an example would help. I have been trying many combinations with the result usually looking like these:
>>> WritePictureTo(picture,"C:\Documents and Settings\Clarke\Desktop.jpg."
Your code contains at least one syntax error, meaning it is not legal jython.
>>> WritePictureTo(picture,C:\Documents and Settings\Clarke\Desktop.jpg.
Your code contains at least one syntax error, meaning it is not legal jython.
>>> WritePictureTo(picture,C:\Documents and Settings\Clarke\Desktop\mypicture.jpg.)
Your code contains at least one syntax error, meaning it is not legal jython.
>>>
Help! Student1295
| Clarke, the name of the function is writePictureTo, NOT WritePictureTo. The syntax error that you're getting is that you are opening the parentheses and not closing, or opening the quotes and not closing. Mark Guzdial |
| The problem that people are having with setMediaPath not showing all the pictures: THAT'S ON PURPOSE. setMediaPath puts up a box to let you pick a FOLDER, not a FILE. Just choose MediaSources and click "Open." You won't go into MediaSources, you'll just select it. (If setMediaFolder works for you but not setMediaPath, you have an old version of JES.) Mark Guzdial |
#make half of canvas negative
def negative(flower):
half=int(getHeight(flower)/2)
for x in range(1,int(getWidth(flower))):
for y in range(1,half):
p = getPixel(flower,x,y)
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(p,negColor)
mirrorHorizontal(canvas)
show(canvas)
return(canvas)
The above is my code to make half the picture negative. The problem is, it's not doing anything. No error message, and no negative, either. It just returns a canvas with no negative and no errors at all! Please help! Student1217
| Why is it indented in, Andrea? All "def"'s should be against the left edge of the program area. Why do you call your input "flower" but then try to mirror the canvas? It looks to me like you defined your function in the middle of hw2. That won't work. Define it AFTER (look at the Collage example in the book), then CALL IT from within HW2. Mark Guzdial |
Well, I'm COMPLETELY confused now! I've sought answers to this all week. This is how it was explained today. I have no idea what you are suggesting, or how to fix what the problem is, because I don't know what the problem is. Canvas? That's the canvas. Flower is the flower (like barb)?????? Here's the whole code for your enjoyment! :)
def hw2():
flower=makePicture(getMediaPath("Lauren342x126.jpg"))
print flower
canvas=makePicture(getMediaPath("7inX95in.jpg"))
print canvas
#first picture (original) at left edge
targetX=1
for sourceX in range(1, getWidth(flower)):
targetY=getHeight(canvas)-getHeight(flower)-5
for sourceY in range(1, getHeight(flower)):
px=getPixel(flower, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
#second picture, clearRed
clearRed(flower)
targetX=126
for sourceX in range(1, getWidth(flower)):
targetY=getHeight(canvas)-getHeight(flower)-5
for sourceY in range(1, getHeight(flower)):
px=getPixel(flower, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
#third picture, greyScale
greyScale(flower)
targetX=252
for sourceX in range(1, getWidth(flower)):
targetY=getHeight(canvas)-getHeight(flower)-5
for sourceY in range(1, getHeight(flower)):
px=getPixel(flower, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
#forth picture, posterize
hw1(flower)
targetX=378
for sourceX in range(1, getWidth(flower)):
targetY=getHeight(canvas)-getHeight(flower)-5
for sourceY in range(1, getHeight(flower)):
px=getPixel(flower, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX=targetX+1
mirrorHorizontal(source)
show(canvas)
return(canvas)
def clearRed(picture):
for p in getPixels(picture):
setRed(p,0)
def greyScale(picture):
for p in getPixels(picture):
intensity=(getRed(p)+getGreen(p)+getBlue(p))/3
setColor(p, makeColor(intensity, intensity, intensity))
def hw1(picture):
#loop through the pixels
for p in getPixels(picture):
#get RGB values
red=getRed(p)
blue=getBlue(p)
green=getGreen(p)
#check and set red values
if(red>=200):
setRed(p, 255)
if (red>=128 and red<200):
setRed(p, 128)
if (red<128):
setRed(p, 64)
#check and set blue values
if(blue>=128):
setBlue(p, 192)
if(blue<128):
setBlue(p,red)
#check and set green values
if(green>=192):
setGreen(p, 192)
if(green<192):
setGreen(p, 64)
def mirrorHorizontal(source):
mirrorpoint=int(getHeight(source)/2)
for y in range (1, mirrorpoint):
for x in range(1, getWidth(source)):
p=getPixel(source, x, y+mirrorpoint)
p2=getPixel(source, x, mirrorpoint-y)
setColor(p2, getColor(p))
def negative(flower):
half=int(getHeight(flower)/2)
for x in range(1,int(getWidth(flower))):
for y in range(1,half):
p = getPixel(flower,x,y)
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(p,negColor)
I guess I do have a question: if I don't put the NEGATIVE function into the code - where do I call it? I'm confused!
| Why not call your negative function the same way you're calling clearRed and hw1 and mirrorhorizontal? Why should it be different? Mark Guzdial |
So I'm a little confused as far as what we can have for hw2...is it ok to have two or three defs in our program area, or should EVERYTHING be in the def for hw2? I'm pretty sure someone asked this earlier, but I wasn't too sure of the answer given. Student1192
| Read the Collage example in the book, Karin. You'll see multiple defs in the program area. Perfectly okay. You'll see each of the lower defs being "called" by the collage function. Mark Guzdial |
BE VERY CAREFUL!
Someone just wiped out this whole page! I retrieved it from the history, but be VERY careful editing at this point. This page is ENORMOUS. Mark Guzdial
Thanks, I'll try that. For some reason I was under the impression I needed to include the negative in the code. Thanks! Where else can you get answers from the professor at 10:40 at night?! :-) Student1217
i can't get my mirroring part to work:
def mirrorHorizontal(bcsm):
mirrorpoint = 110
for y in range (1,mirrorpoint):
for x in range(1,334):
pbottom = getPixel(bcsm,x,y+mirrorpoint)
ptop = getPixel(bcsm,x,mirrorpoint-y)
setColor(ptop,getColor(pbottom))
repaint(bcsm)
...help?
| Why are you using the numbers that you are, Susan? Are you making sure that you call mirrorHorizontal with your canvas? Mark Guzdial |
It worked - thank you! Kind of obvious, too, after all that. Student1217
If we mirror out picture that is cut into 4 quarters, we will have the same thing on both sides. How will the TA know that there are 4 separate things we did while only two will be mirrored when the picture is finished?
Student1189
My Jes is running really slow and it never finishes my entire program. After a few minutes it usually says not responding. What could be the reason for this and is there anything i can do to fix it?
Student966
| Make sure that you don't have triple loops, that you're not accidentally calling a function like mirrorHorizontal INSIDE a loop. You can use printNow() (look it up in the book index) to help you track where you are. Mark Guzdial |
This is my code so far, and when i run it i only get 2 out of the 4 pictures showing up on my canvas. It looks like the 1st and 3rd pictures are showing up blank because the pictures appearing are in the 2nd and 4th spaces across the top of the canvas. I can't figure out what i'm doing wrong. The picture i'm using is 100 pixels wide. Any help would be great!
def hw2():
snowboard=makePicture(getMediaPath("snowboarder.jpg"))
print snowboard
canvas=makePicture(getMediaPath("7inX95in.jpg"))
print canvas
#first picture, at left edge
targetX = 5
for sourceX in range(1,getWidth(snowboard)):
targetY = 1
for sourceY in range(1,getHeight(snowboard)):
px=getPixel(snowboard,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#second picture,105 pixels over
targetX = 105
for sourceX in range(1,getWidth(snowboard)):
targetY = 1
for sourceY in range(1,getHeight(snowboard)):
px=getPixel(snowboard,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#3rd picture, 310 pixels over
targetX = 310
for sourceX in range(1,getWidth(snowboard)):
targetY = 1
for sourceY in range(1,getHeight(snowboard)):
px=getPixel(snowboard,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#4th picture, 415 pixels over
targetX = 415
for sourceX in range(1,getWidth(snowboard)):
targetY = 1
for sourceY in range(1,getHeight(snowboard)):
px=getPixel(snowboard,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
show(canvas)
return(canvas)
jennifer sigg
| This one took me a LOOOONNNGGG time to figure out, Jennifer. Bottomline: Use AT LEAST TWO SPACES for each indentation level. Your spaces were all screwed up, but because you used only one space for each indentation level, it was really hard to see. Basically, the first and fourth pictures were never getting drawn because the loops were messed up. When I respaced EVERY LINE, it all worked. Mark Guzdial |
def hw2():
buz= getMediaPath ("yellowjacket.jpg")
buzz = makePicture(buz)
canva = getMediaPath("7inX95in.jpg")
canvas = makePicture(canva)
targetX=1
for sourceX in range ( 1, getWidth(buzz)):
targetY = 1
for sourceY in range ( 1, getHeight(buzz)):
color = getColor(getPixel(buzz,sourceX,sourceY))
setColor(getPixel(canvas,targetX,targetY))
targetY = targetY + 1
targetX = targetX + 1
for sourceX in range (1, getWidth(buzz)):
targetY=1
for sourceY in range(1, getHeight(buzz)):
color = getColor (getPixel (buzz, sourceX, sourceY))
setColor(getPixel(canvas, targetY, targetX))
targetY = targetY + 1
targetX = targetX + 1
for sourceX in range (1, getWidth(buzz)):
targetY=1
for sourceY in range(1, getHeight(buzz)):
color = getColor (getPixel (buzz, sourceX, sourceY))
setColor(getPixel(canvas, targetY, targetX),color)
targetY = targetY + 1
targetX = targetX + 1
JES keeps changing its mind about what is wrong with the function ive got so far. it was choosing a line of the program that i hadnt changed since early on and started saying it was wrong even after i had it working for a while. it will load fine then when i add on the next for loop it decides the one i had debugged was wrong again.
Student1272
| Nick – really, honestly, and truly – JES HAS NO MIND. It's just applying rules to execute your code. It can't change anything. The problem is that you have an extra space before "four sourceX" in your first loop – it's not lining up with targetY. Mark Guzdial |
def hw2():
france = makePicture(getMediaPath("france.jpg"))
print france
canvas = makePicture(getMediaPath("7inX95in.jpg"))
print canvas
#first picture (original) at left edge
targetX = 1
for sourceX in range(1, getWidth(france)):
targetY = getHeight(canvas)-getHeight(france
for sourceY in range(1, getHeight(france)):
px = getPixel(france, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY=targetY+1
targetX = targetX+1
#second picture, clearRed
clearRed(france)
targetX = 126
for sourceX in range(1, getWidth(france)):
targetY = getHeight(canvas)-getHeight(france)
for sourceY in range(1, getHeight(france)):
px = getPixel(france, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY = targetY+1
targetX = targetX+1
#third picture, greyScale
greyScale(france)
targetX = 252
for sourceX in range(1, getWidth(france)):
targetY = getHeight(canvas)-getHeight(france)
for sourceY in range(1, getHeight(france)):
px = getPixel(france, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY = targetY+1
targetX = targetX+1
#forth picture, clearBlue
clearBlue(france)
targetX = 378
for sourceX in range(1, getWidth(france)):
targetY = getHeight(canvas)-getHeight(france)
for sourceY in range(1, getHeight(france)):
px = getPixel(france, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY = targetY+1
targetX = targetX+1
show(canvas)
return canvas
def clearRed(picture):
for p in getPixels(picture):
setRed(p,0)
def greyScale(picture):
for p in getPixels(picture):
intensity = (getRed(p)+getGreen(p)+getBlue(p))/3
setColor(p, makeColor(intensity, intensity, intensity))
def clearBlue(picture):
for p in getPixels(picture):
setBlue(p,0)
def mirrorHorizontal(source):
mirrorpoint = int(getHeight(source)/2)
for y in range (1, mirrorpoint):
for x in range(1, getWidth(source)):
p = getPixel(source, x, y+mirrorpoint)
p2 = getPixel(source, x, mirrorpoint-y)
setColor(p2, getColor(p))
def negative(picture):
half = int(getHeight(flower)/2)
for x in range(1,int(getWidth(france))):
for y in range(1,half):
p = getPixel(france,x,y)
red = getRed(p)
green = getGreen(p)
blue=getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p,negColor)
HELP! I have been working on this forever and I have no idea what is wrong with the code. There are errors: here 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.
PLEASE HELP! I am soooo frustruated!
| Here's the line: targetY = getHeight(canvas)-getHeight(france Put a final paren on it and it'll load. Mark Guzdial |
hello, I'm keep running my code, and all I get is a "..." after I try to execute hw2(): I've even tried running my somebody else's whose worked just to see if there was an error in my code, but it did the same thing.
def hw2():
daisy=makePicture(getMediaPath("barb.jpg"))
print daisy
canvas=makePicture(getMediaPath("7inX95in.jpg"))
print canvas
targetX=1
for sourceX in range(1, getWidth(daisy)):
targetY=1
for sourceY in range(1, getHeight(daisy)):
px=getPixel(daisy, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY= targetY + 1
targetX= targetX + 1
negative(daisy)
targetX=140
for sourceX in range(1, getWidth(daisy)):
targetY=1
for sourceY in range(1, getHeight(daisy)):
px=getPixel(daisy, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY= targetY + 1
targetX= targetX + 1
decreaseRed(daisy)
targetX=280
for sourceX in range(1, getWidth(daisy)):
targetY=1
for sourceY in range(1, getHeight(daisy)):
px=getPixel(daisy, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY= targetY + 1
targetX= targetX + 1
posterize(daisy)
targetX=420
for sourceX in range(1, getWidth(daisy)):
targetY=getHeight(canvas)-getHeight(daisy)-5
for sourceY in range(1, getHeight(daisy)):
px=getPixel(daisy, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY= targetY + 1
targetX= targetX + 1
mirrorHorizontal(daisy)
def negative(picture):
for p in getPixels(picture):
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
negColor=makeColor(255-red, 255-green, 255-blue)
setColor(p, negColor)
def decreaseRed(picture):
for p in getPixels(picture):
value=getRed(p)
setRed(p, value0.5)
def posterize(picture):
for p in getPixels(picture):
red=getRed(p)
green=getGreen(p)
blue=getBlue(p)
if(red >= 200):
setRed(p, 255)
if(red >= 128 and red <= 200):
setRed(p, 128)
if(red < 128):
setRed(p, 64)
if(blue >= 128):
setBlue(p, 192)
if(blue < 128):
setBlue(p, getRed(p))
if(green >= 192):
setGreen(p, 192)
if(green < 192):
setGreen(p, 64)
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))
| I'll look into the "..." business, but in the meantime: Why are you mirroring "daisy" and not the "canvas"? And why aren't you returning anything? Mark Guzdial |
| I don't get any "...". I loaded your code into JES, and typed into the Command Area p=hw2(). I then got an arrayIndexOutOfBounds error, so you'll need to walk through your code. Mark Guzdial |
(previous person) even after putting the paranthesis, I still get errors. I ran codes from the book and small examples, and I'm never succesful. Maybe I'm doing something wrong. Is this right: you have the code on the top screen of jes. Then, in the command area you have the setMediaPath() thing all done – copied out of the book. Then, all you write is hw2()?(then load, after saving) Right? OR am I missing some big step that will solve the mystery to my problems?
| I didn't debug your program – just figured out how to get it to load. You're going to have to trace it out to make sure that it works. We are willing to help, but you have to work through it too. What errors are you getting? And where? You can't just copy this out of the book – you have to figure it out for yourself. Mark Guzdial |
| I changed your reference to france.jpg to flower1.jpg, and the whole thing ran fine. So my guess is that france.jpg is too large for these coordinates, so you're getting ArrayIndexOutOfBounds. Resize things and you'll be fine, I'll bet. Mark Guzdial |
Also, how do I know what numbers that should be seperating my pictures, i.e. what should the number be where 126 is? How do I find the heigth/width of the picture I am dealing with?
| If you open up this thing called MediaTools in JES, there is a picture option. Save your picture in the command area as some variable and then go into the picture option and on the pull-down menu clikc on whatever you named your picture. Then if you put the pointer on the edge of the picture you can get the height and width of your picture. Have you tried looking in the book? It also answers these questions as well as the Help section of JES. Ashley Coker |
| You can also print the picture to get the height and width, and you can use getHeight and getWidth. But you really don't NEED to get the actual values – you can do it all from working out the algebra. Mark Guzdial |
When I try to mirror my picture it always tells me a local or global name has not been defined, you need to define the funtion first. I have mirrorhorizontal defined and written into the main code. I have tried using different refences such as source, picture, and the name of my picture, but nothing works.
| What line does it say for where the name is not defined? What's on that line? Remember that you can also increase your error level from Normal to Expert (under Edit menu, Options item) and it'll tell you exactly WHICH name it can't find. Mark Guzdial |
It says the error is when the mirrorHorizontal(source) is written at the bottom of the main code.
| I've never seen an error that says "Local or global name not found: When mirrorHorizontal(source) is at the bottom of the main code." :-) What's the actual error message? What line does it list as the error? What is on that line? You do remember, I hope, that Python is case sensitive: If you have def mirrorHorizontal, you must call it mirrorHorizontal(canvas), and if you use mirrorhorizontal, it won't work. Mark Guzdial |
The error says: 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.
in file C:\Documents and Settings\mitchell\My Documents\cs\hw2, on line 46, in function hw2
NameError: source
Heres my code
def hw2():
cruz = makePicture(getMediaPath("cruz118.jpg"))
canvas = makePicture(getMediaPath("7inX95in.jpg"))
targetX = 1
for sourceX in range(1,getWidth(cruz)+1):
targetY = 1
for sourceY in range(1,getHeight(cruz)):
px=getPixel(cruz,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#red
increaseRed(cruz)
targetX = 90
for sourceX in range(1,getWidth(cruz)):
targetY = 1
for sourceY in range(1,getHeight(cruz)):
px=getPixel(cruz,sourceX,sourceY)
cx=getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#green
increaseGreen(cruz)
targetX = 200
for sourceX in range(1,getWidth(cruz)):
targetY = 1
for sourceY in range(1,getHeight(cruz)):
px = getPixel(cruz,sourceX,sourceY)
cx = getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#blue
increaseBlue(cruz)
targetX = 290
for sourceX in range(1,getWidth(cruz)):
targetY = 1
for sourceY in range(1,getHeight(cruz)):
px = getPixel(cruz,sourceX,sourceY)
cx = getPixel(canvas,targetX,targetY)
setColor(cx,getColor(px))
targetY = targetY + 1
targetX = targetX + 1
mirrorHorizontal(source)
show(canvas)
return(canvas)
def increaseRed(cruz):
for p in getPixels(cruz):
value = getRed(p)
setRed(p,154)
repaint(cruz)
def increaseGreen(cruz):
for p in getPixels(cruz):
value = getGreen(p)
setGreen(p,65)
repaint(cruz)
def increaseBlue(cruz):
for p in getPixels(cruz):
value = getBlue(p)
setBlue(p,value + 60)
repaint(cruz)
def mirrorHorizontal(source):
mirrorpoint = int(getHeight(source)/2)
for y in range(1, mirrorpoint):
for x in range(1, getWidth(source)):
p=getPixel(source, x, y+mirrorpoint)
p2=getPixel(source, x, mirrorpoint-y)
setColor(p2, getColor(p))
def negative(picture):
half = int(getHeight(cruz)/2)
for x in range(1,int(getWidth(cruz))):
for y in range(1,half):
p = getPixel(cruz,x,y)
red = getRed(p)
green = getGreen(p)
blue=getBlue(p)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(p,negColor)
| That's pretty clear, then. You say in hw2() "mirrorHorizontal(source)" But you have no picture named "source." Perhaps you meant "canvas" there? Mark Guzdial |
That runs the program but it leaves me with a blank image
I have an error with this line: cx = getPixel(canvas, targetX, targetY)... Why is that? This is in my second picture. The code is the same as above... so, why the error?
I figured it out: out of bounds image. What can I do about it? How do I fix it and what does that mean?
| targetX or targetY has gone beyond the edge of the canvas. You'll have to walk through your code and figure out why you ended up trying to copy into pixels that aren't there. Then, you'll have to change your coordinates so that the pictures fit onto the canvas, or use a larger canvas. Mark Guzdial |
For the questions above, I can see a small line of the image on the left side of the canvas, but everything else is white, could it be something wrong with negating it?
I mean right side
| I can't really guide you through this step-by-step here in the CoWeb. My suggestions are: (a) go see Ashley at Starbucks now until noon, (b) come to IC109 at 1 pm, (c) contact me or a TA via IM or email, and/or (d) work on it awhile on your own, and post questions when you're stuck. Mark Guzdial |
Ok, I've written all my defs for manipulation, mirroring, and making 1/2 the canvas negative...now where do I TELL jes to make 1/2 the canvas negative?? I've checked out other people's codes, and it looks like some of them tell jes to and some don't...Student1192
| Karin, I've answered that at least three times on this page – why don't you read above and see what you can find? Mark Guzdial |
I just got done reading this page and I still don't understand. It seems like some people don't even call "negative(picture)" and I don't see how that can happen. When I use my code as is, all I get back is a white canvas. This doesn't make sense to me because yesterday wehn I did it, it gave me back four pictures (before the neg. & mirroring) and I can't figure out what's so different that JES can't print even the four manipulated pictures. Sorry if I'm asking the same question, I'm just really lost. Student1192
def hw2():
#original picture + canvas
swanLake = getMediaPath("swanLake.jpg")
swan = makePicture(swanLake)
swan2 = makePicture(getMediaPath("swanLake.jpg"))
canvasf = getMediaPath("7inX95in.jpg")
canvas = makePicture(canvasf)
targetX = 1
for sourceX in range (1, getWidth(swan)):
targetY = 1
for sourceY in range (1, getHeight(swan)):
px = getPixel(swan, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#red pic
increaseRed(swan)
targetX = 104
for sourceX in range(1, getWidth(swan)):
targetY = 1
for sourceY in range(1, getHeight(swan)):
px = getPixel(swan, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#blue pic
increaseBlue(swan)
targetX = 207
for sourceX in range (1, getWidth(swan)):
targetY = 1
for sourceY in range (1, getHeight(swan)):
px = getPixel(swan, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY = targetY + 1
targetX = targetX + 1
#green pic
increaseGreen(swan2)
targetX = 311
for sourceX in range (1, getWidth(swan2)):
targetY = 1
for sourceY in range (1, getHeight(swan2)):
px = getPixel(swan2, sourceX, sourceY)
cx = getPixel(canvas, targetX, targetY)
setColor(cx, getColor(px))
targetY = targetY + 1
targetX = targetX + 1
mirrorHorizontal(canvas)
show(canvas)
return(canvas)
def increaseRed(picture):
for px in getPixels(picture):
value = getRed(px)
setRed(px, 205)
def increaseBlue(picture):
for px in getPixels(picture):
value = getBlue(px)
setBlue(px, 255)
def increaseGreen(picture):
for px in getPixels(picture):
value = getGreen(px)
setGreen(px, 205)
def negative(picture):
half = int(getHeight(picture)/2)
for x in range(1, int(getWidth(picture))):
for y in range(1, half):
px = getPixel(picture, x, y)
red = getRed(px)
green = getGreen(px)
blue = getBlue(px)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(px, negColor)
repaint(picture)
show(picture)
def mirrorHorizontal(canvas):
mirrorpoint = int(getHeight(canvas)/2)
for y in range(1, mirrorpoint):
for x in range(1, getWidth(canvas)):
p = getPixel(canvas, x, y+mirrorpoint)
p2 = getPixel(canvas, x, mirrorpoint-y)
setColor(p2, getColor(p))
what is this command reffering to?
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.
what is my problem?
| You probably mistyped the name of a function or variable. Mark Guzdial |
i have a quick question: when it says to "turn in your code, your original image, and your resulting image as "hw2"", what exactly does that mean. i know we turn in the code, but what do we attatch? (our original Picture?) thanks...
| Yes, all your original pictures – only one, if you used only one. Mark Guzdial |
Karin,
I had the same problem for a while...it would work until I tried to mirror and then I just got a blank, white canvas. As it tured out, I had the mirroring program written wrong. It was mirroring space that was already white onto my pictures, in effect. Keep changing your mirroring program (use all the examples in the book) until you can see your pictures again. Go through it line by line and see what you're doing. For example, right now, try switching those 'y+mirrorpoint' and 'mirrorpoint-y' around. See what it does then!
| Karin – that's EXACTLY your problem. Swap your p and p2 (works the same as the y+mirrorpoint and y-mirrorpoint switch that's recommend, but it's easier to swap p and p2). You're basically mirroring WHITE (from the bottom) on top of your pictures. Mark Guzdial |
Is it alright to negate half of the pictures instead of half of the canvas since my pictures are clustered in the top 1/2 of the canvas? (I know we can't do each picture individually, but say a single function to negate say the top 1/4 of the canvas)
Sean
| No, you must do half the canvas – that's written up in the assignment. Mark Guzdial |
I am trying to negate the left half of my collage and i am not quite sure i know what i am doing. Itried to combine range with the negative function but it does not seem to work right can someone please help me.
def negativeinrange(picture):
for x in range(1,54):
for y in range(1,77):
for px in getPixel(picture,x,y)
red = getRed(px)
green = getGreen(px)
blue = getBlue(px)
negColor = makeColor(255-red, 255-green, 255-blue)
setColor(px,negColor)
Paula Verden
| If you want to do the left half, Paula, you want for x in range(1,getWidth(picture)/2) and for y in range(1,getHeight(picture)). Mark Guzdial |
Professor guzdial can i see the eyesbluer program we wrote in breakout about a week ago it might help me a little. I thought i saved on my computer but it is not there. thank you
Paula Verden
| I didn't save it, Paula, but it's essentially the same as the red eye removal program on p. 100 in the book. Mark Guzdial |
ok my collage is getting generated and now i cannot get the program to write the canvas to my computer so i can upload it.
here is the line:
writePictureTo(picture, r"C:\Documents and Settings\NICOLE\Desktop\PaulaCollage\paulacollage.jpg")
and i get 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 98 of C:\Documents and Settings\NICOLE\Desktop\Jes Labs & Hws\hw2.py
Paula Verden
| In the command area, type |
>>>collage=hw2()
>>>writePictureTo(collage,r"C:\....\hw2.jpg")
using the address at which you want to save the collage. Student521 |
I am having trouble actually turning in my assignment. I receive a message that says, "An error has occurred in the turnin process. It is likely that the program turnin has failed. Please check JES's settings and resubmit the assignment. Error: File not found - gtg474g-HW_2.zip (Access is denied)" Any suggestions? May I just e-mail my assignment to my TA? Thanks for your help.
Sorry... posted by Student1125
Stephanie: Given the time (it's now 5:12), if you didn't figure out the problem in JES and didn't upload your code and image file to the Coweb manually, you should send it to your TA with an explanation as an email attachment. Colin Potts
| Actually (see the Grading Policy), you have 24 hours to turn it in, but be sure not to change your program at all so that the last time that the file is MODIFIED stays before the deadline. Mark Guzdial |
dfthtghfyh
Link to this Page