Results 1 to 2 of 2
- 11-01-2009, 10:08 PM #1
How can I square(^2) the pic in the grid
How can I square(^2) the pic in the grid?
public Picture makeGrid(int size)
{
Picture targetPicture = new Picture(this.getWidth()*size, this.getHeight()*size);
Pixel sourcePixel = null;
Pixel targetPixel = null;
int targetX = 0;
int targetY = 0;
//loop through the source picture columns
for(int sourceX = 0; sourceX < this.getWidth(); sourceX++)
{
//loop through the source picture rows
for(int sourceY = 0; sourceY < this.getHeight(); sourceY++)
{
// get the source pixel
sourcePixel = this.getPixel(sourceX,sourceY);
// loop copying to the target y
for(int indexY = 0; indexY <size; indexY++)
{
// loop copying to the target x
for(int indexX = 0; indexX < size; indexX++)
{
targetX = sourceX + size*2 + indexX;
targetY = sourceY + size*2 + indexY;
targetPixel =targetPicture.getPixel(targetX, targetY);
targetPixel.setColor(sourcePixel.getColor());
}
}
}
}
return targetPicture;
}
my code give the following result:
makeGrid(2)

makeGrid(3)

But the code should work like this as show:

I dont know how can I square the pic
I am new to java
Chris
thxLast edited by racewithferrari; 11-01-2009 at 10:23 PM. Reason: incomplete, tags
-
Two suggestions:
1) Read what JavaRanch has to say about providing enough details for your question to be answerable: TellTheDetails
2) Please use code tags when posting code.
Much luck.
Similar Threads
-
Display Square Roots
By hypes057 in forum New To JavaReplies: 8Last Post: 08-25-2009, 10:34 AM -
change the square to triangle java
By anotsu in forum New To JavaReplies: 3Last Post: 07-09-2009, 11:17 AM -
Simple square root problem!
By nortski in forum New To JavaReplies: 7Last Post: 04-01-2009, 02:11 PM -
8-Square puzzle loop
By SapphireSpark in forum New To JavaReplies: 7Last Post: 12-04-2008, 07:21 PM -
SWT OpenGL snippet: draw a square
By Java Tip in forum SWTReplies: 0Last Post: 06-28-2008, 09:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks