Liquid Crystal Digits

Share your advanced PureBasic knowledge/code with the community.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Liquid Crystal Digits

Post 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
DE AA EB
juror
Enthusiast
Enthusiast
Posts: 228
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Liquid Crystal Digits

Post by juror »

very cool - 8)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Liquid Crystal Digits

Post by IdeasVacuum »

That's interesting, but I think the fonts like LCDMono are very good too.....
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Liquid Crystal Digits

Post by Little John »

Very nice, davido.
Thank you!
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Liquid Crystal Digits

Post by davido »

Thank you all for your kind remarks.
@IdeasVacuum,
I'll have to look at LCDMono.
DE AA EB
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Liquid Crystal Digits

Post by Kwai chang caine »

Works great, can be useful
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Liquid Crystal Digits

Post 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
    
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Liquid Crystal Digits

Post by davido »

@WilliamL,
An excellent improvement. :D
Thank you.
DE AA EB
User avatar
idle
Always Here
Always Here
Posts: 5098
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Liquid Crystal Digits

Post by idle »

very good thanks for sharing
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Liquid Crystal Digits

Post by Kwai chang caine »

Works great, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply