ah124131 0 Newbie Poster

Alright, I posted earlier with help on compiling my method, now it compiles and now I am stuck again. Help would be great since this awful head cold is getting the best of me.

Ok so, so far I have my method almost where I need it, I have my picture that opens up in to a black area in the upper left hand corner. Now the tricky part, multiplying that image within these parameters. So if I do makeGrid(2) I should see 4 of the same picture in a grid like manner. Here is my code again:

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 + indexX;
targetY = sourceY * size + indexY;
          targetPixel =targetPicture.getPixel(targetX, targetY);
          targetPixel.setColor(sourcePixel.getColor());
        }
      }
    }
  }
  return targetPicture;
}
}

Any helpful hints or suggestions would be much appreciated! Thanks =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.