Pinstripe/Display: Difference between revisions
m (→{{header|PureBasic}}: template fix) |
m (→{{header|PureBasic}}: Update) |
||
Line 5: | Line 5: | ||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
<lang PureBasic>; Create a Pinstripe image |
|||
{{incorrect|PureBasic|This does not fill the screen.}} |
|||
⚫ | |||
Generating the Pinstripe picture |
|||
⚫ | |||
Protected x, l=1, imgID |
Protected x, l=1, imgID |
||
imgID=CreateImage(#PB_Any, Width, |
imgID=CreateImage(#PB_Any, Width, Height) |
||
If imgID |
If imgID |
||
StartDrawing(ImageOutput(imgID)) |
StartDrawing(ImageOutput(imgID)) |
||
Repeat |
Repeat |
||
Box(x, 0, l, Height, #White) |
|||
If x> |
If x>3*Width/4 And l<4 : l=4: x-1 |
||
ElseIf x> |
ElseIf x>Width/2 And l<3 : l=3: x-1 |
||
ElseIf x> |
ElseIf x>Width/4 And l<2 : l=2: x-1 |
||
EndIf |
EndIf |
||
x+2*l |
x+2*l |
||
Line 23: | Line 22: | ||
EndIf |
EndIf |
||
ProcedureReturn imgID |
ProcedureReturn imgID |
||
EndProcedure |
EndProcedure |
||
Test the code, and save the result. |
|||
; Open a window and display the pinstripe |
|||
<lang PureBasic>PicID=PinstripeDisplay() |
|||
If OpenWindow(0,0,0,1,1,"PureBasic Pinstripe",#PB_Window_Maximize|#PB_Window_SystemMenu) |
|||
If PicID And UsePNGImageEncoder() |
|||
PicID = PinstripeDisplay(WindowWidth(0), WindowHeight(0)) |
|||
Path$=GetSpecialFolder(#CSIDL_DESKTOP)+"PB_Pinstripe.png" |
|||
ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), ImageID(PicID)) |
|||
SaveImage(PicID, Path$,#PB_ImagePlugin_PNG,0,2) |
|||
While WaitWindowEvent() <> #PB_Event_CloseWindow |
|||
⚫ | |||
Wend |
|||
Result |
|||
EndIf |
|||
[[file:PB_Pinstripe.png]] |
|||
⚫ | |||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
Revision as of 08:58, 4 June 2011
You are encouraged to solve this task according to the task description, using any language you may know.
The task is to demonstrate the creation of 1 pixel wide pinstripes across the width of the display. The pinstripes should alternate one pixel white, one pixel black.
Quarter of the way down the display, we can switch to a wider 2 pixel wide pinstripe pattern, alternating two pixels white, two pixels black. Half way down the display, we switch to 3 pixels wide, and for the lower quarter of the display we use 4 pixels.
PureBasic
<lang PureBasic>; Create a Pinstripe image Procedure PinstripeDisplay(Width, Height)
Protected x, l=1, imgID imgID=CreateImage(#PB_Any, Width, Height) If imgID StartDrawing(ImageOutput(imgID)) Repeat Box(x, 0, l, Height, #White) If x>3*Width/4 And l<4 : l=4: x-1 ElseIf x>Width/2 And l<3 : l=3: x-1 ElseIf x>Width/4 And l<2 : l=2: x-1 EndIf x+2*l Until x >= Width StopDrawing() EndIf ProcedureReturn imgID
EndProcedure
- Open a window and display the pinstripe
If OpenWindow(0,0,0,1,1,"PureBasic Pinstripe",#PB_Window_Maximize|#PB_Window_SystemMenu)
PicID = PinstripeDisplay(WindowWidth(0), WindowHeight(0)) ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), ImageID(PicID)) While WaitWindowEvent() <> #PB_Event_CloseWindow Wend
EndIf </lang>
Tcl
<lang tcl>package require Tcl 8.5 package require Tk 8.5
wm attributes . -fullscreen 1 pack [canvas .c -highlightthick 0] -fill both -expand 1 set colors {black white}
set dy [expr {[winfo screenheight .c]/4}] set y 0 foreach dx {1 2 3 4} {
for {set x 0} {$x < [winfo screenwidth .c]} {incr x $dx} {
.c create rectangle $x $y [expr {$x+$dx}] [expr {$y+$dy}] \
-fill [lindex $colors 0] -outline {}
set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]
} incr y $dy
}</lang>