Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Summer 2004 Homework 2 Questions

Questions on making your collages?

What time tomorrow is the HMK due?
All assignments are due at 5:00p.m. the day they are due unless otherwise specified.

I want to make sure I put my pictures in the correct place using the getMediaPath function, how do I set my media path the same as the TAs for grading purposes? thanks, Adair Schwartz
Dont worry about that, we will overwrite the mediapaths so that they refer to the proper places. Just be sure to turn in your pictures with your assignement. Larry Olson

do the four pictures have to cover the entire 7x95in jpg, because the picture that I am using is kind of small so it does not cover the entire page and hence some space is left is that ok?
Yes that's okay. The entire canvas does not need to be covered as long as there is an image in each of the four quadrants. Nicole Seekely

what if i want to crop the picture and use that cropped one as an original? how do i set that up without copying it to the canvas 1st?

One way of cropping a picture is just to specify the pixels that you want copied in the range for the x and/or why loop. For example, if you wanted to crop off the left 25 columns of pixels, you would do something like:
for sourceX in range(26, getWidth(pic)+1):
However, you would need to do that every time you copy the picture onto the cavas. See Slide 25 from May 28th lecture. Otherwise, you can crop the actual image using JES in the same fashion and then save it using the writePictureTo function. Nicole Seekely

how do i make a 7x95in canvas?

The 7x95in.jpg is in the media sources directory already. There's also a function on page 96 called makeEmptyPicture(x,y) that lets you create a blank. For some reason it's not mentioned in the "FUNCTIONS AND OBJECTS SUMMARY" for chapter 3
Sorry – I have already corrected that for the Fall version of the book. Mark Guzdial


everything works fine when I'm simply copying the original pic to the canvas but as soon as I try to do the collage I get an error:

code: setColor(getPixel(canvas,targetX,targetY),color)

error message: A local name was used before it was created. You need to define the method or variable before you try to use it.

Am I missing something?

Are you sure that you have previously defined each of those variables that you used (i.e. canvas, targetX,targetY, AND color)? If that's not the case, then maybe post some more of your code so we can figure out what's wrong. Nicole Seekely

It's unclear in the assignment which 'quadrants of the picture' we're working with. Do we code our original and altered pictures to be in four adjacent quandrants, or do we put each picture in each of the four quadrants of the canvas?
If I understand what you're asking correctly, you should have at least ONE original and/or altered picture in each of the four quadrants OF THE CANVAS. So the basic requirement would be to have the original picture in quadrant1 of the canvas, then an altered picture in quadrant 2 of the canvas, an altered in quadrant 3, and an altered in quadrant 4. Hope that clarifies it! Nicole Seekely

stupid question...how exactly do you use the writePictureTo function?

Everything works in my hw2 except for the writePictureTo function, usually picture is in the (parenthesis), so we do writePictureTo(picture, "location"). But since we're using a picture and the canvas what do we put for the name in place of picture?
Thanks

To answer both those questions... the writePictureTo is used at the end of your code/function. (It would be in a spot such as where you would put repaint(picture) or something of the sort.) So after you're done manipulating the picture, you insert writePictureTo(picture,location). This saves the manipulated picture to your computer. Be careful with the variable "picture" - for this assignment, you would most likely be putting "canvas" or whatever you named your canvas as since that is the final image you want. For location, you can either put the direct path and filename such as r"C:/JES/mediasources/hw2.jpg" or you can just put "hw2.jpg". Nicole Seekely

I am having the same problem as the person above. I can make everything work when I'm copying the original picture, but as soon as I try to do another one it has an error. This is the line that is not working:

setColor(getPixel(canvas,targetX,targetY),color)

And this is the error message it is giving me:

I wasn't able to do what you wanted. The error java.lang.ArrayIndexOutOfBoundsException has occured

I made sure I had already named everything like you told him to do, but I don't think that is the problem I'm having. Here is some of my code before that line...

targetX = 280
for sourceX in range(1,getWidth(pic)):
targetY = 1
for sourceY in range(1,getHeight(pic)):
px=getPixel(pic,sourceX,sourceY)
color = getColor(px)
setColor(getPixel(canvas,targetX,targetY),color)
Okay, so you're getting an Out of Bounds error which means JES is telling you you're trying to access pixels that don't exist. It looks like you're trying to copy a picture into the top right quadrant? There's only about 500 pixels give or take a few width-wise in the canvas. So if your picture is greater than 500 minus 280 wide, you'll be copying pixels beyond the existence of the canvas. So maybe try setting your targetX to a smaller number and see if it works. Let me know if this is the problem or not! Nicole Seekely

I am having trouble putting my pictures in different quadrants. I can get the pictures to line up next to each other, but I can't get them into four quadrants. I looked on all the slides and in my notes, but can't find out how to do it...HELP!?!?
All ya gotta do is change the targetX and targetY for each picture to get them to change position. For example, to place the picture in the first quadrant, you would set targetX and targetY = 1, to place in the second quadrant, target X=250, targetY=1; to place in third quadrant, targetX=1 targetY=350, and so on. Just basically, the more you want the picture to move down or over, the higher the target values. Just be sure that your picture doesn't run off the canvas because then you'll get an out of bounds error. Nicole Seekely

That was it! I changed targetX to 220 and it works! Thanks sooo much!!

I tried using writePictureTo(canvas,"location"), I think I'm just not putting in the right things in the command box. I used hw2() it gives me the collage, a comment about the sizes and the media instance but it doesn't write the picture to file. Help please!

Nevermind, I just got it to write to file!

whenever my picture appears at the end of the program, only a white picture shows up. Does it have to do with my code or my original picture?
Really, it could be either. Most likely it is the code though. Larry Olson

Helpful hint regarding (clockwise) quadrants – Q1 = (1,1); Q2 = (Width/2,1); Q3 = (Width/2, Height/2); Q4 = (1, Height/2). If you are getting an out of bounds error you might consider checking to make sure that x,y is valid before you try to pull/place/modify a pixel there. –This will allow you to have a picture that "runs off the canvas"

everytime i type show(canvas) in the program area it gives me the error message: "SyntaxWarning: local name 'canvas' in 'hw2' shadows use as global in nested scopes
def hw2():"
Then it when i type return canvas it gives the following message:"Your code contains at least one syntax error, meaning it is not legal jython."

WHAT AM I DOING WRONG!?
Good question, email me your code or post it here. Alternately, visit a TA in office hours Larry Olson

the very last of my code is
show(canvas)
return(canvas)
writePictureTo(canvas, r"C:/JES/mediasources/hw2.jpg")
so that should save my collage in mediasources right? Except it's not there, for me to turn in or upload onto the collage posting page. Should i have put something else in the writePictureTo function? This is way confusing.
There is a reason it isnt there. You have placed your writePictureTo() function below a return. When the computer sees a return it immediately thinks "Ok, Im done, there must not be anything beyond this, Im going to give control back to the user along with anything else ive been working on". In this case, you are regaining control of the computer and you are getting your canvas back. The computer never even executes the writePictureTo statement. Larry Olson

oh. well that makes sense.

Link to this Page