PureBasic Forum
https://www.purebasic.fr/english/

Bezier curve generator
https://www.purebasic.fr/english/viewtopic.php?f=16&t=72318
Page 1 of 1

Author:  Papala [ Wed Feb 20, 2019 3:06 pm ]
Post subject:  Bezier curve generator

If some need...
Code:
InitSprite()
Global p1.f = 0, p2.f = 0.33, p3.f = 0.66, p4.f = 1, Duration, time

Procedure Bezier(t.f,d,Target)
  t = t/d
  Result = Pow(1-t,3)*(Target*P1) + 3*Pow(1-t,2)*t*(Target*P2)+ 3*(1-t)*Pow(t,2)*(Target*P3) + Pow(t,3)*(Target*P4)
  ProcedureReturn Result
EndProcedure

Procedure Play()
  p2 = Val(GetGadgetText(0))/100
  p3 = Val(GetGadgetText(1))/100
  Duration = Val(GetGadgetText(2))
  time = ElapsedMilliseconds()
EndProcedure

OpenWindow(0,0,0,800,400,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,600,400)
CreateSprite(0,30,30)
StartDrawing(SpriteOutput(0))
Box(0,0,30,30,#Red)
StopDrawing()
StringGadget(0,700,10,80,20,"33",#PB_String_Numeric)
StringGadget(1,700,50,80,20,"66",#PB_String_Numeric)
StringGadget(2,700,80,80,20,"500",#PB_String_Numeric)
TextGadget(#PB_Any,600,10,80,20,"P1 : ")
TextGadget(#PB_Any,600,50,80,20,"P2 : ")
TextGadget(#PB_Any,600,80,80,20,"Time : ")
ButtonGadget(4,700,150,80,20,"Play")
BindGadgetEvent(4,@Play())
Repeat
  ClearScreen(0)
  If ElapsedMilliseconds()-time < Duration
    DisplaySprite(0,Bezier(ElapsedMilliseconds()-time,Duration,500),100)
  Else
    DisplaySprite(0,500,100)
  EndIf
  FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow


Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/