Some Tips using VectorDrawing lib.

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Some Tips using VectorDrawing lib.

Post by RASHAD »

- Busy

Code: Select all

Global bColor.q 
LoadFont(0, "Georgia", 8, #PB_Font_Bold)  
Procedure runCB(par)
  CreateImage(0,120,120)
  Repeat
    alpha2 = 255    
    For angle2 = 361 To 0 Step -15     
      StartVectorDrawing(ImageVectorOutput(0))
        VectorSourceColor(bColor)
        FillVectorOutput()
        alpha = 255    
        For angle = 30 To 361 Step 30
          VectorSourceColor(RGBA(255,0,0,alpha))   
          x = 60 + 50*Cos(Radian(angle))
          y = 60 + 50*Sin(Radian(angle))
          AddPathCircle(x,y, 8)
          FillPath()
          alpha - 15
        Next
        MovePathCursor(60, 60)     
        AddPathCircle(60, 60, 60, 15, angle2, #PB_Path_Connected)
        VectorSourceColor(bColor)
        FillPath()        
        VectorSourceColor(RGBA(0,0,255,alpha2))
        MovePathCursor(40, 50)
        VectorFont(FontID(0), 18)
        DrawVectorText("Busy")                 
        alpha2 - 15 
      StopVectorDrawing()
      If IsGadget(0)
        SetGadgetAttribute(0,#PB_Canvas_Image,ImageID(0))
      EndIf
      Delay(50)                
    Next            
  ForEver
EndProcedure

  If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowColor(0,$E4E4E5)
    bColor = GetWindowColor(0)
    If bColor < 0
      StartDrawing(WindowOutput(0))
        bColor = Point(100,100)
      StopDrawing()
    EndIf
    bColor = bColor | $FF000000
    
    CanvasGadget(0, 140, 120, 120, 120)
    thread = CreateThread(@runCB(),35)
    Repeat
      Select WaitWindowEvent(1)
        Case #PB_Event_CloseWindow
          Quit = 1
          
      EndSelect          
    Until Quit = 1
  EndIf
- Load progress

Code: Select all

Global bColor.q
LoadFont(0, "Consolas", 8, #PB_Font_Bold)  
Procedure runCB(par)
  CreateImage(0,200,200)
  Repeat
    For angle = 361 To 0 Step -15
      StartVectorDrawing(ImageVectorOutput(0))
      VectorSourceColor(bColor)
      FillVectorOutput()
      VectorSourceLinearGradient(-10,100,600,0)
      VectorSourceGradientColor($FF2DD3FE, 0.0)
      VectorSourceGradientColor($FF56FD2C, 0.5)
      MovePathCursor(100, 100)     
      AddPathCircle(100, 100, 75, 0, 360, #PB_Path_Connected)
      FillPath()
      For angle2 = 0 To 360 Step 15
        MovePathCursor(100,100)
        AddPathCircle(100, 100, 90, angle2-2, angle2+2, #PB_Path_Connected)
        VectorSourceColor(bColor)
        FillPath()
      Next
      MovePathCursor(100, 100)     
      AddPathCircle(100, 100, 50, 0, 360, #PB_Path_Connected)
      VectorSourceColor(bColor)
      FillPath()
        MovePathCursor(100, 100)     
        AddPathCircle(100, 100, 90, 0, angle, #PB_Path_Connected)
        VectorSourceColor(bColor)
        FillPath()
        VectorSourceColor($FF0000FF)
        MovePathCursor(56, 90)
        VectorFont(FontID(0), 18)
        DrawVectorText("Load" + RSet(Str(100-(Angle*100/360)),3," ")+" %")
      StopVectorDrawing()
      If IsGadget(0)
        SetGadgetAttribute(0,#PB_Canvas_Image,ImageID(0))
      EndIf
      Delay(200)  
    Next
  ForEver
EndProcedure

  If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowColor(0,$E4E4E5)
    bColor = GetWindowColor(0)
    If bColor < 0
      StartDrawing(WindowOutput(0))
        bColor = Point(100,100)
      StopDrawing()
    EndIf
    bColor = bColor | $FF000000
    
    CanvasGadget(0, 100, 100, 200, 200)
    
    thread = CreateThread(@runCB(),35)
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1          

      EndSelect          
    Until Quit = 1
  EndIf
- Animate In Out

Code: Select all

 Global bColor.q   
Procedure createIMG()
  If CreateImage(0, 200, 200)
    StartVectorDrawing(ImageVectorOutput(0))
      VectorSourceColor(bColor)
      FillVectorOutput()
      VectorSourceLinearGradient(-10,100,600,0)
      VectorSourceGradientColor($FF2DD3FE, 0.0)
      VectorSourceGradientColor($FF56FD2C, 0.5)
      MovePathCursor(100, 100)     
      AddPathCircle(100, 100, 75, 0, 360, #PB_Path_Connected)
      FillPath()
      For angle = 0 To 360 Step 15
        MovePathCursor(100,100)
        AddPathCircle(100, 100, 90, angle-2, angle+2, #PB_Path_Connected)
        VectorSourceColor(bColor)
        FillPath()
      Next
      MovePathCursor(100, 100)     
      AddPathCircle(100, 100, 50, 0, 360, #PB_Path_Connected)
      VectorSourceColor(bColor)
      FillPath()
    StopVectorDrawing()
  EndIf
EndProcedure
 
  LoadFont(0, "Consolas", 8, #PB_Font_Bold)
 
Procedure runCB(par)
CreateImage(1,200,200)
  Repeat
    For Alpha = 0 To 255 Step 10
      StartVectorDrawing(ImageVectorOutput(1))
        VectorSourceColor(bColor)
        FillVectorOutput()
        DrawVectorImage(ImageID(0), Alpha) 
      StopVectorDrawing()
      If IsGadget(0)
        SetGadgetAttribute(0,#PB_Canvas_Image,ImageID(1))
      EndIf
      Delay(200)
    Next
    For Alpha = 255 To 0 Step -10
      StartVectorDrawing(ImageVectorOutput(1))
        VectorSourceColor(bColor)
        FillVectorOutput()
        DrawVectorImage(ImageID(0), Alpha) 
      StopVectorDrawing()
      If IsGadget(0)
        SetGadgetAttribute(0,#PB_Canvas_Image,ImageID(1))
      EndIf
      Delay(200)
    Next
  ForEver
EndProcedure

  If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ;SetWindowColor(0,$E4E4E5)
    bColor = GetWindowColor(0)
    If bColor < 0
      StartDrawing(WindowOutput(0))
        bColor = Point(100,100)
      StopDrawing()
    EndIf
    bColor = bColor | $FF000000
    createIMG()
    CanvasGadget(0, 100, 100, 200, 200)   
   
    thread = CreateThread(@runCB(),35)
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1         

      EndSelect         
    Until Quit = 1
  EndIf
- Searching
RASHAD
Modified by Zebuddi123

Code: Select all

LoadFont(0, "Downtown", 20, #PB_Font_Bold)
Procedure runCB(par)
   Protected sDot.s, iCounter.i, iNbr.i
   CreateImage(0,200,200)
   Repeat
      For angle = 361 To 0 Step -15 : iCounter + 2
        StartVectorDrawing(ImageVectorOutput(0))
         VectorSourceColor($FFF0F0F0)
         FillVectorOutput()
         VectorSourceLinearGradient(-100, 0, 400, 0)
         VectorSourceGradientColor($FF2DD3FE, 0.5)
         MovePathCursor(100, 100)     
         AddPathCircle(100, 100, 88, 0, 360, #PB_Path_Connected)
         FillPath()
         For angle2 = 0 To 360 Step 15
            MovePathCursor(100,100)
            AddPathCircle(100, 100, 90, angle2, angle2+4, #PB_Path_Connected)
            ClosePath()
            VectorSourceColor($FFF0F0F0)
            FillPath()
         Next
         MovePathCursor(100, 100)     
         AddPathCircle(100, 100, 50, 0, 360, #PB_Path_Connected)
         VectorSourceColor($FFF0F0F0)
         FillPath()
         MovePathCursor(100, 100)     
         AddPathCircle(100, 100, 90, 0, angle, #PB_Path_Connected)
         ClosePath()
         VectorSourceColor($FFF0F0F0)
         FillPath()
         VectorSourceColor($FF000000)
         MovePathCursor(58, 90)
         VectorFont(FontID(0), 14)
         ;DrawVectorText("Load % " + Str(100-(Angle*100/360)))
         
         ;Zebuddi----------------------------------
         If iCounter <= 10 : sDot + "."
         ElseIf iCounter=> 12 And iCounter <= 20
            iNbr + 1 :    sDot = Mid(sDot, 1, Len(sDot) - iNbr)
            If iCounter = 20 :    iCounter = 0 : iNbr = 0 : EndIf   
         EndIf
         DrawVectorText("Searching" + sDot )
         ;----------------------------------------
         
         StopVectorDrawing()
         If IsGadget(0)
          SetGadgetAttribute(0,#PB_Canvas_Image,ImageID(0))
         EndIf
         Delay(200)
      Next
   ForEver
EndProcedure

If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   CanvasGadget(0, 100, 100, 200, 200)
   
   thread = CreateThread(@runCB(),35)
   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_CloseWindow
            Quit = 1         
            
      EndSelect         
   Until Quit = 1
EndIf
Edit :Modified
Egypt my love
Post Reply