Left mouse button: paint
Right mouse button: delete
Ctrl+R: switch character set (randomly)
Ctrl+L: clear canvas
Note: the DPIaware compiler flag must be disabled.

Code: Select all
;; updated 15 dec 2024
Procedure.s SetCharset(i)
AllCharsets.s = "0123456789ABCDEF,abcdefghijklmnopqrstuvwxyz0123456789,01,AGTC,/\o,■,▒"
If i = 0 : i = Random(CountString(AllCharsets, ","))+1 : EndIf
SelectedCharset.s = StringField(AllCharsets, i, ",")
SetWindowTitle(0, "ASCII-Paint - charset: " + SelectedCharset)
ProcedureReturn SelectedCharset
EndProcedure
#CELLSIZE = 28
#XXX = 24
#YYY = 20
AreaX = #CELLSIZE * #XXX
AreaY = #CELLSIZE * #YYY
OpenCryptRandom()
LoadFont(9, "Lucida Console", 16)
OpenWindow( 0,0,0,AreaX+160,AreaY+20,"ASCII-Paint",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor (0,0)
CanvasGadget(2,8,2,AreaX,AreaY)
StartDrawing(CanvasOutput(2))
Box(0,0, AreaX, AreaY,0)
StopDrawing()
;; init palette
CanvasGadget(3,AreaX + 50 , 4, 100 ,AreaY + 10)
StartDrawing(CanvasOutput(3))
Box(0,0, 100 , AreaY + 10 , $262626)
For gg = 0 To 8
color = (RGB(Random(255), Random(255), Random(255))) : Box(20, 18 + gg*30 , 20, 20, color)
Next
For gg = 0 To 8
color = (RGB(Random(255), Random(255), Random(255))) : Box(50, 18 + gg*30 , 20, 20, color)
Next
selectedColor = color
Box(1, 1, 3, WindowHeight(0), selectedColor)
StopDrawing()
;; init palette end
charset.s = SetCharset(2)
AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_L, 123) ;; clear canvas
AddKeyboardShortcut(0, #PB_Shortcut_Control | #PB_Shortcut_R, 124) ;; switch charset
Repeat
Select WaitWindowEvent():
Case #PB_Event_Menu
Select EventMenu()
Case 123
StartDrawing(CanvasOutput(2))
Box(0,0, AreaX, AreaY,0)
StopDrawing()
Case 124
charset.s = SetCharset(0)
EndSelect
Case #PB_Event_CloseWindow: End
Case #PB_Event_Gadget
Select EventGadget()
Case 3
If EventType() = #PB_EventType_LeftClick
StartDrawing(CanvasOutput(3))
selectedColor = Point(GetGadgetAttribute(3, #PB_Canvas_MouseX), GetGadgetAttribute(3, #PB_Canvas_MouseY))
Box(1, 1, 3, WindowHeight(0), selectedColor)
StopDrawing()
EndIf
Case 2
Select EventType()
Case #PB_EventType_LeftButtonDown
pendown=1
Case #PB_EventType_RightButtonDown
delmode=1 : pendown=1
Case #PB_EventType_LeftButtonUp, #PB_EventType_RightButtonUp
pendown=0 : delmode=0
Case #PB_EventType_MouseMove
If pendown=1
mx=GetGadgetAttribute(2, #PB_Canvas_MouseX) : my=GetGadgetAttribute(2, #PB_Canvas_MouseY)
mxx=(mx/#CELLSIZE) * #CELLSIZE : myy=(my/#CELLSIZE) * #CELLSIZE
StartDrawing(CanvasOutput(2))
DrawingFont(FontID(9))
If delmode
RoundBox(mxx,myy, #CELLSIZE - 2, #CELLSIZE - 2,2,2, 0)
Else
char$ = Mid(charset, CryptRandom(Len(charset)), 1)
DrawText(mxx, myy, char$ , selectedColor)
EndIf
StopDrawing()
EndIf
EndSelect
EndSelect
EndSelect
ForEver