Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Applying differential to tangent line ( you can use it to angle of character on a hill )

Author
Message
puppysss
17
Years of Service
User Offline
Joined: 13th Mar 2007
Location: UnCyber Space
Posted: 11th Jun 2012 16:47
rem Applying differential to tangent line by puppysss
rem various settings
backdrop on
box 0,0,10,50
get image 1,0,0,10,50
cls

rem main loop
do
rem draw parabola line and circle
for x = 0 to 800
line x , f(x) , x+1 , f(x+1)
next x
circle mousex() , f(mousex()), 5

rem get equation of tangent line
equ1 = fprime(mousex())*( (mousex()-500) - mousex() ) + f(mousex())
equ2 = fprime(mousex())*( (mousex()+500) - mousex() ) + f(mousex())

rem draw tangent line
line mousex()-500 , equ1 , mousex()+500 , equ2

rem draw sprite and rotate
sprite 1,mousex(),f(mousex()),1
offset sprite 1 ,0,50
rotate sprite 1 , atan(fprime(mousex()))
loop

rem original line function
function f(x)
y = (x-250)^2/1000 + 250
endfunction y

rem differential function
function fprime(x#)
y# = (x#-250)/500
endfunction y#

Knowledge Is Well-Known Wisdom.
So Wisdom Is Very Absolute.

Login to post a reply

Server time is: 2024-03-29 06:33:01
Your offset time is: 2024-03-29 06:33:01