Here is a test, OK on windows console host.
Is it doable in the terminal?
Code: Select all
#include "windows.bi"
Dim Shared As hdc h:h=getdc(getconsolewindow())
Dim Shared As hdc Memhdc:Memhdc = CreateCompatibleDC(h)
Dim Shared As Any Ptr Membitmap:Membitmap = CreateCompatibleBitmap(h, Loword(Width)*8,Hiword(Width)*16)
SelectObject(Memhdc, Membitmap)
SelectObject(Memhdc,GetStockObject(DC_BRUSH))
SelectObject(Memhdc,GetStockObject(DC_PEN))
Declare Sub getconsole(Byref columns As Long,Byref rows As Long)
Dim Shared As Long xx,yy
getconsole(xx,yy)
Print xx,yy
Print Loword(Width),Hiword(Width)
print "Press any key"
sleep
Sub getconsole(Byref columns As Long,Byref rows As Long)
Dim As CONSOLE_SCREEN_BUFFER_INFO csbi
print GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), @csbi)
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1
End Sub
Sub setfontsize(h As hdc,size As Long,style As zstring Ptr)
SelectObject(h,CreateFont(size,0,0,0,Loword(Width)*8,0,0,0,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,VARIABLE_PITCH,style))
End Sub
Sub setfontcolours(h As hdc,text As Ulong)
SetTextColor(h,text)
SetBkMode(h,transparent)
End Sub
Sub ClearScreen(c As Ulong=bgr(0,0,100))
Var colour=c
SetDCBrushColor(memhdc,colour)
SetDCPenColor(memhdc,colour)
rectangle(memhdc,0,0,Loword(Width)*8,Hiword(Width)*16)
End Sub
Sub text(h As hdc,x As Long,y As Long,s As String)
textout(h,x,y,s,Len(s))
End Sub
Sub pprint(s As String,x As Long,y As Long,size As Long=30,colour As Ulong=bgr(200,100,0),kind As String="courier new")
setfontsize(Memhdc,size,kind)
setfontcolours(Memhdc,colour)
text(Memhdc,x,y,s)
End Sub
Sub _circle(h As hdc,xx As Long,yy As Long,r As Long,clr As Ulong)'b as ball) 'custom
#define incircle(cx,cy,r,mx,my,a) _
Iif(a<=1,a*(cx-mx)*a*(cx-mx) +1*(cy-my)*1*(cy-my)<= r*r*a*a,a*(cx-mx)*a*(cx-mx) +1*(cy-my)*1*(cy-my)<= (r)*(r))
For x As Long=xx-r To xx+r
For y As Long=yy-r To yy+r
If incircle(xx,yy,r,x,y,1) Then
SetPixel(h,x,y,clr)
End If
Next
Next
End Sub
sub dots(h as hdc)
#define Irange(f,l) Int(Rnd*((l+1)-(f)))+(f)
for n as long=1 to 500
SetPixel(h,irange(0,Loword(Width)*8),irange(0,Hiword(Width)*16),bgr(255,255,255))
next
end sub
Sleep 100
randomize 3
clearscreen()
dots(Memhdc)
_circle(Memhdc,700,100,50,bgr(255,255,255))
_circle(Memhdc,690,100,48,bgr(50,50,50))
pprint "Last night I saw the new moon",5,15,,rnd*bgr(255,255,255)
pprint "With the old moon in her arm,",5,45,,rnd*bgr(255,255,255)
pprint "A sign, a sign since we were born",5,75,,rnd*bgr(255,255,255)
pprint "There'll be a deadly storm.",5,105,,rnd*bgr(255,255,255)
pprint "They had not sailed upon the sea",5,135,,rnd*bgr(255,255,255)
pprint "A day, but barely three,",5,165,,rnd*bgr(255,255,255)
pprint "When loud and boisterous grew the winds",5,195,,rnd*bgr(255,255,255)
pprint "And stormy grew the sea.",5,225,,rnd*bgr(255,255,255)
pprint "(From Anglified version of the ballad of Sir Patrick Spens)",5,300,20,bgr(255,255,255),"times new roman"
BitBlt(h,0, 0,Loword(Width)*8,Hiword(Width)*16,Memhdc, 0, 0,SRCCOPY)
sub finish destructor
DeleteObject(Membitmap)
DeleteDC (Memhdc)
end sub
Sleep