Dark Bit Factory &  Gravity
		GENERAL => Challenges & Competitions => Topic started by: Clyde on July 08, 2006
		
			
			- 
				Now this I've had quite a few headaches with, first one being that there's no Load / Set Font command like in Blitz. And I don't really know what the default font is or it's dimensions are. Im guess it's 8x8. Also, found that with certain calculations there's this annoying 'beep'. I presume it's linked to a certain Chr() number, but can't find the source of it. Also I've had to leave a 1 place border around the effect, due to getting odd results with having it as a full screen render. Probably due to the font not being a fixed width, and the Print Chr(); 
Also I've tried to make this as simple as possible due to time and life comitments, but I recon it's not turned out too badly. I could of course, cheated and loaded in and converted a fixed width font to use as the rendering, and do it in the old fashion of using a customized Bitmap Font lib, but I wanted to experiment with the standard printing. I've also opted for using GFXlib, as I found that the easiest way of going about it.
Hope it inspires people with their entries, and also hope it works on your systems.  And a big thanks to Optimus for inspiring the Plasma method.
Ok then here goes:
'
' ASCII Render Engine V1.01
' Credits: Code By Clyde 
' Plasma Inspired By Optimus
'
Option Static
Option Explicit
Const XRES=640
Const YRES=480
Const PI = 3.14151693
Dim Shared Vel
Dim Shared ScreenNo
Dim Shared Pal(255)
Dim Shared Sin1(4095),Sin2(4095),Sin3(4095)
Declare Sub CreatePal(Â  Byval Val1 As Integer, Byval Val2 As Integer, Byval Val3 As Integer )
Declare Sub InitializeASCII()
Declare Sub RunASCII()
Declare Sub UpdateASCIIPlasma()
InitializeASCII()
RunASCII()
Sub CreatePal(Â  Byval Val1 As Integer, Byval Val2 As Integer, Byval Val3 As Integer )
  Â  
  Â  '
  Â  ' Local variables.
  Â  '
  Â  Dim As Integer a, m, r, g, b
  
  Â  For a=0 To 255
  Â  Â  Â  
  Â  Â  Â  m = a*( 360/255 ) 
		
  Â  Â  Â  r = Cos(( m+Val1 )*( PI/180 )) *127+127
  Â  Â  Â  g = Cos(( m+Val2 )*( PI/180 )) *127+127
  Â  Â  Â  b = Cos(( m+Val3 )*( PI/180 )) *127+127
  Â  Â  Â  
  Â  Â  Â  Pal( a ) = ( r Shl 16 ) Or ( g Shl 8 ) Or ( b Shl 0 ) 
  Â  
  Â  Next
End Sub
Sub InitializeASCII()
  Â  ScreenRes XRES,YRES,32,3,1 : Screenset 1, 0 : SetMouse  Â ,,0
  Â  WindowTitle "ASCII Plasma!"
  Â  Randomize Timer()
  Â  
  Â  ScreenNo = 1
  Â  
  Â  Dim i
  Â 
  Â  For i=0 To 4095
  Â  Â  Â  Sin1(i)=Sin(i/ 10)* 96+ 96
  Â  Â  Â  Sin2(i)=Sin(i/ 20)*112+112
  Â  Â  Â  Sin3(i)=Sin(i/ 70)*128+128
	Next 
  Â  
  Â  CreatePal( 10, 40, 120 )
  Â  
End Sub
Sub RunASCII()
  Â  
  Â  Dim Key As String
  Â  
  Â  While Key<>Chr(27)
  Â  Â  Â  
  Â  Â  Â  Cls
  Â  Â  Â  
  Â  Â  Â  Screencopy 2, ScreenNo
  Â  Â  Â  
  Â  Â  Â  Vel=Timer()*10
  Â  Â  Â  
  Â  Â  Â  UpdateASCIIPlasma()
  
  Â  Â  Â  Screensync
  Â  Â  Â  ScreenNo Xor = 1
		Screenset ScreenNo, ScreenNo xor 1
  Â  Â  Â  
  Â  Â  Â  Key=Inkey()
  Â  
  Â  Wend
  Â  
End Sub
Sub UpdateASCIIPlasma()
  Â  
  Â  Dim x, y, c
  Â  Dim Vel1, Vel2
  Â  Dim Char, RChar, BChar, GChar
  Â  Â  Â  
  Â  Vel1=  Vel 
  Â  Vel2=6*Vel
  Â  
  Â  If Vel1>503 then Vel1=Vel1-(Vel1\503)*503
  Â  If Vel2>880 then Vel2=Vel2-(Vel2\880)*880
  Â  
  Â  For y=1 To (YRES\8)-1
  Â  Â  Â  For x=1 To (XRES\8)-1
			
  Â  Â  Â  Â  Â  c=(sin1(x)+sin2(y+Vel1)+sin3(x+y+Vel2)) And 255
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Color Pal(c),0
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  RChar= ((Pal(c) shr 16) and &HFF )  
  Â  Â  Â  Â  Â  BChar= ((Pal(c) shr  8) And &HFF )
  Â  Â  Â  Â  Â  GChar= ((Pal(c) shr  0) and &HFF )
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Char = (RChar + BChar + GChar) \ 3
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  If Char<0  Â then Char=0
  Â  Â  Â  Â  Â  If Char>255 then Char=255
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Locate y,x : Print Chr(Char);
  Â  Â  Â  Â  Â  
  Â  Â  Â  Next 
	Next 
  Â  
End Sub
Cheers and all the best,
Clyde.
			 
			
			- 
				That's fucking great Clyde! I opened my IDE tonight to do exactly what you've done here and I just stared at it, I din't know where to start because I'm caught between two methods of doing it and I don't know which will be best, I guess that I'll have to experiment with both.
Your routine works nice and smooth , really It is nice, the colours are so good that I had to look twice to see the ascii chars making up the display!
Good job and have some good Karma for getting the ball rolling :)
			 
			
			- 
				Thanks so very much dude.
			
 
			
			- 
				Hmm must have not posted my earlier reply.
Anyway, nice effect clyde but I am not to keen on the letters cycling as well.
Change the line that print the character to 
Locate y,x : Print Chr(177);and it looks more like one of those textmode demo's :)
Full listing below.
'
' ASCII Render Engine V1.01
' Credits: Code By Clyde
' Plasma Inspired By Optimus
' Butchered By TinDragon :P
'
Option Static
Option Explicit
Const XRES=640
Const YRES=480
Const PI = 3.14151693
Dim Shared Vel
Dim Shared ScreenNo
Dim Shared Pal(255)
Dim Shared Sin1(4095),Sin2(4095),Sin3(4095)
Declare Sub CreatePal(  Byval Val1 As Integer, Byval Val2 As Integer, Byval Val3 As Integer )
Declare Sub InitializeASCII()
Declare Sub RunASCII()
Declare Sub UpdateASCIIPlasma()
InitializeASCII()
RunASCII()
Sub CreatePal(  Byval Val1 As Integer, Byval Val2 As Integer, Byval Val3 As Integer )
   
    '
    ' Local variables.
    '
    Dim As Integer a, m, r, g, b
 
    For a=0 To 255
       
        m = a*( 360/255 )
        r = Cos(( m+Val1 )*( PI/180 )) *127+127
        g = Cos(( m+Val2 )*( PI/180 )) *127+127
        b = Cos(( m+Val3 )*( PI/180 )) *127+127
       
        Pal( a ) = ( r Shl 16 ) Or ( g Shl 8 ) Or ( b Shl 0 )
   
    Next
End Sub
Sub InitializeASCII()
    ScreenRes XRES,YRES,32,3,1 : Screenset 1, 0 : SetMouse   ,,0
    WindowTitle "ASCII Plasma!"
    Randomize Timer()
   
    ScreenNo = 1
   
    Dim i
   
    For i=0 To 4095
        Sin1(i)=Sin(i/ 10)* 96+ 96
        Sin2(i)=Sin(i/ 20)*112+112
        Sin3(i)=Sin(i/ 70)*128+128
Next
   
    CreatePal( 10, 40, 120 )
   
End Sub
Sub RunASCII()
   
    Dim Key As String
   
    While Key<>Chr(27)
       
        Cls
       
        Screencopy 2, ScreenNo
       
        Vel=Timer()*10
       
        UpdateASCIIPlasma()
 
        Screensync
        ScreenNo Xor = 1
Screenset ScreenNo, ScreenNo xor 1
       
        Key=Inkey()
   
    Wend
   
End Sub
Sub UpdateASCIIPlasma()
   
    Dim x, y, c
    Dim Vel1, Vel2
    Dim Char, RChar, BChar, GChar
       
    Vel1=  Vel
    Vel2=6*Vel
   
    If Vel1>503 then Vel1=Vel1-(Vel1\503)*503
    If Vel2>880 then Vel2=Vel2-(Vel2\880)*880
   
    For y=1 To (YRES\8)-1
        For x=1 To (XRES\8)-1
            c=(sin1(x)+sin2(y+Vel1)+sin3(x+y+Vel2)) And 255
           
            Color Pal(c),0
           
            RChar= ((Pal(c) shr 16) and &HFF ) 
            BChar= ((Pal(c) shr  8) And &HFF )
            GChar= ((Pal(c) shr  0) and &HFF )
           
            'Char = (RChar + BChar + GChar) \ 3
           
            'If Char<0   then Char=0
            'If Char>255 then Char=255
           
            Locate y,x : Print Chr(177);
           
        Next
Next
   
End Sub
			 
			
			- 
				They look like two differnt effects, just the difference of one character but I love the style of Clydes version. Lots of Ascii demos have cycling characters and the best ones choose those characters carefully to achieve all sorts of stuff, even anti-aliasing of sorts.
The fuzzy block ascii character looks nice but I tend to favour the varied ascii character demos because the solid  chr$(177) ones fail to capture the true essence of the diverse ascii set and using the shapes contained in the characters to make a display.
I guess it's just a matter of personal preference.
			 
			
			- 
				Yep personal preferrance or taste is what makes us different. Dont get me wrong Clyde's effect is cool. Infact any char's used as just one for the effect makes a vary interesting take on it, not just the solid like block I picked. Shows just how easy it is to change an effects look with out much work.
Nice effect Clyde  :cheers: 
[Edit] I think one ascii value is used to make a beep Clyde, might be why your getting them, I had sound off when i tried code  :||
			 
			
			- 
				Thanks for the suggestion Tin Dragon.
I was aiming for capturing the essence of the TMDC demos that I've seen; where each character represents a shade of colour; as Shockie has pointed out. If there was a loadfont command similar to BB I could generate my own custom shadetext string, and have a better choice of symbols to match up with; like I have done in an early attempt at ascii rendering with Blitz; but Text printing in Blitz is extremely slow. For a first shot at it in FB, I dont think it turned out too badly. And I'm going to do a few more effects using this method hopefully over the weekend. As with it, anything is possible. I might even make a fully fledged multipart demo with it.
Hope it inspires and thanks for viewing,
Cheers and all the very best to all that enter,
Clyde.
			 
			
			- 
				
If there was a loadfont command similar to BB I could generate my own custom shadetext string, and have a better choice of symbols to match up with
You can still do that Clyde :) You don't need a loadfont command, just a more complicated renderer! Or you could do something in BB.
			 
			
			- 
				Main reason Im sticking with FB, is that I can't use bass v2 or above with Blitz.
And FB is much quicker at quite alot of thing. For the compo, I dont want to get too technical with it all. Sole reason, this stupid back of mine.
			 
			
			- 
				
Also, found that with certain calculations there's this annoying 'beep'. I presume it's linked to a certain Chr() number, but can't find the source of it
ASCII 7 or Chr(7) or Ctrl-G are all beep.  You probably need to avoid anything below 32 (space) to get consistent results, eg 8 is backspace, 9 is tab, 10 is line feed, etc. Check out the descriptions here http://www.lookuptables.com/.
Nice demos so far, Clyde, Relsoft, Tindragon, Shockwave - sadly I'm like Shockie, haven't an original idea in my head!
Jim
			 
			
			- 
				Nice one Clyde :) great effect m8
			
 
			
			- 
				Hehe, Well Jim, you are the master of fractals in my opinion, how about coding a textmode lorenz attractor or something?
			
 
			
			- 
				Thanks Jim And Cheers Tetra.
			
 
			
			- 
				Ok here's a little update with the info supplied by Jim which I didnt know about; also know full screen without a need for a border, as I was getting odd renderings before hand. Pretty much the same, but looks alot better this'll be my final entry of this effect.
'
' ASCII Render Engine V1.02
' Credits: Code By Clyde
' Plasma Inspired By Optimus
' Cheers Jim for the ASCII Chart.
Option Static
Option Explicit
Const XRES=640
Const YRES=480
Const PI = 3.14151693
Dim Shared Vel
Dim Shared ScreenNo
Dim Shared Pal(255)
Dim Shared Sin1(4095),Sin2(4095),Sin3(4095)
Declare Sub CreatePal(  Byval Val1 As Integer, Byval Val2 As Integer, Byval Val3 As Integer )
Declare Sub InitializeASCII()
Declare Sub RunASCII()
Declare Sub UpdateASCIIPlasma()
InitializeASCII()
RunASCII()
Sub CreatePal(  Byval Val1 As Integer, Byval Val2 As Integer, Byval Val3 As Integer )
   
    '
    ' Local variables.
    '
    Dim As Integer a, m, r, g, b
 
    For a=0 To 255
       
        m = a*( 360/255 )
        r = Cos(( m+Val1 )*( PI/180 )) *127+127
        g = Cos(( m+Val2 )*( PI/180 )) *127+127
        b = Cos(( m+Val3 )*( PI/180 )) *127+127
       
        Pal( a ) = ( r Shl 16 ) Or ( g Shl 8 ) Or ( b Shl 0 )
   
    Next
End Sub
Sub InitializeASCII()
    ScreenRes XRES,YRES,32,3,1 : Screenset 1, 0 : SetMouse   ,,0
    WindowTitle "ASCII Plasma!"
    Randomize Timer()
   
    ScreenNo = 1
   
    Dim i
   
    For i=0 To 4095
        Sin1(i)=Sin(i/ 10)* 96+ 96
        Sin2(i)=Sin(i/ 20)*112+112
        Sin3(i)=Sin(i/ 70)*128+128
    Next
   
    CreatePal( 90, 40, 10 )
   
End Sub
Sub RunASCII()
   
    Dim Key As String
   
    While Key<>Chr(27)
       
        Screencopy 2, ScreenNo
       
        Vel=Timer()*10
       
        UpdateASCIIPlasma()
 
        Screensync()
        
        ScreenNo Xor = 1
        Screenset ScreenNo, ScreenNo xor 1
       
        Key=Inkey()
        Cls
    Wend
   
End Sub
Sub UpdateASCIIPlasma()
   
    Dim x, y, c
    Dim Vel1, Vel2
    Dim Char, RChar, BChar, GChar
       
    Vel1=  Vel
    Vel2=6*Vel
   
    If Vel1>503 then Vel1=Vel1-(Vel1\503)*503
    If Vel2>880 then Vel2=Vel2-(Vel2\880)*880
   
    For y=0 To (YRES\8)
        For x=0 To (XRES\8)
            c=(sin1(x)+sin2(y+Vel1)+sin3(x+y+Vel2)) And 255
           
            Color Pal(c),0
           
            RChar= ((Pal(c) shr 16) and &HFF ) 
            BChar= ((Pal(c) shr  8) And &HFF )
            GChar= ((Pal(c) shr  0) and &HFF )
           
            Char = (RChar + BChar + GChar) \ 3
           
            If Char<33  then Char=33
            If Char>255 then Char=255
           
            Locate y,x : Print Chr(Char);
           
        Next
    Next
   
End Sub
			 
			
			- 
				Looks good Clyde, well done :)
			
 
			
			- 
				It's a pitty I haven't seen all these ASCII/ANSI examples yet because I don't have blitzbasic installed. Is BB free or you have to pay for that? Maybe there is a demo version of it that can run these examples?
			
 
			
			- 
				Blitz3D cost $100 and BlitzPlus cost $60
http://www.blitzbasic.com/Products/_index_.php
There is a demo version, 30 day trial version I think.
Download it from here (http://www.blitzbasic.com/file/get.php?file=/Products/demos/Blitz3DDemo183.exe)
Btw, nice plasma effect Clyde dude  :)
			 
			
			- 
				I'd only reccomend the Blitz demo Optimus, after using freebasic and devc everything else seems overpriced :P What I'll do is increase the upload limit here so that people can attach blitz exes.
So as from now you can upload 750kb in one go.
			 
			
			- 
				Cheers Shock\Rbraz maties :)
@Optimus: The code I submitted is Freebasic mate.
			 
			
			- 
				Oh sorry, how come didn't I noticed?
Ok, checked it now and looks cool. Well, I can enjoy it even more if I speed up that timer right there and use TinDragon's idea :)
Nice colors!
			 
			
			- 
				Thanks.