Page 1 of 1

Liquid Crystal Digits

Posted: Mon Mar 21, 2016 11:26 pm
by davido
I required some liquid crystal digits so I created a set with Vector Graphics.
I list the code below in case someone may find them useful.
Of course, any improvements would be welcomed.
5.42LTS and tested on OSX and Windows 10.

Code: Select all

Macro HexaaaagonVertical(X,Y,W,H)
      MovePathCursor(X, Y)
      AddPathLine(X + W/2, Y + W/2)
      AddPathLine(X + W/2, Y + H + W/2)
      AddPathLine(X,Y + H + W)
      AddPathLine(X - W/2,Y + H + W/2)
      AddPathLine(X - W/2,Y + W/2)
      ClosePath() 
    EndMacro
    
Macro HexaaaagonHorizontal(X,Y,W,H)
      MovePathCursor(X, Y)
      AddPathLine(X + W/2,Y - W/2)
      AddPathLine(X + W/2 + H,Y - W/2)
      AddPathLine(X + W + H,Y)
      AddPathLine(X + W/2 + H,Y + W/2)
      AddPathLine(X + W/2,Y + W/2)
      ClosePath() 
    EndMacro
    
    Macro MakeNumber(X,Y,W,H,Num)
      If Num & %0000001
        HexaaaagonHorizontal(X,Y,W,H)
      EndIf
      If Num & %0000010 
        HexaaaagonVertical(X - 1,Y + 1,W,H)
      EndIf
      If Num & %0000100 
        HexaaaagonVertical(X + W + H + 1,Y + 1,W,H)
      EndIf
      If Num & %0001000 
        HexaaaagonHorizontal(X,Y + W + H + 2,W,H)
      EndIf
      If Num & %0010000 
        HexaaaagonVertical(X - 1,Y + W + H + 3,W,H)
      EndIf
      If Num & %0100000 
        HexaaaagonVertical(X + W + H + 1,Y + W + H + 3,W,H)
      EndIf
      If Num & %1000000 
        HexaaaagonHorizontal(X,Y + W + W + H + H + 4,W,H)
      EndIf
    EndMacro  
    
    Global Dim Digits.i(9)
    Digits(0) = %1110111
    Digits(1) = %0100100
    Digits(2) = %1011101
    Digits(3) = %1101101
    Digits(4) = %0101110
    Digits(5) = %1101011
    Digits(6) = %1111011
    Digits(7) = %0100101
    Digits(8) = %1111111
    Digits(9) = %1101111
    
    
If OpenWindow(0, 0, 0, 400, 100, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 600, 500)

    If StartVectorDrawing(CanvasVectorOutput(0))
      
      For M = 0 To 9
        MakeNumber(20 + M * 33,20,4,10,Digits(M))
      Next M

      VectorSourceColor(RGBA(0, 0, 255, 255))
      FillPath()
;     
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

Re: Liquid Crystal Digits

Posted: Tue Mar 22, 2016 3:00 am
by juror
very cool - 8)

Re: Liquid Crystal Digits

Posted: Tue Mar 22, 2016 3:13 am
by IdeasVacuum
That's interesting, but I think the fonts like LCDMono are very good too.....

Re: Liquid Crystal Digits

Posted: Tue Mar 22, 2016 6:10 am
by Little John
Very nice, davido.
Thank you!

Re: Liquid Crystal Digits

Posted: Tue Mar 22, 2016 8:04 am
by davido
Thank you all for your kind remarks.
@IdeasVacuum,
I'll have to look at LCDMono.

Re: Liquid Crystal Digits

Posted: Tue Mar 22, 2016 9:47 am
by Kwai chang caine
Works great, can be useful
Thanks for sharing 8)

Re: Liquid Crystal Digits

Posted: Wed Nov 03, 2021 10:02 pm
by WilliamL
I was impressed with the LCD digits and starting playing with vector graphics for the first time. It all seems a bit alien to me but this was my start with vector graphics and the idea was to make LCD images in any size that I could use. This digits are completely adjustable for size, taper, and spacing between crystals(?). I want to thank davido for the motivation.

Code: Select all

EnableExplicit
  
Procedure VerticalPath(X,Y,W,H,taper)
    Define offset=1
    Define py=y+offset
    Define ph=(h/2)-taper-offset-offset
    MovePathCursor(x,py) ; top point of vertical line
    AddPathLine(taper,taper, #PB_Path_Relative) ; \
    AddPathLine(0,ph-taper-taper,#PB_Path_Relative) ; |
    AddPathLine(-taper,taper,#PB_Path_Relative) ; /
    AddPathLine(-taper,-taper,#PB_Path_Relative) ; \
    AddPathLine(0,-ph+taper+taper,#PB_Path_Relative) ; |
    AddPathLine(taper,-taper,#PB_Path_Relative) ; /
    ClosePath() 
EndProcedure
     
Procedure HorizontalPath(x,y,w,h,taper)
    Define offset=1
    Define px=x+taper+offset
    Define pw=w-taper-taper-offset-offset
      MovePathCursor(px,y)
      AddPathLine(taper,-taper, #PB_Path_Relative) ; /
      AddPathLine(pw-taper-taper,0,#PB_Path_Relative) ; - 
      AddPathLine(taper,taper,#PB_Path_Relative) ; \
      AddPathLine(-taper,taper,#PB_Path_Relative) ; /
      AddPathLine(-pw+taper+taper,0,#PB_Path_Relative) ; -
      AddPathLine(-taper,-taper,#PB_Path_Relative) ; \
      ClosePath() 
EndProcedure
    
Macro MakeNumber(Num,W,H,taper)
    If Num & %0000001 ; top horizontal line
        HorizontalPath(0,taper,W,H,taper) ; x,y,w,h,slant ; left point
    EndIf
    If Num & %0000010  ; top left verticle
        VerticalPath(taper,taper,W,H,taper)
    EndIf
    If Num & %0000100  ; top right verticle
        VerticalPath(w-taper,taper,W,H,taper)
    EndIf
    If Num & %0001000 ; center line
        HorizontalPath(0,(h/2),W,H,taper)
    EndIf
    If Num & %0010000  ; bottom left verticle
        VerticalPath(taper,h/2,W,H,taper)
    EndIf
    If Num & %0100000  ; bottom right verticle
        VerticalPath(w-taper,h/2,W,H,taper)
    EndIf
    If Num & %1000000 ; bottom line
        HorizontalPath(0,h-taper,W,H,taper)
    EndIf
EndMacro  
    
    Global Dim Digits.i(9)
    Digits(0) = %1110111
    Digits(1) = %0100100
    Digits(2) = %1011101
    Digits(3) = %1101101
    Digits(4) = %0101110
    Digits(5) = %1101011
    Digits(6) = %1111011
    Digits(7) = %0100101
    Digits(8) = %1111111
    Digits(9) = %1101111
    
    #image=0
Define digit
Define Width=50
Define Height=width*2
Define taper=width/10
If OpenWindow(0, 0, 0,(width*10)*2,height+20, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

           
    For digit = 0 To 9
        CreateImage(#image+digit,width,height, 24, #White)
            StartVectorDrawing(ImageVectorOutput(#image+digit))
                MakeNumber(Digits(digit),width,height,taper)
                VectorSourceColor(RGBA(0, 0, 255, 255))
                FillPath()
            StopVectorDrawing()
        ImageGadget(#image+digit,10+(digit*width*2),10,width,height,ImageID(#image+digit))
    Next
EndIf

Define event
Repeat
    event=WaitWindowEvent()
Until event = #PB_Event_CloseWindow
    

Re: Liquid Crystal Digits

Posted: Thu Nov 04, 2021 7:53 pm
by davido
@WilliamL,
An excellent improvement. :D
Thank you.

Re: Liquid Crystal Digits

Posted: Thu Nov 04, 2021 9:54 pm
by idle
very good thanks for sharing

Re: Liquid Crystal Digits

Posted: Sat Nov 06, 2021 8:42 pm
by Kwai chang caine
Works great, thanks for sharing 8)