DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    15

    90 degree Rotation

    Hi, I'm trying to create a program that rotates a figure by 90 degrees clockwise. It is run in the command prompt, is supposed to output the new position of the figure. This program can be viewed as a foundation for tetris pieces. Here is an example of how it should look:

    [***]
    [-*-]
    [-*-]

    90 rotate

    [--*]
    [***]
    [--*]

    90 rotate

    [-*-]
    [-*-]
    [***]


    This is the result I get for the first 3 or 4 times the figure is rotated, but then I get random results after that. Could someone run my code and tell me what is going on?

    public class Rotation
    {
    public static boolean[][] isBlockPresent = new boolean[3][3];
    public static boolean[][] isMatrixBuffer = new boolean[3][3];

    public static void main(String args[])
    {
    isBlockPresent[1][0] = true;
    isBlockPresent[1][1] = true;
    isBlockPresent[2][1] = true;
    isBlockPresent[1][2] = true;

    for(int r = 0; r<3; r++)
    {
    System.out.print("[");

    for(int c = 0; c<3; c++)
    {
    if(isBlockPresent[c][r])
    System.out.print("*");
    else
    System.out.print("-");
    }

    System.out.println("]");
    }

    for(int m = 0; m<5; m++)
    {
    System.out.println();
    RotateClockwise();
    }

    }

    public static void RotateClockwise()
    {
    for(int r = 0; r<3; r++)
    {
    for(int c = 0; c<3; c++)
    isMatrixBuffer[c][r] = isBlockPresent[r][2 - c];
    }

    isBlockPresent = isMatrixBuffer;

    for(int r = 0; r<3; r++)
    {
    System.out.print("[");

    for(int c = 0; c<3; c++)
    {
    if(isBlockPresent[c][r])
    System.out.print("*");
    else
    System.out.print("-");
    }

    System.out.println("]");
    }
    }
    }



    Thanks,
    Ben.

  2. #2
    Join Date
    Jan 2006
    Posts
    15
    nvm, i solved it already. thx.

Similar Threads

  1. Search based on degree of separation
    By Skeptical in forum Database
    Replies: 0
    Last Post: 03-01-2005, 05:31 AM
  2. Replies: 12
    Last Post: 12-21-2001, 11:41 PM
  3. I refuse to get a degree.
    By Gregg in forum Talk to the Editors
    Replies: 4
    Last Post: 12-12-2001, 06:43 AM
  4. What sort of IT degree is good?
    By Jay in forum Careers
    Replies: 6
    Last Post: 03-14-2001, 04:21 PM
  5. Replies: 2
    Last Post: 10-05-2000, 07:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links