Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: WidowMaker [retired] on August 05, 2007
-
Been looking at lots of ascii demos recently during my period of dissilusionment. I have Been properly impressed with a lot of them, mind you the ones I liked the best seemed to not have dedicated ascii engines, these seem to take a small screen buffer and then later convert it into a visual display.
What I think is the appeal of these demo is that the refresh rates in the text modes has tears and glitches and gives them a nice look all of their own.
I want to make something like that with a cleaner look, I used ptc _ext by Rbraz so here is a basic routine that lets you change the resolution of the grid and the screen with no hassle.
For now it just draws random coloured blocks but the buffer could be made to display anything.
I plan you use it to draw some vector bobs and a plasma but it is here for you to use too if anybody feels like using it for anything.
Ok here is source code;
'
' PSEUDO ASCII CRACKTRO
' =====================
'
'
'
' WIDOW MAKER 2007
'
'
'-------------------------------------------------------------------------------
OPTION STATIC
OPTION EXPLICIT
' SCREEN RES
CONST XRES = 800
CONST YRES = 600
' GRID RES
CONST GRID = 8
DIM SHARED AS INTEGER WXRES
DIM SHARED AS INTEGER WYRES
WXRES = XRES / GRID
WYRES = YRES / GRID
' INCLUDES
#INCLUDE "TINYPTC_EXT.BI"
#INCLUDE "WINDOWS.BI"
'-------------------------------------------------------------------------------
' VARIABLES
DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )
DIM SHARED AS UINTEGER WBUFFER ( WXRES * WYRES )
'-------------------------------------------------------------------------------
' SUBS
DECLARE SUB BLIT_BUFFER()
DECLARE SUB ERASE_GRID()
'-------------------------------------------------------------------------------
' OPEN SCREEN
PTC_ALLOWCLOSE(0)
PTC_SETDIALOG(0,"",0,0)
IF (PTC_OPEN("P0STM0RT3M",XRES,YRES)=0) THEN
END-1
END IF
'-------------------------------------------------------------------------------
' MAIN LOOP;
'-------------------------------------------------------------------------------
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<>-32767)
ERASE_GRID()
BLIT_BUFFER()
PTC_UPDATE@BUFFER(0)
WEND
END
'-------------------------------------------------------------------------------
' DRAWS THE SCREEN ACCORDING TO WHAT IS IN WBUFFER.
'-------------------------------------------------------------------------------
SUB BLIT_BUFFER()
DIM AS INTEGER XX,YY,Y2,SLICE,tc
DIM PP AS UINTEGER PTR
FOR YY=0 TO WYRES-1
FOR XX=0 TO WXRES-1
FOR Y2=0 TO GRID-1
pp=@buffer((XX*GRID)+(((YY*GRID)+Y2)*XRES))
SLICE = GRID
TC=WBUFFER(XX+(YY*WXRES))
asm
mov eax,dword ptr[TC]
mov ecx, [SLICE]
mov edi, [PP]
rep stosd
end asm
NEXT
NEXT
NEXT
END SUB
'-------------------------------------------------------------------------------
' FOR NOW JUST GENERATE RANDOM PIXELS, LATER IT WILL BE JUST DRAWN OVER.
'-------------------------------------------------------------------------------
SUB ERASE_GRID()
DIM AS INTEGER XX,YY
FOR YY=0 TO WYRES-1
FOR XX=0 TO WXRES-1
WBUFFER(XX+(YY*WXRES))=RGB(INT(RND(1)*255),INT(RND(1)*255),INT(RND(1)*255))
NEXT
NEXT
END SUB
Haven't bothered with an exe as it is just a screen full of flashing coloured squares :P
-
Widow Maker . . .
Nice work there . . . if i change grid to anything but 8 on my system why does it crash (big time!) ? I know you will be working on the buffer to generate more than just blocks but I found it fascinating anyway!!! Surely it should be able to generate any size grid? Not a criticism btw - just interested?
Drew
-
Weird how it crashes for you DrewPee :\ Probably I have fucked up somewhere and written > than the screen buffer at some resolutions. Sorry about that.
Here is a plasma using that code;
'
' PSEUDO ASCII CRACKTRO
' =====================
'
'
'
' WIDOW MAKER 2007
'
'
'-------------------------------------------------------------------------------
OPTION STATIC
OPTION EXPLICIT
' SCREEN RES
CONST XRES = 640
CONST YRES = 480
' GRID RES
CONST GRID = 4
DIM SHARED AS INTEGER WXRES
DIM SHARED AS INTEGER WYRES
WXRES = XRES / GRID
WYRES = YRES / GRID
' INCLUDES
#INCLUDE "TINYPTC_EXT.BI"
#INCLUDE "WINDOWS.BI"
'-------------------------------------------------------------------------------
' VARIABLES
DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )
DIM SHARED AS UINTEGER WBUFFER ( WXRES * WYRES )
dim shared as double fuckfuck(xres)
DIM SHARED AS UINTEGER COL_PAL(10000)
DIM SHARED AS DOUBLE GADD,GADD2
'-------------------------------------------------------------------------------
' SUBS
DECLARE SUB BLIT_BUFFER()
DECLARE SUB ERASE_GRID()
DECLARE SUB PRECALC()
DECLARE SUB PLASMA()
'-------------------------------------------------------------------------------
' OPEN SCREEN
PTC_ALLOWCLOSE(0)
PTC_SETDIALOG(0,"",0,0)
IF (PTC_OPEN("P0STM0RT3M",XRES,YRES)=0) THEN
END-1
END IF
PRECALC()
'-------------------------------------------------------------------------------
' MAIN LOOP;
'-------------------------------------------------------------------------------
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<>-32767)
GADD=GADD-1.5
GADD2=GADD2-1.4
' ERASE_GRID()
PLASMA()
BLIT_BUFFER()
PTC_UPDATE@BUFFER(0)
WEND
END
SUB PLASMA()
DIM AS INTEGER YY,XX,VALL,QQ,RR
dim as double ll,mm
for xx=0 to xres
fuckfuck(xx)=171+50*sin((GADD+xx)/39)
next
FOR YY=0 TO WYRES-1
QQ = 599 * SIN (( GADD2 + YY) /69)
rr = 599 * SIN (( GADD - YY) /87)
mm=171+50*sin((GADD+yy)/237)
FOR XX=0 TO WXRES-1
VALL = 5000+(2499*cos((gadd2-YY+QQ)/fuckfuck(xx))+2499*SIN((gadd-YY+rr)/mm))
WBUFFER(XX+(YY*WXRES))=COL_PAL(VALL)
NEXT
NEXT
END SUB
SUB PRECALC()
DIM X AS INTEGER
DIM AS DOUBLE RR,GG,BB
RR=125
GG=125
BB=125
FOR X=0 TO 10000
rr=125+124*sin(X/1813)
gg=125+124*sin((X+1000)/1813)
bb=125+124*sin((X+2000)/1813)
COL_PAL(X) = RGB( INT(RR),INT(GG),INT(BB) )
NEXT
END SUB
'-------------------------------------------------------------------------------
' DRAWS THE SCREEN ACCORDING TO WHAT IS IN WBUFFER.
'-------------------------------------------------------------------------------
SUB BLIT_BUFFER()
DIM AS INTEGER XX,YY,Y2,SLICE,tc
DIM PP AS UINTEGER PTR
FOR YY=0 TO WYRES-1
FOR XX=0 TO WXRES-1
FOR Y2=0 TO GRID-1
pp=@buffer((XX*GRID)+(((YY*GRID)+Y2)*XRES))
SLICE = GRID
TC=WBUFFER(XX+(YY*WXRES))
asm
mov eax,dword ptr[TC]
mov ecx, [SLICE]
mov edi, [PP]
rep stosd
end asm
NEXT
NEXT
NEXT
END SUB
'-------------------------------------------------------------------------------
' FOR NOW JUST GENERATE RANDOM PIXELS, LATER IT WILL BE JUST DRAWN OVER.
'-------------------------------------------------------------------------------
SUB ERASE_GRID()
DIM AS INTEGER XX,YY
FOR YY=0 TO WYRES-1
FOR XX=0 TO WXRES-1
WBUFFER(XX+(YY*WXRES))=RGB(INT(RND(1)*255),INT(RND(1)*255),INT(RND(1)*255))
NEXT
NEXT
END SUB
Exe attached.... :P
-
Widow Maker,
You were right . . . i changed the For yy=0 to WYRES-1 to For yy=0 to WYRES-8 and did the same with the xx variable - then changed the grid value to 16 and it worked fine - it was trying to draw the 'blocks' outside the screen array.
The Plasma effect is wicked - smooth as anything - again if you change the grid value you get some fantastic results . . . try changing it to 32 . . . looks fantastic.
Thanks for sharing the code Widow Maker, appreciate it very much!
Drew
-
...
Haven't bothered with an exe as it is just a screen full of flashing coloured squares :P
:(
-
He added an exe of the effect in one of the posts above with a Plasma effect Benny :)
-
Ja. But not with the ASCII looking fx :-(
-
It's just a load of squares mate.
-
@Shocky:
Ok. I was just curious you know :whisper:
-
I'll make an exe later when I go to my other computer :)