Results 1 to 14 of 14
Thread: creating a make grid method
- 10-23-2010, 02:38 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
creating a make grid method
I need to create a method that makes a square grid, size images wide by size images wide, of duplicate copies of the original image. Every other row needs to be negated. Here's the code I have so far:
Java Code:public Picture makeGrid(int size) { Picture targetPicture = new Picture(this.getHeight()*size, this.getWidth()*size); //declares both the source pixel and target pixel and sets it to null Pixel sourcePixel = null; Pixel targetPixel = null; int targetX = 0; int targetY = 0; //loops through the source picture columns for (int sourceX = 0; sourceX < sourcePicture.getWidth(); sourceX++) { //loops through the source picture rows for (int sourceY = 0; sourceY < sourcePicture.getHeight(); sourceY++) { //set sourcepixel = correct pixel sourcePixel = this.getPixel(sourceX,sourceY); //gets the 3 colors for (int indexX = 0; indexX < size; indexX++) { for (int indexY = 0; indexY < size; indexY++) { targetX = sourceX * size; targetY = sourceY * size; targetPixel = targetPicture.getPixel(targetX,targetY); //set pixel = correct pixel int red = targetPixel.getRed(); int green = targetPixel.getGreen(); int blue = targetPixel.getBlue(); {//if row is even if (sourceY%2==1 ) { // negates the colors targetPixel.setColor(new Color(255 - red, 255 - green, 255 - blue)); //gets the source and target pixels } else targetPixel.setColor(sourcePixel.getColor()); } } } } } return targetPicture;Last edited by Fubarable; 10-23-2010 at 03:05 AM. Reason: Moderator Edit: Code tags added
-
Hello, and welcome to the forum.
You may need to provide more information so that we'll know more about your problem and be better able to help you. For instance what does your current code do or not do? What error messages are you seeing? What functionality is still missing and how have you tried to supply this functionality? What is the Picture class? Pixel class? And the same for all other classes that are not part of standard Java. The better the question, usually the better the answer.
Also, I have edited your code and added code tags which should help make your posted code retain its formatting and be more readable.
To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Best of luck, and again, welcome!Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 10-23-2010, 06:30 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
Thanks for the welcome.
The current code returns a blank picture. What is supposed to be returned is duplicates of the picture depending on what number is entered into the parameter. Such as, if you enter 2 into the parameter, 4 duplicates of the picture are shown, the two on the first row are the same, but the 2 on the second row are negated. If 3 is entered into the parameter you get 3 rows of 3 pictures the middle row being negated, etc.
I think that the rest of the code is correct. I just don't know what to put into targetX and targetY (the pixels of the target picture) to get it to work.
- 10-27-2010, 07:25 AM #4
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
In your first loop shouldn't it be this.getWidth not sourcePicture??
- 10-27-2010, 09:17 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
I assume I'm probably at the same school as Matt because we have an identical assignments and my code looks extremely similar to his.
Why're you multiplying the length and with by size? to my (limited) understanding the size variable is only related to the size of the finished project in how many times size said to copy the target pic.
but yeah, I'm lost so that possibly (probably?) isn't true.
- 10-28-2010, 01:46 AM #6
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
Are you taking CSI 201 at SUNY Albany? You're probably right about the size variable. I really don't understand how entering a number into the parameter is supposed to duplicate the images. Wouldn't it just make the picture bigger since you're multiplying it by the height and width of the picture.
- 10-28-2010, 04:23 AM #7
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Yup, thats the class. Somebody on the blackboard forums said to use the scale up method to do it. as for the inverse thing, I came down to nearly the same solution as yours. mine is slightly different; "if ((grid % 2.0) == 0)"
I cant even test any of the code because I stupidly just bought a new laptop, and sold my new one. Dr java + 64bit apparently doesn't mix well. fail.
I'm planning on heading to office hours tomorrow, which will hopefully make this all more clear.
- 10-28-2010, 05:18 AM #8
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
Try new JDK update... what problems do you get with Drjava and 64bit? I'm taking 201 too. already finished the assignment but i'd rather not give you the whole code..
What you're actually doing is making a completely NEW picture that increases in size according to the parameter (size) to tell it to.. So you're using the same amount of columns/rows in the targetpicture as the sourcepicture but increasing the amount of rows/columns because of the size parameter..
I spent like 3 hours with my TA friend doing this last night -.-
- 10-28-2010, 05:26 AM #9
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
And you're fine with the
" Picture targetPicture = new Picture(this.getHeight()*size, this.getWidth()*size);"
part cause I used it too except i made it targetPic just to make it abit shorter.
- 10-28-2010, 05:29 AM #10
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Just an infinite amount of errors with the picture.java file, my code is fine bug wise. when I compile it throws errors for stuff I haven't touched (that worked fine when i was working with 32 bit) Ill look into the new jdk.
Im sure Ill knock this out tomorrow but im a very trial and error kind of guy and not being able to test is killing me
- 10-28-2010, 10:02 PM #11
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
im working on the same assignment and my code is almost identical all i get back when i run the program is the original image i started with. has anyone came up with a fix to this code?
- 10-29-2010, 01:23 AM #12
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Yup, got mine working perfectly. Its the scaleUp method, with a few lines to inverse the color and switching the +/* symbols at the bottom. also switching out numSwaps or whatever their variable was for our new one
- 10-29-2010, 01:35 AM #13
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Oh, and by the way, matt if you're still reading this IDK how good an idea posting the code up here is. considering other people from the same class found it there is a chance that a TA or the teacher could find it, and that probably wouldn't be very good for your grade.
- 10-29-2010, 02:47 AM #14
Member
- Join Date
- Oct 2010
- Posts
- 9
- Rep Power
- 0
Has anyone figured out the code for this yet? I am able to get the program to spit out a picture that's the proper size but the caterpillar isn't duplicated, only the original shows up in the corner. I'm guessing that the problem lies in the coordinates for the target pictures pixel and I just can't figure out what they should be. Anybody know what to do here?
targetPixel = targetPicture.getPixel(x,y);
Thanks in advance.Last edited by Brainz; 10-29-2010 at 02:55 AM.
Similar Threads
-
How to make a MouseListener Method to do multy tasks?
By Laythe in forum Java AppletsReplies: 6Last Post: 12-13-2009, 02:44 AM -
Static method cannot make new objects?
By zerkz in forum New To JavaReplies: 2Last Post: 10-15-2009, 03:17 AM -
Use an internal Method or Make a class file?
By TimHuey in forum New To JavaReplies: 2Last Post: 09-18-2009, 03:06 PM -
Creating Make File
By kiki2009 in forum New To JavaReplies: 7Last Post: 07-11-2009, 01:20 PM -
Help creating a changing grid
By adlb1300 in forum New To JavaReplies: 11Last Post: 10-24-2007, 01:41 PM


LinkBack URL
About LinkBacks


Bookmarks