Draw Inside any Path

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

Draw Inside any Path

Post by RASHAD »

Hi
#1 :

Code: Select all

Procedure Draw()    
  x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If StartVectorDrawing(CanvasVectorOutput(0))      
    AddPathCircle(300, 300, 250)
    If IsInsidePath(x, y, #PB_Coordinate_Device)
      If StartDrawing(CanvasOutput(0))
        Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
        StopDrawing()
      EndIf
    EndIf 
    StopVectorDrawing()
  EndIf      
EndProcedure

If OpenWindow(0, 0, 0, 600, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 600, 600)
  If StartVectorDrawing(CanvasVectorOutput(0))
    AddPathCircle(300, 300, 250)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(2)
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget And EventGadget() = 0 
      If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
        draw()
      EndIf
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
  
EndIf


#2 :

Code: Select all

Procedure Draw()    
  x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If StartVectorDrawing(CanvasVectorOutput(0))      
    AddPathEllipse(200, 100, 150, 75)
    If IsInsidePath(x, y, #PB_Coordinate_Device)
      If StartDrawing(CanvasOutput(0))
        Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
        StopDrawing()
      EndIf
    EndIf 
    StopVectorDrawing()
  EndIf      
EndProcedure

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 400, 200)
  If StartVectorDrawing(CanvasVectorOutput(0))
    AddPathEllipse(200, 100, 150, 75)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(2)
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget And EventGadget() = 0 
      If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
        draw()
      EndIf
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
  
EndIf

Egypt my love
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Draw Inside any Path

Post by STARGÅTE »

This is the first time I've seen code using StartDrawing in an open StartVectorDrawing block.
It seems to work, but I wonder that it works.
But what is the intention of using normal drawing inside a vector drawing scene?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Draw Inside any Path

Post by RASHAD »

Hi STARGÅTE
I do that most of the time :)
But no problem

Code: Select all

Global flag

Procedure Draw()    
  x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
  If StartVectorDrawing(CanvasVectorOutput(0))      
    AddPathCircle(300, 300, 250)
    If IsInsidePath(x, y, #PB_Coordinate_Device)
      flag = 1
    Else
      flag = 0
    EndIf 
    StopVectorDrawing()
  EndIf
  If flag = 1
    StartDrawing(CanvasOutput(0))
    Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
    StopDrawing()
  EndIf     
EndProcedure

If OpenWindow(0, 0, 0, 600, 600, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 600, 600)
  If StartVectorDrawing(CanvasVectorOutput(0))
    AddPathCircle(300, 300, 250)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(2)
    StopVectorDrawing()
  EndIf
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget And EventGadget() = 0 
      If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
        draw()
      EndIf
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
  
EndIf

Egypt my love
Post Reply