Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default 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)
    How can I square(^2) the pic in the grid-grid2.jpg

    makeGrid(3)
    How can I square(^2) the pic in the grid-grid3.jpg


    But the code should work like this as show:
    How can I square(^2) the pic in the grid-cater.jpg

    I dont know how can I square the pic

    I am new to java
    Chris
    thx
    Last edited by racewithferrari; 11-01-2009 at 10:23 PM. Reason: incomplete, tags

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Display Square Roots
    By hypes057 in forum New To Java
    Replies: 8
    Last Post: 08-25-2009, 10:34 AM
  2. change the square to triangle java
    By anotsu in forum New To Java
    Replies: 3
    Last Post: 07-09-2009, 11:17 AM
  3. Simple square root problem!
    By nortski in forum New To Java
    Replies: 7
    Last Post: 04-01-2009, 02:11 PM
  4. 8-Square puzzle loop
    By SapphireSpark in forum New To Java
    Replies: 7
    Last Post: 12-04-2008, 07:21 PM
  5. SWT OpenGL snippet: draw a square
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 06-28-2008, 09:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •