Code: Select all
; SDF Heart shape - PJ102023 - derived from IQ code @ https://www.shadertoy.com/view/dljyDc
EnableExplicit
Procedure.f sdHeart(x.f,y.f)
Static a.f, b.f, c.f : y + 0.5 : y = 1.0 - y : x = Abs(x)
If x + y > 1.0 : ProcedureReturn Sqr((x - 0.25) * (x - 0.25) + (y - 0.75) * (y - 0.75)) - 0.35355 : Else
c = x + y : If c < 0 : c = 0.0 : EndIf
a = x * x + (y - 1.0) * (y - 1.0) : b = (x - 0.5 * c) * (x - 0.5 * c) + (y - 0.5 * c) * (y - 0.5 * c)
If a < b : ProcedureReturn Sqr(a) * Sign(x-y) : Else : ProcedureReturn Sqr(b) * Sign(x-y) : EndIf
EndIf
EndProcedure
OpenWindow(0,0,0,640,480,"Circling the heart",#PB_Window_Maximize|#PB_Window_BorderLess) : AddWindowTimer(0,0,25)
Define.f w = WindowWidth(0), h = WindowHeight(0), hw = w / 2, hh = h / 2, x, y, p, sz, c.i, frame
CanvasGadget(0,0,0,w,h,#PB_Canvas_Keyboard) : SetActiveGadget(0)
StartVectorDrawing(CanvasVectorOutput(0)) : VectorSourceColor(RGBA(230,230,230,255)) : FillVectorOutput() : StopVectorDrawing()
Repeat
Select WaitWindowEvent(25)
Case #PB_Event_CloseWindow : End
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_LeftButtonDown : End
Case #PB_EventType_KeyDown : End
EndSelect
Case #PB_Event_Timer
frame + 1
StartVectorDrawing(CanvasVectorOutput(0))
ScaleCoordinates(DesktopResolutionX(),DesktopResolutionY())
Select frame
Case 0 To 250
For c = 1 To 10
x = Random(w) : y = Random(h) : p.f = sdHeart((x - hw) / hh, (y - hh) / hh) * hh
If p < 0 : VectorSourceColor(RGBA(150,20,10,45)) : sz = 1.5 : Else : VectorSourceColor(RGBA(20,20,70,30)) : sz = 1.5 : EndIf
p = Abs(p) : AddPathCircle(x,y,p) : StrokePath(sz)
Next
Case 250 To 350
Case 350 To 400 : VectorSourceColor(RGBA(230,230,230,25)) : FillVectorOutput()
Case 401 : Frame = 1
EndSelect
StopVectorDrawing()
EndSelect
ForEver