Page 1 of 1

Funny Vectordrawing ClipPath

Posted: Sun Jul 11, 2021 9:32 am
by [blendman]
HI

It's just for the fun, the vectordrawing library is so cool :)

Code: Select all

Procedure DrawPathCircle(x,y,size,r,g,b,a,line=0)
  AddPathCircle(x,y,size)
  VectorSourceColor(RGBA(r,g,b, a))
  If line=0
    FillPath()
  Else
    StrokePath(line)
  EndIf
EndProcedure
Procedure CreateHead(x.f,y.f,s,r,g,b)
  ; shadow
  a = s*0.1875 ; 15
  b= s/2       ;40
  DrawPathCircle(x+a,y+a,s,0,0,0,100)
  VectorSourceCircularGradient(x+a,y+a,s) 
  VectorSourceGradientColor(RGBA(0,0,0,250),0.5)
  VectorSourceGradientColor(RGBA(0,0,0,0),1)
  AddPathCircle(x+a,y+a,s)
  FillPath()
  ; drawing skin
  DrawPathCircle(x,y,s,r,g,b,255)
  ; white eye
  ;  DrawPathCircle(x,y,s-1,240,240,240,150)
  SaveVectorState()
  AddPathCircle(x,y,s)
  ClipPath()
  
  ; draw inside the circle
  DrawPathCircle(x-15,y-5,s,255,255,255,50)
  ; diffuse light
  VectorSourceCircularGradient(x-b,y-b,s) 
  VectorSourceGradientColor(RGBA(255,255,255,150),0)
  VectorSourceGradientColor(RGBA(255,255,255,0),1)
  AddPathCircle(x-b,y-b,s)
  FillPath()
  ; specular light
  DrawPathCircle(x-b,y-b,30,255,255,255,10)
  
  ; mouth
  ;AddPathCurve(x+s*0.5,y+s*0.5,x+s*0.6,y+s*0.8,x+s*0.5,y+s*0.5)
  MovePathCursor(x-S*0.3, y+s*0.5)
  AddPathCurve(x+0.3,y+s*0.8,x+s*0.5,y+s*0.5,x+s*0.4,y+s*0.4)
   VectorSourceColor(RGBA(0,0,0,255))
  StrokePath(s*0.02)
  RestoreVectorState()
EndProcedure
Procedure CreateEye(x.f,y.f,x1.d,y1.d,s)
  ; shadow
  a = s*0.1875 ; 15
  b= s/2       ;40
  DrawPathCircle(x+a,y+a,s,0,0,0,100)
  VectorSourceCircularGradient(x+a,y+a,s) 
  VectorSourceGradientColor(RGBA(0,0,0,250),0.5)
  VectorSourceGradientColor(RGBA(0,0,0,0),1)
  AddPathCircle(x+a,y+a,s)
  FillPath()
  ; drawing
  DrawPathCircle(x,y,s,110,120,80,255)
  ; white eye
  DrawPathCircle(x,y,s-1,240,240,240,150)
  SaveVectorState()
  AddPathCircle(x,y,s)
  ClipPath()
  
  ; draw inside the circle
  DrawPathCircle(x-15,y-5,s,255,255,255,50)
  ; diffuse light
  VectorSourceCircularGradient(x-b,y-b,s) 
  VectorSourceGradientColor(RGBA(255,255,255,250),0)
  VectorSourceGradientColor(RGBA(255,255,255,0),1)
  AddPathCircle(x-b,y-b,s)
  FillPath()
  ; specular light
  DrawPathCircle(x-b,y-b,10,255,255,255,200)
  ; black iris
  DrawPathCircle(x+x1,y+y1,10,0,0,0,255)
  RestoreVectorState()
EndProcedure
Procedure DrawCanvas()
  Static x.d, y.d, direction
 
  w = WindowWidth(0)
  h = WindowHeight(0)
  size = 60 ; eye
  sizeBody = 180
  ; max & min for movements
  maxX = size*0.5
  minX = -size*0.7
  maxY = size*0.5
  minY = -size*0.7
  
  y1 =h/2-30
  
  If StartVectorDrawing(CanvasVectorOutput(0))
    If EventType() = #PB_EventType_MouseMove 
       x = GetGadgetAttribute(0, #PB_Canvas_MouseX)-(w/2+size/2)
       y = GetGadgetAttribute(0, #PB_Canvas_MouseY)-(h/2+size/2)
    EndIf
    
    AddPathBox(0,0,w,h)
    VectorSourceColor(RGBA(255,255,255,255))
    FillPath()
    
    MovePathCursor(0, 0)
    ; automatic move in X
    ;     If x<-size*0.8
    ;       direction=1
    ;     ElseIf x > 0
    ;       direction =-1
    ;     ElseIf x=0 And direction =0 
    ;       direction =1
    ;     EndIf
    ;     x+direction*0.5
    
    ; move the eyes by mouse
    If x > maxX
      x= maxX
    ElseIf  x<minX
     x =minX
   EndIf 
   If y > maxY
      y= maxY
    ElseIf  y<minY
     y =minY
    EndIf
    CreateHead(w/2,y1,sizeBody,100,120,240)
    CreateEye(w/2-90,y1,x,y,size)
    CreateEye(w/2,y1,x,y,size)
    CreateEye(w/2+90,y1,x,y,size)
    StopVectorDrawing()
  EndIf
EndProcedure

w=600
h=300
If OpenWindow(0, 0, 0, w, h, "Funny VectorDrawing clipping", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, w, h)
  Repeat
    Event = WaitWindowEvent(1)
    DrawCanvas()
  Until Event = #PB_Event_CloseWindow
EndIf
Cheers :)

Re: Funny Vectordrawing ClipPath

Posted: Sun Jul 11, 2021 9:39 am
by Mijikai
Thats cool 8)
Nice XD

Re: Funny Vectordrawing ClipPath

Posted: Sun Jul 11, 2021 10:53 am
by Denis
He he, pas mal!

Re: Funny Vectordrawing ClipPath

Posted: Sun Jul 11, 2021 5:59 pm
by Kwai chang caine
Nice !!! this Tchernobyl man :mrgreen:
Thanks for sharing 8)

Re: Funny Vectordrawing ClipPath

Posted: Sun Jul 11, 2021 7:31 pm
by davido
@blendman,
Nice one! :D