TV-Noise

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

EDIT: fixed some Errors
i found an older variation of tvnoise on my harddisk.
This one makes a TV-testing picture and has in MemoryBuild Sound .
Fee free to make you own tv-channel now ;)

Code: Select all

;TV-Test-picture

;#Swidht=640
;#SHeight=480
#SCREEN_X=800
#SCREEN_Y=600
#SCREEN_DEPTH=32
#MyFontID=1

Sender.s="PUREBASIC"

XSchritt=#SCREEN_X/20
YSchritt=#SCREEN_Y/15

Mode=1
DelayZeit=5000

;Make tv-noise, generate a sound in mem without a WAV-file

#pi = 3.141593                      ; pi 
fq = 250                           ; frequenz in Hz for sinustone 
#samplerate = 44100                 ; samplerate 
#bitrate = 16                       ; Bits per sample, #bitrate Mod 8 must be 0 ! 
#channels = 2                       ; number of channels 
#secs = 1                           ; time for the tone in seconds 
BytesNeeded=#samplerate * #secs * #channels *2
BytesNeeded=BytesNeeded + 44;(44 is the header)
mem1=GlobalAlloc_(#GMEM_FIXED,Bytesneeded) ;Api only ;)
mem2=GlobalAlloc_(#GMEM_FIXED,Bytesneeded)

avBytesPerSec.l = #channels*#bitrate/8*#samplerate  ; calculate the average bytes per second 
Global  actsamplevalue.w         ; for signed RAW data 
offset=44    
For acttime = 1 To #samplerate * #secs 
 For actchannel = 1 To #channels 
        If fq <= 150 
          m = 1 
        ElseIf fq >= 300 
          m = -1 
        EndIf 
        fq + m 
        actsamplevalue = 32766 * Sin(2 * #pi * fq * acttime / #samplerate) 
        If actsamplevalue <20000 
         actsamplevalue = actsamplevalue +5000
        EndIf 
        PokeW(mem2+offset,Random(32765))
        PokeW(mem1+offset,actsamplevalue )
        offset+2
    Next 
  Next 

  PokeL(mem1,$46464952) ;
  PokeL(mem1+4,36+avBytesPerSec*#secs) ;WriteLong(36+avBytesPerSec*#secs) ; normally filesize - 8 Bytes, here a bit tricky, fmt-chunk + data-chunk 
  PokeL(mem1+8,$45564157)
  PokeL(mem1+12,$20746D66)
  PokeL(mem1+16,16);WriteLong(16)                     ; chunk data size 
  PokeW(mem1+20,1);WriteWord(1)                      ; compression code 
  PokeW(mem1+22,#Channels);WriteWord(#channels)              ; number of channels 
  PokeL(mem1+24,#samplerate);WriteLong(#samplerate)            ; samplerate 
  PokeL(mem1+28,avBytesPerSec);WriteLong(avBytesPerSec)          ; average bytes per second, here 2(channels)*2(block align)*44100(samplerate) 
  PokeW(mem1+32,#bitrate/8*#channels);WriteWord(#bitrate/8*#channels)   ; Block Align ('bytes per sample') 
  PokeW(mem1+34,#bitrate);WriteWord(#bitrate)               ; Bits per sample 
  PokeS(Mem1+36,"data");WriteByte(Asc("d")) 
  PokeL(mem1+40,avBytesPerSec*#secs);;WriteLong(avBytesPerSec*#secs)    ; data chunk size in byes 

  PokeL(mem2,$46464952) ;
  PokeL(mem2+4,36+avBytesPerSec*#secs) ;WriteLong(36+avBytesPerSec*#secs) ; normally filesize - 8 Bytes, here a bit tricky, fmt-chunk + data-chunk 
  PokeL(mem2+8,$45564157)
  PokeL(mem2+12,$20746D66)
  PokeL(mem2+16,16);WriteLong(16)                     ; chunk data size 
  PokeW(mem2+20,1);WriteWord(1)                      ; compression code 
  PokeW(mem2+22,#Channels);WriteWord(#channels)              ; number of channels 
  PokeL(mem2+24,#samplerate);WriteLong(#samplerate)            ; samplerate 
  PokeL(mem2+28,avBytesPerSec);WriteLong(avBytesPerSec)          ; average bytes per second, here 2(channels)*2(block align)*44100(samplerate) 
  PokeW(mem2+32,#bitrate/8*#channels);WriteWord(#bitrate/8*#channels)   ; Block Align ('bytes per sample') 
  PokeW(mem2+34,#bitrate);WriteWord(#bitrate)               ; Bits per sample 
  PokeS(Mem2+36,"data");WriteByte(Asc("d")) 
  PokeL(mem2+40,avBytesPerSec*#secs);;WriteLong(avBytesPerSec*#secs)    ; data chunk size in byes 
 


; Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
     #SoundSync = $0
     #SoundASync = $1
     #SoundMemory = $4
     #SoundLoop = $8
     #SoundNoStop = $10
     #SoundNoDefault = $2

If InitSprite()=0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  End
EndIf

If OpenScreen(#SCREEN_X, #SCREEN_Y, #SCREEN_DEPTH, "TV-TEST")
 Flags=#PB_Font_Bold
 Result = LoadFont(#MyFontID, "Times New Roman", 32, Flags) 
 UseFont(#MyFontID) 

StartDrawing(ScreenOutput()) 
  Pitch        = DrawingBufferPitch() 
StopDrawing() 

White = $FFFFFF
Noise = 0 
Carry = 0 
Index = 0 
Seed  = $12345 

 Repeat
 FlipBuffers()
 If IsScreenActive() 
  ClearScreen($50,$50,$50)
  StartDrawing(ScreenOutput())
  T1=GetTickCount_()
  If T1>T0+DelayZeit
   If Mode=1 
    Mode=2
    result=sndPlaySound_(mem2,#SoundASync |#SoundMemory|#SoundLoop )
   Else
    Mode=1
    result=sndPlaySound_(mem1,#SoundASync |#SoundMemory|#SoundLoop )
   EndIf
   T0=T1  
  EndIf  
  If Mode=1 
  ;Draw grid
  DrawingMode(1)
  X=0
  Y=0
  While x<#SCREEN_X-1
   LineXY(X, 0, X, #SCREEN_Y-1 , $FFFFFF) 
   X+XSchritt
   While y< #SCREEN_Y-1
    LineXY(0, y, #SCREEN_X-1, y , $FFFFFF) 
    y+YSchritt
   Wend
  Wend
  LineXY(#SCREEN_X-1, 0, #SCREEN_X-1, #SCREEN_Y-1 , $FFFFFF) 
  LineXY(0, #SCREEN_Y-1, #SCREEN_X-1, #SCREEN_Y-1 , $FFFFFF) 


  ;draw boxes
  Box(XSchritt*4,YSchritt*2,xSchritt*1.5,YSchritt*3,$FFFFFF) ;white
  Box(XSchritt*5.5,YSchritt*2,xSchritt*1.5,YSchritt*3,$00FFFF);yellow
  Box(XSchritt*7,YSchritt*2,xSchritt*1.5,YSchritt*3,$AAAA00);ligh bluegreen
  Box(XSchritt*8.5,YSchritt*2,xSchritt*1.5,YSchritt*3,$00AA44);green
  Box(XSchritt*10,YSchritt*2,xSchritt*1.5,YSchritt*3,$FF00FF);purple
  Box(XSchritt*11.5,YSchritt*2,xSchritt*1.5,YSchritt*3,$0000FF);red
  Box(XSchritt*13,YSchritt*2,xSchritt*1.5,YSchritt*3,$FF0000);blue
  Box(XSchritt*14.5,YSchritt*2,xSchritt*1.5,YSchritt*3,$000000);black
  
  Box(XSchritt*4,YSchritt*5,xSchritt*3,YSchritt*2,$000000);black
  Box(XSchritt*7,YSchritt*5,xSchritt*3,YSchritt*2,$505050);darkgrey
  Box(XSchritt*10,YSchritt*5,xSchritt*3,YSchritt*2,$A0A0A0);lighgrey
  Box(XSchritt*13,YSchritt*5,xSchritt*3,YSchritt*2,$FFFFFF);white

  Box(XSchritt*4,YSchritt*7,xSchritt*12,YSchritt*3,$FFFFFF);white
  Box(XSchritt*6,YSchritt*7+1,xSchritt*8,YSchritt-1,$000000);black
  Box(XSchritt*5.5,YSchritt*8,xSchritt*10.5,YSchritt,$505050);darkgrey

  For I=1 To 5
   Box(XSchritt*6 + (I* XSchritt/3),YSchritt*8,xSchritt/6,YSchritt,$FFFFFF);white
   Box(XSchritt*6 + XSchritt/6 + (I*XSchritt/3),YSchritt*8,xSchritt/6,YSchritt,$000000);white
   ;Box(XSchritt*4.25+ I*(XSchritt/4),YSchritt*8,xSchritt/4,YSchritt,$000000);black
  Next I

  For I=1 To 10
   Box(XSchritt*8 + (I* XSchritt/6),YSchritt*8,xSchritt/12,YSchritt,$FFFFFF);white
   Box(XSchritt*8 + XSchritt/12 + (I*XSchritt/6),YSchritt*8,xSchritt/12,YSchritt,$000000);white
   ;Box(XSchritt*4.25+ I*(XSchritt/4),YSchritt*8,xSchritt/4,YSchritt,$000000);black
  Next I

  mschritt=2
  For I=1 To 20
   Box(XSchritt*10.5 + (I* Mschritt*2),YSchritt*8,mSchritt,YSchritt,$FFFFFF);white
   Box(XSchritt*10.5 + 2 + (I*mSchritt*2),YSchritt*8,mschritt,YSchritt,$000000);white
   ;Box(XSchritt*4.25+ I*(XSchritt/4),YSchritt*8,xSchritt/4,YSchritt,$000000);black
  Next I
  
  
  Box(XSchritt*13,YSchritt*8,xSchritt*2.5,YSchritt,RGB(174,84,0));brown
  
  FrontColor($FF,$FF,$FF)
  DrawingFont(FontID()) 
  Locate((#SCREEN_X - TextLength(sender) )/2,YSchritt*7-2)
  DrawText(Sender)
  
  LineXY(#SCREEN_X/2, YSchritt*6,#SCREEN_X/2, YSchritt*9 , $FFFFFF) 
  LineXY(#SCREEN_X/2+xSchritt/4, YSchritt*9,#SCREEN_X/2+xSchritt/4, YSchritt*10, $000000) 
  LineXY(xSchritt*9.75, YSchritt*9,#SCREEN_X/2+xSchritt/4, YSchritt*9, $000000) 
  LineXY(xSchritt*9.75, YSchritt*9,#SCREEN_X/2+xSchritt/4, YSchritt*10, $000000) 
  FillArea(#SCREEN_X/2, YSchritt*9.1, 0, 0) 


  Box(XSchritt*4,YSchritt*10,xSchritt*8,YSchritt,$3333FF);red
  Box(XSchritt*4,YSchritt*11,xSchritt*8,YSchritt,$FF3333);blue
  Box(XSchritt*12,YSchritt*10,xSchritt*4,YSchritt*2,$505050);darkgrey

  ;Draw circle
  DrawingMode(4)
  Ellipse(#SCREEN_X/2, #SCREEN_Y/2, #SCREEN_Y/2 -1,#SCREEN_Y/2 -1 , $FFFFFF) 
  EndIf
  If Mode=2
   For y = 0 To #SCREEN_Y -1
    For x = 0 To #SCREEN_X -1
          noise = seed; 
          noise = noise >> 3 
          noise = noise ! seed 
          carry = noise & 1 
          seed = seed >> 1 
          seed = seed | ( carry << 30) 
          noise = noise & $FF 
           
          *Screen.LONG = DrawingBuffer()
          *Screen + (Pitch * y) +  (x*4)  
          ;*Screen\l =Random(1) * $FFFFFF
          *Screen\l = (noise<<16) | (noise << 8) | noise 
    Next x 
   Next y 
  EndIf
  StopDrawing()
 EndIf
 Delay(1)
 ExamineKeyboard()
 Until KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error", "Can't open a 640*480 - 16 bit screen !", 0)
EndIf
GlobalFree_(mem1)
GlobalFree_(mem2)
End
Last edited by Rings on Wed Feb 23, 2005 9:28 am, edited 1 time in total.
SPAMINATOR NR.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

sweet! love it.. time to mess with some ppl at work.. ;)

- np

*edit*

Is there a way to make it use less resources.. without losing performance?
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Really very nice :D
Putting a delay(1) just before the FlipBuffers() should give some relief to the CPU...
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

Hahahaha, that is just so simple, but so cool :) Nice one.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

My TVnoise :)
Source (needs EspriteEX lib):

Code: Select all

bitplanes.b=32
SCREENWIDTH.l=GetSystemMetrics_(#SM_CXSCREEN):SCREENHEIGHT.l=GetSystemMetrics_(#SM_CYSCREEN)
If InitSprite()=0 Or InitKeyboard()=0
  MessageRequester("Error","Can't access DirectX",0):End
EndIf
While OpenScreen(SCREENWIDTH,SCREENHEIGHT,bitplanes.b,"")=0
  If bitplanes.b>16:bitplanes.b-8
  ElseIf SCREENHEIGHT>600:SCREENWIDTH=800:SCREENHEIGHT=600:bitplanes.b=32
  ElseIf SCREENHEIGHT>480:SCREENWIDTH=640:SCREENHEIGHT=480:bitplanes.b=24
  ElseIf SCREENHEIGHT>400:SCREENWIDTH=640:SCREENHEIGHT=400:bitplanes.b=24
  ElseIf SCREENHEIGHT>240:SCREENWIDTH=320:SCREENHEIGHT=240:bitplanes.b=16
  ElseIf SCREENHEIGHT>200:SCREENWIDTH=320:SCREENHEIGHT=200:bitplanes.b=16
  Else:MessageRequester("Listen:","Can't open Screen!",0):End
  EndIf
Wend

squars.l=100:bn.l=$010101:dly.b=Int(1000/GetMonitorFreq())
For g=0 To squars.l
  CreateSprite(g,64,64)
  StartDrawing(SpriteOutput(g)):BackColor(0,0,0)
  For t=1 To 10000
    Plot(Random(64),Random(64),(Random(256))*bn)
  Next
  StopDrawing()
Next
;-MAIN:
Repeat
  ExamineKeyboard()
  For t=0 To 192 Step 64
    For g=0 To 192 Step 64
      DisplaySprite(Random(squars.l),t,g)
    Next
  Next
  CopyBufferEx(256,256):Delay(dly.b)
Until KeyboardPushed(#PB_Key_Escape)
Almost 0 CPU time consumption.
Always can be done still more randomized, but this one is not bad, overall with modern VGAs.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Code: Select all

While OpenScreen(SCREENWIDTH,SCREENHEIGHT,bitplanes.b,"")=0 
  If bitplanes.b>16:bitplanes.b-8 
  ElseIf SCREENHEIGHT>600:SCREENWIDTH=800:SCREENHEIGHT=600:bitplanes.b=32 
  ElseIf SCREENHEIGHT>480:SCREENWIDTH=640:SCREENHEIGHT=480:bitplanes.b=24 
  ElseIf SCREENHEIGHT>400:SCREENWIDTH=640:SCREENHEIGHT=400:bitplanes.b=24 
  ElseIf SCREENHEIGHT>240:SCREENWIDTH=320:SCREENHEIGHT=240:bitplanes.b=16 
  ElseIf SCREENHEIGHT>200:SCREENWIDTH=320:SCREENHEIGHT=200:bitplanes.b=16 
  Else:MessageRequester("Listen:","Can't open Screen!",0):End 
  EndIf 
Wend 
Very nice piece of code...

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

I had to change this line

Code: Select all

    Plot(Random(64),Random(64),(Random(256))*bn)
to this line:

Code: Select all

    Plot(Random(63),Random(63),(Random(256))*bn)
Looks nice for such low cpu usage ...
regards,
benny!
-
pe0ple ar3 str4nge!!!
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Here is my version (I pinched the init code from Psychophanta, again very nice code) :)

Code: Select all

bitplanes.b=32 
SCREENWIDTH.l=GetSystemMetrics_(#SM_CXSCREEN)
SCREENHEIGHT.l=GetSystemMetrics_(#SM_CYSCREEN) 
If InitSprite()=0 Or InitKeyboard()=0 
  MessageRequester("Error","Can't access DirectX")
  End 
EndIf 
If InitSprite3D()=0
  MessageRequester("Error","Can't access Sprite3D")
  End 
EndIf 
While OpenScreen(SCREENWIDTH,SCREENHEIGHT,bitplanes.b,"")=0 
  If bitplanes.b>16
  	bitplanes.b-8 
  ElseIf SCREENHEIGHT>600
  	SCREENWIDTH=800	
	 	SCREENHEIGHT=600
	 	bitplanes.b=32 
  ElseIf SCREENHEIGHT>480
  	SCREENWIDTH=640
	  SCREENHEIGHT=480
  	bitplanes.b=24 
  ElseIf SCREENHEIGHT>400
  	SCREENWIDTH=640
	  SCREENHEIGHT=400
  	bitplanes.b=24 
  ElseIf SCREENHEIGHT>240
  	SCREENWIDTH=320
	  SCREENHEIGHT=240
  	bitplanes.b=16 
  ElseIf SCREENHEIGHT>200
  	SCREENWIDTH=320
	  SCREENHEIGHT=200
  	bitplanes.b=16 
  Else
  	MessageRequester("Listen:","Can't open Screen!")
  	End 
  EndIf 
Wend 

SetFrameRate(60)
bn.l=$010101
dly.b=Int(1000/GetMonitorFreq()) 

If CreateSprite(0,256,256,#PB_Sprite_Texture)=0
  MessageRequester("Error","Can't create Sprite")
  End 
EndIf
TransparentSpriteColor(0,255,0,255) 
If CreateSprite3D(0,0)=0
	MessageRequester("Error","Can't create sprite3d")
	End	
EndIf

w=(SCREENWIDTH/256)-1
h=(SCREENHEIGHT/256)-1
l=0

Repeat 
  ExamineKeyboard() 
  If StartDrawing(SpriteOutput(0))
		For y=0 To 255
  		For x=0 To 255
	 			Plot(x,y,(Random(256))*$010101)
  		Next
		Next
  	StopDrawing()
	EndIf

	If Start3D()
		y=0
		For ly=0 To h
			x=0
			For lx=0 To w
	  		DisplaySprite3D(0,x,y,255)
		  	x+256
  		Next
		  y+256
  	Next
	  Stop3D()
	EndIf
  FlipBuffers()
  Delay(dly)
Until KeyboardPushed(#PB_Key_Escape)
Still has the low cpu usage and has finer pixels...

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Oops, here is is again - but without using Sprite3D! I had previously used the zoom features...

Code: Select all

bitplanes.b=32 
SCREENWIDTH.l=GetSystemMetrics_(#SM_CXSCREEN)
SCREENHEIGHT.l=GetSystemMetrics_(#SM_CYSCREEN) 
If InitSprite()=0 Or InitKeyboard()=0 
  MessageRequester("Error","Can't access DirectX")
  End 
EndIf 
 
While OpenScreen(SCREENWIDTH,SCREENHEIGHT,bitplanes.b,"")=0 
  If bitplanes.b>16
  	bitplanes.b-8 
  ElseIf SCREENHEIGHT>600
  	SCREENWIDTH=800	
	 	SCREENHEIGHT=600
	 	bitplanes.b=32 
  ElseIf SCREENHEIGHT>480
  	SCREENWIDTH=640
	  SCREENHEIGHT=480
  	bitplanes.b=24 
  ElseIf SCREENHEIGHT>400
  	SCREENWIDTH=640
	  SCREENHEIGHT=400
  	bitplanes.b=24 
  ElseIf SCREENHEIGHT>240
  	SCREENWIDTH=320
	  SCREENHEIGHT=240
  	bitplanes.b=16 
  ElseIf SCREENHEIGHT>200
  	SCREENWIDTH=320
	  SCREENHEIGHT=200
  	bitplanes.b=16 
  Else
  	MessageRequester("Listen:","Can't open Screen!")
  	End 
  EndIf 
Wend 

SetFrameRate(60)
bn.l=$010101
dly.b=Int(1000/GetMonitorFreq()) 

If CreateSprite(0,256,256)=0
  MessageRequester("Error","Can't create Sprite")
  End 
EndIf 

w=(SCREENWIDTH/256)-1
h=(SCREENHEIGHT/256)-1
l=0

Repeat 
  ExamineKeyboard() 
  If StartDrawing(SpriteOutput(0))
		For y=0 To 255
  		For x=0 To 255
	 			Plot(x,y,(Random(256))*$010101)
  		Next
		Next
  	StopDrawing()
	EndIf

	y=0
	For ly=0 To h
		x=0
		For lx=0 To w
  		DisplaySprite(0,x,y)
	  	x+256
 		Next
	  y+256
 	Next

  FlipBuffers()
  Delay(dly)
Until KeyboardPushed(#PB_Key_Escape)
-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

benny wrote:I had to change this line

Code: Select all

    Plot(Random(64),Random(64),(Random(256))*bn)
to this line:

Code: Select all

    Plot(Random(63),Random(63),(Random(256))*bn)
Looks nice for such low cpu usage ...
Ohh, that's right. I believed Random() returned value from 0 to parameter-1 :o So then should be:

Code: Select all

    Plot(Random(63),Random(63),(Random(255))*bn)
:wink:

DoubleDutch, nice your versions.
However, I did it with antialiased points (it works only for modern VGAs) because it seems more realistic. :idea:
Keep in mind TV sets have not the high resolution the computers' monitors have :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

Here's a small Broken TV example (which works well as a screen saver):

Code: Select all

; broken TV

; Converted from Jeppe Nielsons Blitz 'Broken TV' code

sw.l=GetSystemMetrics_(#SM_CXSCREEN)
sh.l=GetSystemMetrics_(#SM_CYSCREEN)

#cell=72

dSW=sw/4 : dSH=sh/4
bw.f=dSW/#cell : bh.f=dSH/#cell


; setup display
ShowCursor_(0)
OpenWindow(0, 0, 0, sw, sh,  #PB_Window_BorderLess, "")

; main loop
Repeat
 DC=StartDrawing(WindowOutput())
 For y=0 To #cell-1
  For x=0 To #cell-1
   c=30+Random(210)
   FrontColor(c,c,c)
   Box(x*bw,y*bh,bw,bh)
  Next
 Next
  
 BitBlt_(DC , dSW,0 , dSW,dSH , DC , 0,0,#SRCCOPY)
 BitBlt_(DC , 0,dSH , dSW*2,dSH , DC , 0,0,#SRCCOPY)
 BitBlt_(DC , 0,dSH*2 , dSW*2,dSH*2 , DC , 0,0,#SRCCOPY)
 BitBlt_(DC , dSW*2,0 , dSW*2,dSH*4 , DC , 0,0,#SRCCOPY)
 
 StopDrawing()
 Delay(5)
Until GetAsyncKeyState_(#VK_ESCAPE)=-32767

; cleanup
CloseWindow(0)
ShowCursor_(1)
End
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

syntax error wrote:Here's a small Broken TV example (which works well as a screen saver):
...
Uffh! too slow, and too much CPU time wasted.

EDIT:
Updated to PB4.0, and no needed external user libs:

Code: Select all

bitplanes.b=32
Global SCREENWIDTH.l,SCREENHEIGHT.l
If ExamineDesktops()=0:SCREENWIDTH=DesktopWidth(0):SCREENHEIGHT=DesktopHeight(0)
Else:SCREENWIDTH=GetSystemMetrics_(#SM_CXSCREEN):SCREENHEIGHT=GetSystemMetrics_(#SM_CYSCREEN)
EndIf
If InitMouse()=0 Or InitSprite()=0 Or InitSprite3D()=0 Or InitKeyboard()=0
  MessageRequester("Error","Can't access DirectX",0):End
EndIf
While OpenScreen(SCREENWIDTH,SCREENHEIGHT,bitplanes.b,"")=0
  If bitplanes.b>16:bitplanes.b-8
  ElseIf SCREENHEIGHT>600:SCREENWIDTH=800:SCREENHEIGHT=600
  ElseIf SCREENHEIGHT>480:SCREENWIDTH=640:SCREENHEIGHT=480
  ElseIf SCREENHEIGHT>400:SCREENWIDTH=640:SCREENHEIGHT=400
  ElseIf SCREENHEIGHT>240:SCREENWIDTH=320:SCREENHEIGHT=240
  ElseIf SCREENHEIGHT>200:SCREENWIDTH=320:SCREENHEIGHT=200
  Else:MessageRequester("Listen:","Can't open Screen!",0):End
  EndIf
Wend
;Refer some values:
!extrn _PB_DDrawBase
!extrn _PB_DirectX_PrimaryBuffer
!extrn _PB_DirectX_BackBuffer
!extrn _PB_Sprite_FXBuffer
!extrn _PB_FlipBuffers@0
!DDBLT_WAIT equ $1000000
;The stretch will be from (w,h) to (SCREENWIDTH,SCREENHEIGHT):
w.l=256:h.l=256
!mov eax,dword[v_w]
!mov dword[SrcRight],eax
!mov eax,dword[v_h]
!mov dword[SrcBottom],eax
!mov eax,dword[v_SCREENWIDTH]
!mov dword[DestRight],eax
!mov eax,dword[v_SCREENHEIGHT]
!mov dword[DestBottom],eax
Procedure PrimaryBufferInit()
  !mov eax,dword[_PB_DirectX_PrimaryBuffer]
  !test eax,eax
  !jz @f
  !mov dword[PrimaryBuffer],eax
  ProcedureReturn
  !@@:
  !;PrimaryBufferInit:
  !push DDrawBase
  !mov eax,dword[_PB_DirectX_BackBuffer]
  !push eax
  !mov eax,dword[eax]
  !call dword[eax+144]
  !push PrimaryBuffer
  !mov eax,dword[DDrawBase]
  !push eax
  !mov eax,dword[eax]
  !call dword[eax+56]
  !mov eax,dword[PrimaryBuffer]
  !;EndPrimaryBufferInit
EndProcedure
Macro MyRestoreScreen;Copy the BackBuffer into the SpecialFX-Buffer
  !push $10      ;#DDBLTFAST_NOCOLORKEY|#DDBLTFAST_WAIT
  !push 0 dword[_PB_DirectX_BackBuffer] 0 0
  !mov eax,dword[_PB_Sprite_FXBuffer]
  !push eax
  !mov eax,dword[eax]
  !call dword[eax+28]
EndMacro
Macro MyCopyBuffer;Copy the BackBuffer into the FrontBuffer.
  !push $10      ;#DDBLTFAST_NOCOLORKEY|#DDBLTFAST_WAIT
  !push 0 dword[_PB_DirectX_BackBuffer] 0 0
  !mov eax,dword[PrimaryBuffer]
  !push eax
  !mov eax,dword[eax]
  !call dword[eax+28]
EndMacro
Macro MyCopyBufferEx;Copy the BackBuffer into the FrontBuffer stretching
  !mov eax,dword[_PB_DirectX_PrimaryBuffer]
  !push dword dwSize dword DDBLT_WAIT dword SrcLeft dword[_PB_DirectX_BackBuffer] dword DestLeft eax
  !mov eax,dword[eax]
  !call dword[eax+20]
EndMacro
Macro MySwapBuffers;Swap the BackBuffer with the FrontBuffer.
  !mov edx,dword[PrimaryBuffer]
  !mov eax,dword[edx]
  !mov eax,dword[eax+44]
  !push dword 9 dword 0 edx
  !call eax
EndMacro
Macro MyDisplayDirect;All drawing commands draw direct to screen.
  !mov eax,dword[_PB_DirectX_BackBuffer] 
  !mov dword[BackBuffer],eax 
  !mov eax,dword[_PB_DirectX_PrimaryBuffer] 
  !mov dword[_PB_DirectX_BackBuffer],eax
  !call _PB_FlipBuffers@0
EndMacro
Macro MyStopDisplayDirect;Stop all drawing commands to be drawed directly to screen.
  !mov eax,dword[BackBuffer] 
  !mov dword[_PB_DirectX_BackBuffer],eax
  !call _PB_FlipBuffers@0
EndMacro
DataSection
!DDrawBase:dd 0
!PrimaryBuffer:dd 0
!BackBuffer:dd 0
!SrcLeft:dd 0
!SrcTop:dd 0
!SrcRight:dd 0
!SrcBottom:dd 0
!DestLeft:dd 0
!DestTop:dd 0
!DestRight:dd 0
!DestBottom:dd 0
!dwSize:dd 100
EndDataSection
PrimaryBufferInit()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rects.l=2000:bn.l=$010101:spw.l=256:sph.l=16
For g.l=0 To rects.l
  CreateSprite(g.l,spw.l,sph.l)
  StartDrawing(SpriteOutput(g.l)):BackColor(0)
  For y.l=0 To sph.l-1
    For x.l=0 To spw.l-1
      Plot(x.l,y.l,(Random(255))*bn.l)
    Next
  Next
  StopDrawing()
Next
;-MAIN:
Repeat
  ExamineKeyboard():y.l=0
  While y.l<=h.l-sph.l
    DisplaySprite(Random(rects.l),0,y.l)
    y.l+sph.l
  Wend
  MyCopyBufferEx
  Delay(16);:While KeyboardPushed(#PB_Key_Space):ExamineKeyboard():Delay(20):Wend
Until KeyboardPushed(#PB_Key_Escape)
ClearScreen(0):FlipBuffers(0):ClearScreen(0):CloseScreen()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply