sprites now need to be created with #PB_Sprite_AlphaBlending and it breaks compatibility with 6.20 and prior code
test with 6.20 and 6.30
Code: Select all
EnableExplicit
#WITHSOUND = 0
CompilerIf #PB_Compiler_Version >= 630
#MPB_Sprite_AlphaBlending = #PB_Sprite_AlphaBlending
CompilerElse
#MPB_Sprite_AlphaBlending = 0
CompilerEndIf
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
Global font,font1
Global event,ct,sc,bput=0,st=ElapsedMilliseconds()+30000
Global width, height,color,lt
Global snd,spath.s
Structure matrix
ncols.i
nrows.i
total.i
twidth.i
theight.i
gcount.i
Array depth.i(0)
Array mat.i(0)
Array spmatrix.i(0)
EndStructure
Global matrix.matrix
Global spexp
Procedure InitMatrix(width,height)
;Protected char.s,chars.s = "ハミヒーウシナモニサワツオリアホテマケメエカキムユラセネスタヌヘ+-/*><=,.0123456789abcdefABCDEF"
Protected char.s,chars.s = "бвгджзклмнпрстфхцчшщаэыуояеёюиъь+-/*><=,.0123456789ABCDEFKPUTIN"
Protected len = Len(chars)
Protected a,tempImage,font,fontsTextWidth,fontsTextHeight,mx,my
ReDim matrix\spmatrix(len)
font = LoadFont(#PB_Any,"Arial",22,#PB_Font_HighQuality | #PB_Font_Bold)
For a = 0 To len
tempImage = CreateImage(#PB_Any,1,1) ;if you need to get the size of a font in pixels
If tempImage
If StartDrawing(ImageOutput(tempImage)) ;draw to the temp image
DrawingFont(FontID(font)) ;with the selected font
char.s = Mid(chars,a,1)
fontsTextWidth = TextWidth(char) ;get the width and height in pixles
fontsTextHeight = TextHeight(char)
If fontsTextWidth > mx
mx = fontsTextWidth
EndIf
If fontsTextHeight > my
my = fontsTextHeight
EndIf
StopDrawing()
matrix\spmatrix(a) = CreateSprite(#PB_Any,fontsTextWidth,fontsTextHeight,#MPB_Sprite_AlphaBlending) ;create the sprite of required size
If matrix\spmatrix(a)
If StartDrawing(SpriteOutput(matrix\spmatrix(a))) ;now you can draw the text to the sprite
DrawingFont(FontID(font))
DrawingFont(FontID(font))
DrawText(0,0,char,RGB(1,1,1))
StopDrawing()
EndIf
EndIf
EndIf
FreeImage(tempImage)
EndIf
Next
matrix\ncols = width / (mx)
matrix\nrows = height / (my)
matrix\twidth = mx
matrix\theight = my
matrix\total = matrix\ncols * matrix\nrows
ReDim matrix\mat(matrix\total)
ReDim matrix\depth(matrix\ncols)
For a = 0 To matrix\ncols
matrix\depth(a) = Random(matrix\nrows,0)
Next
For a = 0 To matrix\total
matrix\mat(a) = matrix\spmatrix(Random(ArraySize(matrix\spmatrix()),1))
Next
EndProcedure
Procedure DrawMatrix(color)
Protected a,xx,yy,sp
Protected sfy.f = (0-255) / (0-matrix\nrows)
Static et,et1,col
For a = 0 To matrix\total-1
xx = a / matrix\nrows
yy = a % matrix\nrows
sp = matrix\mat(a)
DisplayTransparentSprite(sp,(xx*matrix\twidth),(yy * matrix\theight), matrix\depth(xx)*sfy-(yy*sfy),color)
Next
If ElapsedMilliseconds() > et
For a = 0 To matrix\ncols
matrix\depth(a) = Random(matrix\nrows,10)
Next
et = ElapsedMilliseconds()+500;250
EndIf
If ElapsedMilliseconds() > et1
For a = 0 To matrix\total
matrix\mat(a) = matrix\spmatrix(Random(ArraySize(matrix\spmatrix()),1))
Next
et1 = ElapsedMilliseconds()+125
EndIf
EndProcedure
Procedure DisplayMessageCenter(window,msg.s,color=255,scale.f=1.00)
Protected spriteNumber,tempImage,fontsTextWidth,fontsTextHeight,cx,cy,a,b
Static overlay,ct1
ct1+1
If Not overlay
overlay = CreateSprite(#PB_Any,width,height,#MPB_Sprite_AlphaBlending) ;make the crt overlay
If overlay
If StartDrawing(SpriteOutput(overlay))
Box(0,0,width,height,RGB(1,1,1))
For a = 2 To width-1 Step 2
For b = 2 To height-3 Step 3
Plot(a,b,0)
Plot(a,b+1,0)
Next
Next
StopDrawing()
EndIf
EndIf
EndIf
tempImage = CreateImage(#PB_Any,1,1) ;if you need to get the size of a font in pixels
If tempImage
If StartDrawing(ImageOutput(tempImage)) ;draw to the temp image
DrawingFont(FontID(font)) ;with the selected font
fontsTextWidth = TextWidth(msg) ;get the width and height in pixles
fontsTextHeight = TextHeight(msg)
StopDrawing()
spriteNumber = CreateSprite(#PB_Any,fontsTextWidth,fontsTextHeight,#MPB_Sprite_AlphaBlending) ;create the sprite of required size
If spriteNumber
If StartDrawing(SpriteOutput(spriteNumber)) ;now you can draw the text to the sprite
DrawingFont(FontID(font))
DrawText(0,0,msg,color)
StopDrawing()
TransparentSpriteColor(spriteNumber,0)
cx = (((width - (fontsTextWidth*scale)) / 2))
cy = (((height - (fontsTextHeight*scale)) / 2))
ZoomSprite(spriteNumber,fontsTextWidth*scale,fontsTextHeight*scale)
Protected x.i,y.i
x = cx-(ct1&2)
y = cy-(ct1&1)
DisplayTransparentSprite(spriteNumber,x,y) ;jitter the x and y ccoordinates
EndIf
FreeSprite(spriteNumber)
TransparentSpriteColor(overlay,0)
DisplayTransparentSprite(overlay,0,0,255)
EndIf
EndIf
FreeImage(tempImage)
EndIf
EndProcedure
ExamineDesktops()
width = DesktopWidth(0)
height = DesktopHeight(0)
font = LoadFont(#PB_Any,"Arial",height/8,#PB_Font_HighQuality | #PB_Font_Bold)
OpenScreen(width,height,32,"Putin's ACME clock")
initmatrix(width,height)
Global bdraw,cdtime
Repeat
ExamineKeyboard()
ExamineMouse()
If bput > 0
ClearScreen(RGB((ct&63)*2,0,0))
color = RGB(Random(255),Random(255),Random(255))
drawMatrix(color)
cdtime = Date()-(ct*60+(60-ct))
If Date() - cdtime > (Hour(Date())*3600)
bdraw=1
EndIf
DisplayMessageCenter(0,FormatDate("%hh:%ii:%ss",cdtime),RGB(0,255,0),0.025*sc)
ct+1
Else
ClearScreen(0)
color=RGB(0,255,0)
drawMatrix(color)
DisplayMessageCenter(0,FormatDate("%hh:%ii:%ss", Date()),color)
ct=0
bdraw=0
EndIf
sc+1
sc%60
FlipBuffers()
If (KeyboardInkey() Or ElapsedMilliseconds() > st)
bput ! 1
EndIf
Until KeyboardPushed(#PB_Key_Escape)

