Page 1 of 1
Matrix code!
Posted: Sun Aug 07, 2005 5:33 am
by Fou-Lu
Code updated For 5.20+
No, its not the code to generate Matrix in PB.
It's a nice effect though it's simple, Just copy and paste the code. Any suggestion to make it better?
Code: Select all
;~~~~~~~~~~~~~~~~~~~~~~~
;~Fou-lu's great Matrix effect~
;~~~~~~~~~~~~~~~~~~~~~~~
;August 6th, 2005
If InitSprite() And InitMouse():Else
MessageRequester("Error","Sorry, it won't work in your pc!"):End:EndIf
OpenScreen(640,480,32,"")
For n=0 To 15
For m=0 To 9
CreateSprite(m+n*10,7,13)
StartDrawing(SpriteOutput(m+n*10))
green=(n*20)
If green>255:redblue=4*(green-255):green=255:EndIf
FrontColor(RGB(redblue,green,redblue))
DrawingMode(1)
; DrawText(Str(m))
StopDrawing()
Next m
Next n
Structure MatrixNumbers
x.b
y.b
life.w
speed.b
number.b
EndStructure
Global NewList digit.MatrixNumbers()
Global Dim fill(63,29)
Procedure AddDigit(x,y)
If y>29:y=y-30:EndIf
If fill(x,y)=0
AddElement(digit())
digit()\number=Random(9)
digit()\x=x
digit()\y=y
digit()\life=255
digit()\speed=Random(15)+1
fill(x,y)=1
EndIf
EndProcedure
Repeat
dx=Random(63)
dy=Random(29)
ClearScreen(RGB(0,0,0))
ForEach digit()
If digit()\life=255-digit()\speed And Random(digit()\speed*2)>0
oldspeed=digit()\speed
index=ListIndex(digit()):AddDigit(digit()\x,digit()\y+1)
digit()\speed=oldspeed
SelectElement(digit(),index)
EndIf
DisplaySprite((digit()\life/16)*10+digit()\number,digit()\x*10,digit()\y*16)
digit()\life=digit()\life-digit()\speed
If Random(digit()\life/8)=0:digit()\number=Random(9):EndIf
If digit()\life<=0:fill(digit()\x,digit()\y)=0:DeleteElement(digit()):EndIf
Next
AddDigit(dx,dy)
ExamineMouse()
FlipBuffers()
Until MouseButton(1)
Posted: Sun Aug 07, 2005 5:58 am
by oldBear
Cool enuf.
Maybe this will encourage my son to look into pb
cheers
Posted: Sun Aug 07, 2005 12:21 pm
by dobro
my screen saver !!
Code: Select all
; Matrix Cree Par Dobro
;CallDebugger
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#code
#Text_0
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 293, 129, 249, 109, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "config")
If CreateGadgetList(WindowID())
StringGadget(#code, 40, 50, 170, 30, "", #PB_String_Password)
TextGadget(#Text_0, 10, 20, 90, 20, "ENTREZ le Code")
EndIf
EndIf
EndProcedure
nbrsprite=18:;nombre de sprite dans les lignes
; on appercoit les sprites sur la meme colonne affiché l'un apres l'autre !!
taille_fonte =20
Dim ysprite(1000)
Dim de(1000)
Dim nom$(nbrsprite)
Dim index(nbrsprite)
Dim y(nbrsprite)
sprite=1
#Police=1
;*********** pour le screensaver
Param.s = Left(ProgramParameter(), 2)
If Param = "/p"
End
EndIf
If Param = "/c" :;l'utilisateur veut paramettrer le screensaver !
Open_Window_0():; jouvre ma fenetre ( cree a partir de visual designer)
Repeat
Texte$ = GetGadgetText(#code):;je recupere le contenu de ma boite de config
If Texte$="dobro":;si le gars tappe le code "dobro"
dobro=1:; c'est bon on affiche pas la surimpression
code$="ok":;on se prepare a ecrire le mot "ok" dans un fichier
Resultat = OpenFile(1, "matrix.ini") :;on cree le fichier
WriteStringN(code$) :; on ecrit dedans "ok"
CloseFile(1)
Else
dobro=0:; la le mec a pas rentré le bon code
EndIf
Until WindowEvent() = #PB_Event_CloseWindow :; le gars a fermé la boite de config
EndIf
GetCursorPos_(SourisOrigine.POINT)
ShowCursor_(0)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", taille_fonte, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN)
EcranY = GetSystemMetrics_(#SM_CYSCREEN)
;If ReadFile(1, "matrix.ini"):;en temps normal on commence par regarder si le screen saver est enregistré
; code$ = ReadString() :; on lit le contenu de "matrix.ini"
;EndIf
;CloseFile(1)
If code$="ok":; bon le gars est enregistré
dobro=1:; ce flag va retirer la surimpression
Else
dobro=0:; il n'est pas enregistrer donc on affiche la surimpression
EndIf
;************ c'est tout pour le parametrage du screen saver
;NbSprite = EcranX / 40 * 3
OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_BorderLess | #PB_Window_Invisible, "Matrix")
SetWindowPos_(WindowID(), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE) ; fenêtre toujours au premier plan
OpenWindowedScreen(WindowID(), 0, 0, EcranX, EcranY, 1, 0, 0)
For reserv=1 To nbrsprite
nom$(reserv)=Space(30)
Next reserv
; on crée un sprite
For spr=1 To nbrsprite:; nombre de sprite
Resultat = CreateSprite(spr, 24,27*Len(nom$(spr)),0)
For chaine=33 To 58:; nombre de caractere dans un sprite
car$=Chr(chaine+Random(223))
y(spr)=y(spr)+27:; pour que le text s'ecrive une ligne au dessous dans le sprite
StartDrawing(SpriteOutput(spr)):;on commence a dessiner dans le sprite SPR
BackColor(0,0,0):;couleur de fond noir
c = c +255/25 :; on eclaircie la couleur d'ecriture!!
If c>255:c=20:EndIf:; si on depasse 255 (verta fond) on ramene a 20 (vert sombre)
If chaine=58
c = 0 :; on fixe la couleur a 20 (vert sombre)
EndIf
;c=255
FrontColor(0, c, 0): ;on prend la couleur defini plus haut pour dessiner
If chaine=57:;l'avant dernier caractere
FrontColor(130, 255,130): ;on choisi une couleur verte presque blanche
EndIf
Locate(0, y(spr)):;ceci pose le crayon au bon endroit (une ligne en dessous) comme indique plus haut
DrawingFont(FontID):;attention on va ecrire du text sur la zone reserve du sprite
DrawText(car$):; voila on le fait
long = TextLength(nom$(1))
StopDrawing():; signale que l'on arrete de dessiner sur le sprite SPR
Next chaine
Next spr
;ceci prepare les colonne qui vont etre solicite pour l'affichage, un "precalcul" en fait
xrez=Int(EcranX/27)
Dim col(xrez)
For t=1 To EcranX Step 27
col(h)=t
h+1
du:
Next t
;***********************************
indexc=0
For ind=1 To xrez :;correspond au nombre de colonne (en 1024)
ysprite(ind)=-(long*2)-Random(long*10):; tire au hazard une ligne pourle depart d"un sprite
If col<>EcranX :; tant que la valeur lu est differente de la rez ecran en x
indexc=indexc+1 :
de(ind)=col(ind)
;If carcol$=""
; de(ind)=27
;EndIf
Else
indexc=0
EndIf
Next ind
indexc=0
pseud=255
Repeat
;Debug st
RandomSeed(Random(255))
For ind=1 To xrez
; si le sprite sort en bas
If ysprite(ind)>EcranY
ysprite(ind)=-(2+long*2)-Random(long*2)
EndIf
; toute l'astuce de l'animation est la !!
spr=spr+1
If spr>nbrsprite:; on affiche les sprite en decalant une lettre !!
spr=1
EndIf
ysprite(ind)=ysprite(ind)+Random(8)+2:; vitesse de descente des sprites
;DisplayTransparentSprite (spr, de(ind), ysprite(ind))
DisplaySprite(spr, de(ind), ysprite(ind))
;CallDebugger
;Debug st2
Next ind
; affichage des noms
If pseud>=380
pseud=254
EndIf
If dobro=0
;**************** crée par Dobro **********************
StartDrawing( ScreenOutput())
BackColor(0,0,0):;couleur de fond noir
FrontColor(0, 120, 0)
Locate(EcranX-TextLength("Créé par Dobro")-100, EcranY-25):;ceci pose le crayon au bon endroit (une ligne en dessous) comme indique plus haut
DrawingFont(FontID):;attention on va ecrire du text sur la zone reserve du sprite
DrawText("Créé par Dobro"):; voila on le fait
StopDrawing():
; ********************************************
EndIf
FlipBuffers()
ClearScreen(0,0,0)
GetCursorPos_(Souris.POINT)
Until WindowEvent() = #PB_Event_CloseWindow Or Souris\x <> SourisOrigine\x Or Souris\y <> SourisOrigine\y
ShowCursor_(1)
Posted: Sun Aug 07, 2005 12:23 pm
by Dare2
HeHe.

Neat.
Posted: Sun Aug 07, 2005 12:26 pm
by dobro
another screensaver whit the names of the french forum
Code: Select all
; Matrix Cree Par Dobro
;CallDebugger
Dim ysprite(1000)
Dim de(1000)
Dim nom$(30)
Dim index(30)
Dim pseudo.s(128)
Dim y(30)
sprite=1
#Police=1
;*********** pour le screensaver
Param.s = Left(ProgramParameter(), 2)
If Param = "/p"
End
EndIf
GetCursorPos_(SourisOrigine.POINT)
ShowCursor_(0)
; ***********************************
Resultat = InitSprite()
Resultat = InitSprite3D()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN)
EcranY = GetSystemMetrics_(#SM_CYSCREEN)
;NbSprite = EcranX / 40 * 3
OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_BorderLess | #PB_Window_Invisible, "Matrix")
SetWindowPos_(WindowID(), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE) ; fenêtre toujours au premier plan
OpenWindowedScreen(WindowID(), 0, 0, EcranX, EcranY, 1, 0, 0)
pseudo.s(0) = "Fred"
pseudo.s (1)= "Polux"
pseudo.s (2) = "Artemis"
pseudo.s (3) = "comtois"
pseudo.s (4) = "yukin"
pseudo.s (5) = "Patrick88"
pseudo.s (6) = "Oliv"
pseudo.s (7) = "Vyc"
pseudo.s (8) = "Keph"
pseudo.s (9) = "hackotedelaplaque"
pseudo.s (10) = "Cinderella"
pseudo.s (11)= "filperj"
pseudo.s (12)= "MacRain"
pseudo.s (13) = "Bernard"
pseudo.s (14) = "Denis"
pseudo.s (15) = "Snooze"
pseudo.s (16) = "Marcus"
pseudo.s (17) = "Dr. Dri"
pseudo.s (18) = "T€r$@k€n"
pseudo.s (19) = "melysoph"
pseudo.s (20) = "Pierre"
pseudo.s (21) = "Aranoth"
pseudo.s (22) = "Ombres"
pseudo.s (23) = "Chris"
pseudo.s (24) = "gaut"
pseudo.s (25) = "leoneo"
pseudo.s (26) = "Lukky"
pseudo.s (27) = "virtualys"
pseudo.s (28) = "Paneric"
pseudo.s (29) = "hteamspy"
pseudo.s (30) = "Jacqueline ZITO"
pseudo.s (31) = "DEF"
pseudo.s (32) = "brossden"
pseudo.s (33) = "---fred---"
pseudo.s (34) = "Crystal Noir"
pseudo.s (35) = "cookie"
pseudo.s (36) = "Heis Spiter"
pseudo.s (37) = "Le Soldat Inconnu"
pseudo.s (38) = "Flype"
pseudo.s (39) = "pg"
pseudo.s (40) = "Marc"
pseudo.s (41) = "julien"
pseudo.s (42) = "Berikco"
pseudo.s (43) = "TnPz"
pseudo.s (44) = "Dionyzos"
pseudo.s (45) = "killer7"
pseudo.s (46) = "Nadrak"
pseudo.s (47) = "philipus25110"
pseudo.s (48) = "freddix"
pseudo.s (49) = "remram44"
pseudo.s (50) = "cederavic"
pseudo.s (51) = "Orlanth"
pseudo.s (52) = "Guimauve"
pseudo.s (53) = "TEALC"
pseudo.s (54) = "nico"
pseudo.s (55) = "ZapMan"
pseudo.s (56) = "we7theboss"
pseudo.s (57) = "Jacques Stopinski"
pseudo.s (58) = "rollmops"
pseudo.s (59) = "clauded07"
pseudo.s (60) = "mgou"
pseudo.s (61) = "[JB]"
pseudo.s (62) = "ToX-007"
pseudo.s (63) = "Syszz"
pseudo.s (64) = "CORBASE"
pseudo.s (65) = "gansta93"
pseudo.s (66) = "Fiwip"
pseudo.s (67) = "KarLKoX"
pseudo.s (68) = "Yoop"
pseudo.s (69) = "patmaba"
pseudo.s (70) = "El_Choni"
pseudo.s (71) = "Jenova"
pseudo.s (72) = "Nells"
pseudo.s (73) = "france"
pseudo.s (74) = "newzig"
pseudo.s (75) = "Baka"
pseudo.s (76) = "flo"
pseudo.s (77) = "KiWin"
pseudo.s (78) = "Yves Rouquier"
pseudo.s (79) = "lionel_om"
pseudo.s (80) = "trikar"
pseudo.s (81) = "erix14"
pseudo.s (82) = "vanago"
pseudo.s (83) = "lazy"
pseudo.s (84) = "LavaLava"
pseudo.s (85) = "Silver"
pseudo.s (86) = "Necra"
pseudo.s (87) = "Jacobus"
pseudo.s (88) = "Sammael"
pseudo.s (89) = "aby56"
pseudo.s (90) = "Jean-Paul"
pseudo.s (91) = "thedoorp"
pseudo.s (92) = "sobriquet"
pseudo.s (93) = "le_pro_du_pure"
pseudo.s (94) = "gilles robert"
pseudo.s (95) = "CARTER"
pseudo.s (96) = "Patrick"
pseudo.s (97) = "chronomancien"
pseudo.s (98) = "jbernard13"
pseudo.s (99) = "blue"
pseudo.s (100) = "Mickey"
pseudo.s (101) = "Good07"
pseudo.s (102) = "RemyX"
pseudo.s (103) = "titimoby"
pseudo.s (104) = "Heero"
pseudo.s (105) = "Creepy"
pseudo.s (106) = "DOBRO"
pseudo.s (107) = "jblaise.cs"
pseudo.s (108) = "DominiqueB"
pseudo.s (109) = "bugrane"
pseudo.s (110) = "pierre the noob of of bas"
pseudo.s (111) = "blackrock"
pseudo.s (112) = "rYn0"
pseudo.s (113) = "LE_Bassiste_Atitré"
pseudo.s (114) = "NoT"
pseudo.s (115) = "Yam"
pseudo.s (116) = "fweil"
pseudo.s (117) = "YourHead[^_-]"
pseudo.s (118) = "Galen"
pseudo.s (119) = "LOULOU25"
pseudo.s (120) = "micke"
pseudo.s (121) = "charly"
pseudo.s (122) = "garzul"
pseudo.s (123) = "Bloutiouf"
pseudo.s (124) = "DarkDragon"
pseudo.s (125)= "nemo"
pseudo.s (126) = "gillespeyrin"
pseudo.s (127) = "yann64"
For reserv=1 To 30
nom$(reserv)=Space(30)
Next reserv
;CallDebugger
; on crée les sprites pseudo
For pseud=0 To 127
Resultat = CreateSprite(pseud+255,18*Len(pseudo.s(pseud)),24,#PB_Sprite_Texture)
Resultat = CreateSprite3D(pseud+255, pseud+255)
; Debug Resultat
StartDrawing(SpriteOutput(pseud+255))
Locate(0,0):
BackColor(0,0,0):;couleur de fond noir
FrontColor(110, 255,110): ;on choisi une couleur verte presque blanche
DrawingFont(FontID):
DrawText(pseudo(pseud)):
StopDrawing():
Next pseud
; on crée un sprite
For spr=1 To 30:; nombre de sprite
;CallDebugger
Resultat = CreateSprite(spr, 24,27*Len(nom$(spr)),0)
For chaine=33 To 58:; nombre de caractere dans un sprite
car$=Chr(chaine+Random(223))
y(spr)=y(spr)+27:; pour que le text s'ecrive une ligne au dessous dans le sprite
StartDrawing(SpriteOutput(spr)):;on commence a dessiner dans le sprite SPR
BackColor(0,0,0):;couleur de fond noir
c = c +255/25 :; on eclaircie la couleur d'ecriture!!
If c>255:c=20:EndIf:; si on depasse 255 (verta fond) on ramene a 20 (vert sombre)
If chaine=58
c = 0 :; on fixe la couleur a 20 (vert sombre)
EndIf
;c=255
FrontColor(0, c, 0): ;on prend la couleur defini plus haut pour dessiner
If chaine=57:;l'avant dernier caractere
FrontColor(110, 255,110): ;on choisi une couleur verte presque blanche
EndIf
Locate(0, y(spr)):;ceci pose le crayon au bon endroit (une ligne en dessous) comme indique plus haut
DrawingFont(FontID):;attention on va ecrire du text sur la zone reserve du sprite
DrawText(car$):; voila on le fait
long = TextLength(nom$(1))
StopDrawing():; signale que l'on arrete de dessiner sur le sprite SPR
Next chaine
Next spr
;ceci prepare les colonne qui vont etre solicite pour l'affichage, un "precalcul" en fait
xrez=Int(EcranX/27)
Dim col(xrez)
For t=1 To EcranX Step 27
col(h)=t
h+1
du:
Next t
;***********************************
indexc=0
For ind=1 To xrez :;correspond au nombre de colonne (en 1024)
ysprite(ind)=-(long*2)-Random(long*4):; tire au hazard une ligne pourle depart d"un sprite
If col<>EcranX :; tant que la valeur lu est differente de la rez ecran en x
indexc=indexc+1 :
de(ind)=col(ind)
;If carcol$=""
; de(ind)=27
;EndIf
Else
indexc=0
EndIf
Next ind
indexc=0
pseud=255
Repeat
;Debug st
RandomSeed(Random(255))
For ind=1 To xrez
; si le sprite sort en bas
If ysprite(ind)>EcranY
ysprite(ind)=-(2+long*2)-Random(long*2)
EndIf
; toute l'astuce de l'animation est la !!
spr=spr+1
If spr>30:; on affiche les sprite en decalant une lettre !!
spr=1
EndIf
ysprite(ind)=ysprite(ind)+Random(10)+10:; vitesse de descente des sprites
;DisplayTransparentSprite (spr, de(ind), ysprite(ind))
DisplaySprite(spr, de(ind), ysprite(ind))
;Delay(4)
Next ind
; affichage des noms
If pseud>=382
pseud=255
EndIf
Resultat = Start3D()
Sprite3DQuality(1)
zx=zx+1
zy=zy+1
DisplaySprite3D(pseud, EcranX/4, 0, 150)
ZoomSprite3D(pseud, zx, zy)
Stop3D()
If zy>EcranY:zx=0:zy=0:pseud=pseud+1:EndIf
FlipBuffers()
ClearScreen(0,0,0)
GetCursorPos_(Souris.POINT)
Until WindowEvent() = #PB_Event_CloseWindow Or Souris\x <> SourisOrigine\x Or Souris\y <> SourisOrigine\y
ShowCursor_(1)
Posted: Sun Aug 07, 2005 5:23 pm
by Fou-Lu
Dobro these two screen savers didn't work very well here, I think it's because of the size of the sprites3D (not a power of two). But they seem very good.
Well it wasn't a very original idea after all.

Posted: Sun Aug 07, 2005 9:59 pm
by Fou-Lu
I improved it a bit, now it displays other characters.
Code: Select all
;~~~~~~~~~~~~~~~~~~~~~~~
;~Fou-lu's great Matrix effect~
;~~~~~~~~~~~~~~~~~~~~~~~
;August 7th, 2005
If InitSprite() And InitMouse():Else
MessageRequester("Error","Sorry, it won't work in your pc!"):End:EndIf
OpenScreen(640,480,32,"")
For n=0 To 15
For m=0 To 56
CreateSprite(m+n*57,9,13)
StartDrawing(SpriteOutput(m+n*57))
green=(n*20)
If green>255:redblue=4*(green-255):green=255:EndIf
FrontColor(redblue,green,redblue):DrawingMode(1)
m2=m+33
if m2>63:m2=m2+98:endif
DrawText(chr(m2))
StopDrawing()
Next m
Next n
Structure MatrixNumbers
x.b
y.b
life.w
speed.b
number.b
EndStructure
NewList digit.MatrixNumbers()
Dim fill(63,29)
Procedure AddDigit(x,y)
If y>29:y=y-30:EndIf
If fill(x,y)=0
AddElement(digit())
digit()\number=Random(56)
digit()\x=x
digit()\y=y
digit()\life=255
digit()\speed=Random(15)+1
fill(x,y)=1
EndIf
EndProcedure
Repeat
dx=Random(63)
dy=Random(29)
ClearScreen(0,0,0)
ForEach digit()
If digit()\life=255-digit()\speed And Random(digit()\speed*2)>0
oldspeed=digit()\speed
index=ListIndex(digit()):AddDigit(digit()\x,digit()\y+1)
digit()\speed=oldspeed
SelectElement(digit(),index)
EndIf
DisplaySprite((digit()\life/16)*57+digit()\number,digit()\x*10,digit()\y*16)
digit()\life=digit()\life-digit()\speed
If Random(digit()\life/8)=0:digit()\number=Random(56):EndIf
If digit()\life<=0:fill(digit()\x,digit()\y)=0:DeleteElement(digit()):EndIf
Next
AddDigit(dx,dy)
ExamineMouse()
FlipBuffers()
Until MouseButton(1)
Posted: Mon Aug 07, 2006 2:52 pm
by hardfalcon
Here's the initial code ported to PB 4.0:
Code: Select all
;~~~~~~~~~~~~~~~~~~~~~~~
;~Fou-lu's great Matrix effect~
;~~~~~~~~~~~~~~~~~~~~~~~
;August 6th, 2005
If InitSprite() And InitMouse():Else
MessageRequester("Error","Sorry, it won't work in your pc!"):End:EndIf
OpenScreen(640,480,32,"")
For n=0 To 15
For m=0 To 9
CreateSprite(m+n*10,7,13)
StartDrawing(SpriteOutput(m+n*10))
green=(n*20)
If green>255:redblue=4*(green-255):green=255:EndIf
FrontColor(RGB(redblue,green,redblue)):DrawingMode(1)
DrawText(0,0,Str(m))
StopDrawing()
Next m
Next n
Structure MatrixNumbers
x.b
y.b
life.w
speed.b
number.b
EndStructure
Global NewList digit.MatrixNumbers()
Global Dim fill(63,29)
Procedure AddDigit(x,y)
If y>29:y=y-30:EndIf
If fill(x,y)=0
AddElement(digit())
digit()\number=Random(9)
digit()\x=x
digit()\y=y
digit()\life=255
digit()\speed=Random(15)+1
fill(x,y)=1
EndIf
EndProcedure
Repeat
dx=Random(63)
dy=Random(29)
ClearScreen(RGB(0,0,0))
ForEach digit()
If digit()\life=255-digit()\speed And Random(digit()\speed*2)>0
oldspeed=digit()\speed
index=ListIndex(digit()):AddDigit(digit()\x,digit()\y+1)
digit()\speed=oldspeed
SelectElement(digit(),index)
EndIf
DisplaySprite((digit()\life/16)*10+digit()\number,digit()\x*10,digit()\y*16)
digit()\life=digit()\life-digit()\speed
If Random(digit()\life/8)=0:digit()\number=Random(9):EndIf
If digit()\life<=0:fill(digit()\x,digit()\y)=0:DeleteElement(digit()):EndIf
Next
AddDigit(dx,dy)
ExamineMouse()
FlipBuffers()
Until MouseButton(1)
Posted: Tue Aug 08, 2006 12:36 am
by Guimauve
The Version 2 Updated for PB V4.0
Regards
Guimauve
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Great Matrix effect
; File : Great Matrix effect.pb
; File Version : 2.0.0
; Programmation : OK
; Programmed by : Fou-lu
; Updated by : Guimauve
; Date : 06-08-2005
; Last Update : 07-08-2006
; Coded for PureBasic V4.00
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration >>>>>
Structure Matrix
PositionX.w
PositionY.w
Life.w
Speed.b
Number.b
EndStructure
; <<<<<<<<<<<<<<<<<<<<
; <<<<< Mutators >>>>>
Macro SetMatrixPositionX(ObjectA, P_PositionX)
ObjectA\PositionX = P_PositionX
EndMacro
Macro SetMatrixPositionY(ObjectA, P_PositionY)
ObjectA\PositionY = P_PositionY
EndMacro
Macro SetMatrixLife(ObjectA, P_Life)
ObjectA\Life = P_Life
EndMacro
Macro SetMatrixSpeed(ObjectA, P_Speed)
ObjectA\Speed = P_Speed
EndMacro
Macro SetMatrixNumber(ObjectA, P_Number)
ObjectA\Number = P_Number
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Observators >>>>>
Macro GetMatrixPositionX(ObjectA)
ObjectA\PositionX
EndMacro
Macro GetMatrixPositionY(ObjectA)
ObjectA\PositionY
EndMacro
Macro GetMatrixLife(ObjectA)
ObjectA\Life
EndMacro
Macro GetMatrixSpeed(ObjectA)
ObjectA\Speed
EndMacro
Macro GetMatrixNumber(ObjectA)
ObjectA\Number
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Simple Update >>>>>
Macro UpdateMatrix(ObjectA, P_PositionX, P_PositionY, P_Life, P_Speed, P_Number)
SetMatrixPositionX(ObjectA, P_PositionX)
SetMatrixPositionY(ObjectA, P_PositionY)
SetMatrixLife(ObjectA, P_Life)
SetMatrixSpeed(ObjectA, P_Speed)
SetMatrixNumber(ObjectA, P_Number)
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 31 ms <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Init DirectX <<<<<
If InitSprite() = 0 Or InitMouse() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sorry, it won't work in your pc!")
End
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Opening the Screen <<<<<
If OpenScreen(640, 480, 32, "Great Matrix effect") = 0
If OpenScreen(640, 480, 24, "Great Matrix effect") = 0
If OpenScreen(640, 480, 16, "Great Matrix effect") = 0
MessageRequester("Error", "Sorry, it's impossible to Open the Screen !")
End
EndIf
EndIf
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Creating needed Sprites <<<<<
For n = 0 To 15
For m = 0 To 9
If CreateSprite(m + n * 10, 7, 13)
StartDrawing(SpriteOutput(m + n * 10));>
Green = (n * 20)
If Green > 255
redblue = 4 * (Green - 255)
Green = 255
EndIf
DrawingMode(1)
DrawText(0, 0, Str(m), RGB(redblue,Green,redblue))
StopDrawing();<
EndIf
Next m
Next n
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< AddDigit Procedure <<<<<
Procedure AddDigit(x,y, DigitList.Matrix(), FillArray.l(2))
If y > 29
y - 30
EndIf
If FillArray(x, y) = 0
AddElement(DigitList())
UpdateMatrix(DigitList(), x, y, 255, Random(15)+1, Random(9))
FillArray(x, y) = 1
EndIf
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Linkedlist and the array <<<<<
NewList DigitList.Matrix()
Dim FillArray(63,29)
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Running Great Matrix effect <<<<<
Repeat
dx = Random(63)
dy = Random(29)
ClearScreen(0)
ForEach DigitList()
If GetMatrixLife(DigitList()) = 255 - GetMatrixSpeed(DigitList()) And Random(GetMatrixSpeed(DigitList()) * 2) > 0
oldspeed = GetMatrixSpeed(DigitList())
index = ListIndex(DigitList())
AddDigit(GetMatrixPositionX(DigitList()), GetMatrixPositionY(DigitList()) + 1 , DigitList(), FillArray())
SetMatrixSpeed(DigitList(), oldspeed)
SelectElement(DigitList(), index)
EndIf
DisplaySprite((GetMatrixLife(DigitList()) >> 4) * 10 + GetMatrixNumber(DigitList()), GetMatrixPositionX(DigitList()) * 10, GetMatrixPositionY(DigitList()) * 16)
SetMatrixLife(DigitList(), GetMatrixLife(DigitList()) - GetMatrixSpeed(DigitList()))
If Random(GetMatrixLife(DigitList()) >> 2) = 0
SetMatrixNumber(DigitList(), Random(9))
EndIf
If GetMatrixLife(DigitList()) <= 0
FillArray(GetMatrixPositionX(DigitList()), GetMatrixPositionY(DigitList())) = 0
DeleteElement(DigitList())
EndIf
Next
AddDigit(dx, dy, DigitList(), FillArray())
FlipBuffers()
ExamineMouse()
ExamineKeyboard()
Until MouseDeltaX() Or MouseDeltaY() Or MouseWheel() Or KeyboardPushed(#PB_Key_All)
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Posted: Tue Aug 08, 2006 3:25 pm
by Rescator
Shame it's hardcoded to 640x480 though.
Any chance of making it resolution independent/adaptive?
Otherwise it's very cool. Might wanna put in a Delay(1) so it doesn't suck up all the cpu though or use FlipBuffers(2).
And you should also set SetFrameRate(50) or similar before the loop
to ensure that the framerate remain the same regardless of the current monitor refresh rate.
Posted: Tue Aug 08, 2006 7:26 pm
by Guimauve
Hello
I have modified my version. Now the screen is opened to the current screen resolution.
Regards
Guimauve
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Great Matrix effect
; File : Great Matrix effect.pb
; File Version : 2.0.1
; Programmation : OK
; Programmed by : Fou-lu
; Updated by : Guimauve
; Date : 06-08-2005
; Last Update : 08-08-2006
; Coded for PureBasic V4.00
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration >>>>>
Structure Matrix
PositionX.w
PositionY.w
Life.w
Speed.b
Number.b
EndStructure
; <<<<<<<<<<<<<<<<<<<<
; <<<<< Mutators >>>>>
Macro SetMatrixPositionX(ObjectA, P_PositionX)
ObjectA\PositionX = P_PositionX
EndMacro
Macro SetMatrixPositionY(ObjectA, P_PositionY)
ObjectA\PositionY = P_PositionY
EndMacro
Macro SetMatrixLife(ObjectA, P_Life)
ObjectA\Life = P_Life
EndMacro
Macro SetMatrixSpeed(ObjectA, P_Speed)
ObjectA\Speed = P_Speed
EndMacro
Macro SetMatrixNumber(ObjectA, P_Number)
ObjectA\Number = P_Number
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Observators >>>>>
Macro GetMatrixPositionX(ObjectA)
ObjectA\PositionX
EndMacro
Macro GetMatrixPositionY(ObjectA)
ObjectA\PositionY
EndMacro
Macro GetMatrixLife(ObjectA)
ObjectA\Life
EndMacro
Macro GetMatrixSpeed(ObjectA)
ObjectA\Speed
EndMacro
Macro GetMatrixNumber(ObjectA)
ObjectA\Number
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Simple Update >>>>>
Macro UpdateMatrix(ObjectA, P_PositionX, P_PositionY, P_Life, P_Speed, P_Number)
SetMatrixPositionX(ObjectA, P_PositionX)
SetMatrixPositionY(ObjectA, P_PositionY)
SetMatrixLife(ObjectA, P_Life)
SetMatrixSpeed(ObjectA, P_Speed)
SetMatrixNumber(ObjectA, P_Number)
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 31 ms <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Init DirectX <<<<<
If InitSprite() = 0 Or InitMouse() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sorry, it won't work in your pc!")
End
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Screen Resolution <<<<<
ScreenW = GetSystemMetrics_(#SM_CXSCREEN)
ScreenH = GetSystemMetrics_(#SM_CYSCREEN)
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Opening the Screen <<<<<
If OpenScreen(ScreenW, ScreenH, 32, "Great Matrix effect") = 0
If OpenScreen(ScreenW, ScreenH, 24, "Great Matrix effect") = 0
If OpenScreen(ScreenW, ScreenH, 16, "Great Matrix effect") = 0
MessageRequester("Error", "Sorry, it's impossible to Open the Screen !")
End
EndIf
EndIf
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Creating needed Sprites <<<<<
For n = 0 To 15
For m = 0 To 9
If CreateSprite(m + n * 10, 7, 13)
StartDrawing(SpriteOutput(m + n * 10));>
Green = (n * 20)
If Green > 255
redblue = 4 * (Green - 255)
Green = 255
EndIf
DrawingMode(1)
DrawText(0, 0, Str(m), RGB(redblue,Green,redblue))
StopDrawing();<
EndIf
Next m
Next n
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< AddDigit Procedure <<<<<
Procedure AddDigit(x,y, ScreenH, DigitList.Matrix(), FillArray.l(2))
If y > ScreenH / 10
y - 30
EndIf
If FillArray(x, y) = 0
AddElement(DigitList())
UpdateMatrix(DigitList(), x, y, 255, Random(15)+1, Random(9))
FillArray(x, y) = 1
EndIf
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Linkedlist and the array <<<<<
NewList DigitList.Matrix()
Dim FillArray(ScreenW/10, ScreenH/10)
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Running Great Matrix effect <<<<<
Repeat
dx = Random(ScreenW/10)
dy = Random(ScreenH/10)
If IsScreenActive()
ClearScreen(0)
ForEach DigitList()
If GetMatrixLife(DigitList()) = 255 - GetMatrixSpeed(DigitList()) And Random(GetMatrixSpeed(DigitList()) * 2) > 0
oldspeed = GetMatrixSpeed(DigitList())
index = ListIndex(DigitList())
AddDigit(GetMatrixPositionX(DigitList()), GetMatrixPositionY(DigitList()) + 1 , ScreenH, DigitList(), FillArray())
SetMatrixSpeed(DigitList(), oldspeed)
SelectElement(DigitList(), index)
EndIf
DisplaySprite((GetMatrixLife(DigitList()) >> 4) * 10 + GetMatrixNumber(DigitList()), GetMatrixPositionX(DigitList()) * 10, GetMatrixPositionY(DigitList()) * 16)
SetMatrixLife(DigitList(), GetMatrixLife(DigitList()) - GetMatrixSpeed(DigitList()))
If Random(GetMatrixLife(DigitList()) >> 2) = 0
SetMatrixNumber(DigitList(), Random(9))
EndIf
If GetMatrixLife(DigitList()) <= 0
FillArray(GetMatrixPositionX(DigitList()), GetMatrixPositionY(DigitList())) = 0
DeleteElement(DigitList())
EndIf
Next
AddDigit(dx, dy, ScreenH, DigitList(), FillArray())
Else
Delay(10)
EndIf
FlipBuffers()
ExamineMouse()
ExamineKeyboard()
Until MouseDeltaX() Or MouseDeltaY() Or MouseWheel() Or KeyboardPushed(#PB_Key_All)
CloseScreen()
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Posted: Tue Aug 08, 2006 9:20 pm
by Shannara
Fou-Lu wrote:Dobro these two screen savers didn't work very well here, I think it's because of the size of the sprites3D (not a power of two). But they seem very good.
Well it wasn't a very original idea after all.

The power of 2 have been removed in dx9 (or earlier?), and is now video driver specific. Aka, all new NVidia and ATI(?) cards no longer have that restriction. come to think of it, After I updated my laptop drivers, the Geforce 2 Go 5600 doesnt have that restriction either.
Updated your drivers yet?

Posted: Sun Aug 13, 2006 8:59 pm
by Fou-Lu
My drivers are updated... but only for dx8. There are no dx9 drivers for my gfx card (onboard sis530

, really old...)
Posted: Mon Aug 14, 2006 7:07 am
by ToastEater
Very nice examples

i would like to see more

good practise for my n00b directX knowlegde.
Thanks a bunch
regardz