It is currently Tue Dec 10, 2019 3:03 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Bezier curve generator
PostPosted: Wed Feb 20, 2019 3:06 pm 
Offline
User
User

Joined: Wed Sep 12, 2012 5:09 pm
Posts: 38
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



Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye