Useless / Mesmerizing

This is a discussion on Useless / Mesmerizing within the C++ Programming forums, part of the General Programming Boards category; This program is the most useless program ever, but I watched it for 5 minutes straight because it was so ...

  1. #1
    Unregistered User Overload's Avatar
    Join Date
    Jul 2004
    Posts
    12

    Useless / Mesmerizing

    This program is the most useless program ever, but I watched it for 5 minutes straight because it was so mesmerizing.

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    
    int main()
    {
    	int random;
    	int x;
    
    	do
    	{
    	random = rand();
    	cout<<random;
    	for(x=0; x!=50000; x++)
    	{
    	}
    	}while(!kbhit());
    
    	return 0;
    }

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    wow... its almost like watching a fire burn...

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Easily entertained ?

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    I wish i could run it but its not portable enough
    Woop?

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    No this is like watching a fire burn.

    Code:
    #define RGBTODWORD (r,g,b) ((r<<16)+(g<<8)+(b))
     
     
    RGB fire[30][100];
     
    void AddHeat(int heatvalue)
    {
      int x=rand() % 30;
      int y=rand()%100;
      fire[x][y]+=heatvalue;
      fire[x][y]&=0xFF;
    }
     
    void DrawFire(int x,int y)
    {
      int row=0,col=0;
      for (int i=x;i<x+30,i++)
      {
    	   for (int j=y;j<y+100;j++)
    	   {
    		  int heat=fire[col][row];
    		  if (heat>30)
    		  {
    			float coef=heat/255.0;
    			DWORD firecolor=RGBTODWORD(coef*255,0,0);
    			PlotPixel32(i,j,firecolor);
    		  }
    		  row++
    	   } 
    	   col++;
    	   row=0;
       }
    }
     
    void UpdateFire(int cooldownfactor)
    {
      for (int i=0;i<30;i++)
      {
    	 for (int j=98;j>0;j--)	 
    	 {
    	   int heat=fire[i][j+1];
    	   heat-=cooldownfactor;
    	   if (heat<0) heat=0;
    	   fire[i][j]=heat;
    	 }
      }
    }

    Just add main and a loop for your fire and watch to see what happens....that is, if I didn't make any mistakes.
    Last edited by VirtualAce; 07-28-2004 at 12:29 AM.

  6. #6
    nbk
    nbk is offline
    meow nbk's Avatar
    Join Date
    Jul 2004
    Posts
    45
    I almost fell asleep

  7. #7
    Unregistered User Overload's Avatar
    Join Date
    Jul 2004
    Posts
    12
    Quote Originally Posted by Vicious
    wow... its almost like watching a fire burn...
    After i read that post I went back and watched it, and it really does look like a fire burning if you just unfocus your eyes! (Like with those 3-D picture books...)

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    60
    I don't know what <.h> files to include. Which ones!
    Child who knows C++
    Using Borland C/C++ Compiler 5.5 (Command Line Version)

  9. #9
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    Quote Originally Posted by Bubba
    No this is like watching a fire burn.

    Code:
    #define RGBTODWORD (r,g,b) ((r<<16)+(g<<8)+(b))
     
     
    RGB fire[30][100];
     
    void AddHeat(int heatvalue)
    {
      int x=rand() % 30;
      int y=rand()%100;
      fire[x][y]+=heatvalue;
      fire[x][y]&=0xFF;
    }
     
    void DrawFire(int x,int y)
    {
      int row=0,col=0;
      for (int i=x;i<x+30,i++)
      {
    	   for (int j=y;j<y+100;j++)
    	   {
    		  int heat=fire[col][row];
    		  if (heat>30)
    		  {
    			float coef=heat/255.0;
    			DWORD firecolor=RGBTODWORD(coef*255,0,0);
    			PlotPixel32(i,j,firecolor);
    		  }
    		  row++
    	   } 
    	   col++;
    	   row=0;
       }
    }
     
    void UpdateFire(int cooldownfactor)
    {
      for (int i=0;i<30;i++)
      {
    	 for (int j=98;j>0;j--)	 
    	 {
    	   int heat=fire[i][j+1];
    	   heat-=cooldownfactor;
    	   if (heat<0) heat=0;
    	   fire[i][j]=heat;
    	 }
      }
    }

    Just add main and a loop for your fire and watch to see what happens....that is, if I didn't make any mistakes.
    do you need to include any headers beside cstdlib? what do you need for type RBG?

    edit: sorry for repeating child, started this yesterday and finished it today

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    60
    We're wondering what headers to include. ({(<Waiting.>)})
    Child who knows C++
    Using Borland C/C++ Compiler 5.5 (Command Line Version)

  11. #11
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    C++child no need to be rude. By the looks of it probably windows.h or knowing bubba some direct x header(i have no clue cause i never even touched direct x) or it could even be openGL?
    Woop?

  12. #12
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I believe that would be Windows API graphics calls actually

    So include <windows.h>
    create a window.. and call these functions in your loop.
    Last edited by Vicious; 07-30-2004 at 10:05 PM.

  13. #13
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Judging by the call to PlotPixel32, it came from a DirectX program (Andre LaMothe?)

    It is not necessarily DirectX or windows, though...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    That code can be DOS, DirectX, OpenGL, or Windows.

    Your choice. Sorry I forgot all about this thread and so I didn't know all of you were wondering about the headers.

    All you need to do to port it is to write your PlotPixel32 function. Since the algo is not API specific you can use it any way you want.

  15. #15
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Code:
    void PlotPixel32(DWORD *Buffer,int x,int y,DWORD color,int bufwidth)
    {
      Buffer[(y*bufwidth+x)<<2]=color;
    }
    
    void PlotPixel32Ex(DWORD *Buffer,int x,int y,DWORD color,int bufwidth)
    {
       asm {
         push  edi
         
         les    edi,[Buffer]
         mov  eax,[y]
         mov  ebx,[bufwidth]
         mul   eax,ebx
         add   eax,[x]
         shl    eax,2
         add  edi,eax
         mov  eax,[color]
         stosd
         
         pop  edi
       }
    }
    If you want to know which is faster profile it because I cannot make any guarantees that the assembly version is faster.

    This only works if the color is defined as ARGB or XRGB.
    Code:
    #define RGBTODWORD(a,r,g,b)  (DWORD)((a<<24)+(r<<16)+(g<<8)+(b))
    Since y*bufwidth+x will never exceed 32-bits then you don't need to worry about what is in EDX because it will be all zeros. Mul will multiply EAX by r/m 32 and leave the result in EDX:EAX where EDX is the high order 32-bits and EAX is the low-order 32-bits. The CF and OF flags are cleared if EDX is zero (which in this case it will be so no need to check).

    Since most cards support ARGB and XRGB natively you are fairly safe in assuming this snippet will work on all current video hardware.

    For DirectX you simply would use SURFACEDESC.MemPitch for the width value instead of the actual width of the screen. This in turn would not need to be shifted left by 2 since the MemPitch takes care of that.

    In Windows you simply need to get a pointer to the HDC, then to the client area of the HDC and write a 32-bit value to the client area using the API or by getting a pointer directly to the buffer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. yacc: type clashes and useless nontermins
    By zxcv in forum Linux Programming
    Replies: 1
    Last Post: 02-14-2009, 01:52 AM
  2. another sort useless program
    By mrsirpoopsalot in forum C Programming
    Replies: 21
    Last Post: 09-18-2006, 02:35 AM
  3. useless post just saying thanks
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2005, 09:27 PM
  4. Corollary to Feb. 8th useless fact Corollary:
    By Drewpee in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 02-13-2002, 02:44 AM
  5. Useless fact of the day
    By CoderBob in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-07-2002, 07:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21