Greyscale bars/Display: Difference between revisions

m (→‎{{header|Phix}}: added syntax colouring, made p2js compatible)
Line 1,383:
 
=={{header|PureBasic}}==
<lang PureBasic>If Not InitKeyboard(): End: EndIf ;can't init keyboardEnableExplicit
If Not InitSprite(): End: EndIf ;can't init sprite/screen library
If Not ExamineDesktops(): End: EndIf ;can't retrieve information about desktop
 
Macro Check(Function)
Define height.f, width.f, depth
If Not Function : End : EndIf
height.f = DesktopHeight(0)
EndMacro
width.f = DesktopWidth(0)
depth = DesktopDepth(0)
 
Check(InitKeyboard()) ; Cannot initialize keyboard
If OpenScreen(width, height, depth, "Press ENTER to exit")
If Not Check(InitSprite():) End: EndIf ; Cannot ;can't initinitialize sprite/screen library
Define vsCount, v, h, columns, columnWidth, endColor, shade
If Not Check(ExamineDesktops():) End:; EndIf ;can'tCannot retrieve informationinformations about desktopdesktops
StartDrawing(ScreenOutput())
vsCount = 4
For v = 0 To 3
columns = (v + 1) * 8
columnWidth = Round(width / columns, #PB_Round_Up)
endColor = $FFFFFF * (v % 2) ;alternate between black and white for first and last bar
Box(0, (height * v) / vsCount, columnWidth, height / vsCount, endColor)
 
Define.i iHeight, iWidth, iDepth
For h = 1 To columns - 2
height.fiHeight = DesktopHeight(0)
If v % 2 = 0
width.fiWidth = DesktopWidth(0)
shade = 256 / columns * (h + 1)
depthiDepth = DesktopDepth(0)
Else
shade = 256 / columns * (columns - (h + 1))
EndIf
Box((width * h) / columns, (height * v) / vsCount, columnWidth, height / vsCount, RGB(shade, shade, shade))
Next
Box((width * (columns - 1)) / columns, (height * v) / vsCount, columnWidth, height / vsCount, $FFFFFF - endColor)
Next
StopDrawing()
FlipBuffers()
 
If OpenScreen(widthiWidth, heightiHeight, depthiDepth, "Press ENTER to exit")
Repeat
Define.i bMode.b, iLines, fLine.f, iRow, iSpans, fSpan.f,
Delay(10)
fColor.f, iTop, iWide, iHigh, iCol, iShade
ExamineKeyboard()
If StartDrawing(ScreenOutput())
Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Return)
bMode = #True ; Pow = #True; Add = #False
iLines = 32 ; Number of Lines
If iLines < 1 : iLines = 1 : EndIf ; Pow/Add-Min
If bMode
If iLines > 6 : iLines = 6 : EndIf ; Pow-Max
Else
If iLines > 32 : iLines = 32 : EndIf ; Add-Max
EndIf
fLine = iHeight / iLines
iLines - 1
For viRow = 0 To 3iLines
If v % 2 = 0bMode
iSpans = Pow(2, iRow + 3) - 1 ; Pow
Else
columns iSpans = (viRow + 1) * 8 - 1 ; Add
EndIf
fSpan = iWidth / (iSpans + 1)
fColor = 255 / iSpans
columnWidthiTop = Round(widthiRow /* columnsfLine, #PB_Round_Up)
iWide = Round(fSpan, #PB_Round_Up)
iHigh = Round(fLine, #PB_Round_Up)
For hiCol = 10 To columns - 2iSpans
iShade = Round(fColor * iCol, #PB_Round_Up)
If iRow % 2 <> 0 : iShade = 255 - iShade : EndIf ; Alternation
Box(Round(iCol * fSpan, #PB_Round_Up), iTop, iWide, iHigh,
RGB(iShade, iShade, iShade))
Next
Next
StopDrawing()
FlipBuffers()
Repeat
Delay(1030)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or KeyboardPushed(#PB_Key_Return)
KeyboardPushed(#PB_Key_Return)
EndIf
CloseScreen()
EndIf</lang>
End</lang>
Press Enter or Escape to exit the programs's display.