Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 16th, 2011, 08:34 PM
tdmei tdmei is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 5 tdmei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 33 sec
Reputation Power: 0
Frame Buffer Line drawing

Hi all,
Can anyone give an example of frame buffer line drawing?

Reply With Quote
  #2  
Old May 16th, 2011, 09:25 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
See the answer on the other forum you posted this question on.

Reply With Quote
  #3  
Old May 16th, 2011, 09:38 PM
tdmei tdmei is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 5 tdmei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
See the answer on the other forum you posted this question on.

Quote:
Originally Posted by NormR
What is the output that the program generates?
What's wrong with it?

You need to draw a grid on paper and look at it line by line to see what must be output for each line


the thing is I'm lost in writing the display and clear function. Thank

Reply With Quote
  #4  
Old May 17th, 2011, 12:53 AM
ChristopherLowe ChristopherLowe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 50 ChristopherLowe User rank is Private First Class (20 - 50 Reputation Level)ChristopherLowe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 43 m 47 sec
Reputation Power: 3
It looks as though you are confusing pixels with characters. Pixels are the individual 'dots' that make up a screen.

You cannot clear characters from the text console per say. It takes a dirty little hack like this to clear the console's output:

Code:
public void clear() {
  for (int i = 0; i < 23; i++) {
     System.out.print("\n");
  }
}


You can display your 2D array of booleans like so:
Code:
public void display(boolean[][] pixels) {
  for (int x = 0; x < pixels.length; x++) {
     for (int y = 0; y < pixels[].length; y++) {
         if (pixels[x][y]  == true) {
             System.out.println("*");
         } else {
             System.out.println(" ");
         }
    }
}

Reply With Quote
  #5  
Old May 17th, 2011, 06:53 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
Cross posted at:

http://www.javaprogrammingforums.com/whats-wrong-my-code/8974-java-frame-buffer-line-drawing.html#post32374

Reply With Quote
  #6  
Old May 17th, 2011, 03:55 PM
tdmei tdmei is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 5 tdmei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 33 sec
Reputation Power: 0
Thanks a lot,

Reply With Quote
  #7  
Old May 17th, 2011, 04:03 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
Quote:
got the following error when trying to compile. any suggestion ?
NOTE: NPEs occur in execution not at compile.

Exception in thread "main" java.lang.NullPointerException
at ConsoleFrameBuffer.display(ConsoleFrameBuffer.java:24)
at ConsoleFrameBuffer.main(ConsoleFrameBuffer.java:41)

What variable at line 24 is null?
The display() method is called from line 41

Reply With Quote
  #8  
Old May 17th, 2011, 04:24 PM
tdmei tdmei is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 5 tdmei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
What variable at line 24 is null?
The display() method is called from line 41



Thanks

Reply With Quote
  #9  
Old May 17th, 2011, 04:33 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
Quote:
What variable at line 24 is null?

And why is that variable null?

Where has pixels been assigned a value?

Reply With Quote
  #10  
Old May 17th, 2011, 07:28 PM
ChristopherLowe ChristopherLowe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 50 ChristopherLowe User rank is Private First Class (20 - 50 Reputation Level)ChristopherLowe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 43 m 47 sec
Reputation Power: 3
Code:
public class ConsoleFrameBuffer { 

    private boolean pixels[][]; 
    private int width, height; 

    public ConsoleFrameBuffer(int width, int height) 
	{
		this.height=height; 
		this.width=height;
		pixels = new boolean[width][height];
	}     
    
	public ConsoleFrameBuffer() 
	{
		this.width=79;
		this.height=23;
		pixels = new boolean[width][height];
	}
	
    void setPixel(int x, int y, boolean b) {
		pixels[x][y] = b;
	}
  
    void setPixel(int x, int y) {
		pixels[x][y] = true;
	}             

    int getWidth() {
		return width;
	}
 
    int getHeight() {
		return height;
	} 

    public void clear() { 
          for (int i = 0; i < 23; i++) { 
             System.out.print("\n"); 
        } 
    } 


    public void display() { 
          for (int x = 0; x < getWidth(); x++) { 
             for (int y = 0; y < getHeight(); y++) { 
                 if (pixels[x][y]  == true) { 
                     System.out.print("*"); 
                 } else { 
                     System.out.print(" "); 
				} 
			}
		System.out.println();
		} 
    } 
    
    public static void main(String [] args) { 
        ConsoleFrameBuffer fb = new ConsoleFrameBuffer(); 
        //fb.display(); 
        int x = 0, y = 0; 
        while (x < fb.getWidth()) { 
            while (x < fb.getWidth() && y < fb.getHeight()) 
                fb.setPixel(x++, y++); 
            y--; 

            while (x < fb.getWidth() && y >= 0) 
                fb.setPixel(x++, y--); 
            if (y < 0)y = 0; 
        } 

       fb.clear(); 
       fb.display(); 
    } 
}



Output
Code:
*
 *
  *
   *
    *
     *
      *
       *
        *
         *
          *
           *
            *
             *
              *
               *
                *
                 *
                  *
                   *
                    *
                     *
                      *
                      *
                     *
                    *
                   *
                  *
                 *
                *
               *
              *
             *
            *
           *
          *
         *
        *
       *
      *
     *
    *
   *
  *
 *
*
*
 *
  *
   *
    *
     *
      *
       *
        *
         *
          *
           *
            *
             *
              *
               *
                *
                 *
                  *
                   *
                    *
                     *
                      *
                      *
                     *
                    *
                   *
                  *
                 *
                *
               *
              *
             *


The main change I made was to instantiate the boolean array. Also fixed a few bugs and formatting issues. The actual logic is all yours and looks like it needs a few tweaks to produce the desired output.

In the future, please make your code more readable if you want people to be able to help you with it.

Also, I noticed you have imports for and Applet. This is all character console stuff (which is why I was upset earlier about the use of the word pixel here). You will need to take a look at java.awt.BufferedImage if you want to use actual pixels.

Reply With Quote
  #11  
Old May 17th, 2011, 07:37 PM
tdmei tdmei is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 5 tdmei User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 33 sec
Reputation Power: 0
Thumbs up

ChristopherLowe, thank you so much. I understand much better right. Thank you for your help.

Reply With Quote
  #12  
Old May 17th, 2011, 07:46 PM
ChristopherLowe ChristopherLowe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 50 ChristopherLowe User rank is Private First Class (20 - 50 Reputation Level)ChristopherLowe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 43 m 47 sec
Reputation Power: 3
No problem at all my friend.

If you would like a hand converting this into an applet just say so.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Frame Buffer Line drawing

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap