d.j.peters
Nombre de messages : 77 Age : 60 Localisation : Germany Date d'inscription : 31/07/2010
| Sujet: numérique : Courbe de Bézier Jeu 19 Aoû 2010 - 14:14 | |
| http://fr.wikipedia.org/wiki/Courbe_de_B%C3%A9zierDJ - Code:
-
' based on idea of an cubic spline ' X = x0*(1-u)^3 + x1*3*u*(1-u)^2 + x2*3*u^2*(1-u) + x3*u^3 ' Y = y0*(1-u)^3 + y1*3*u*(1-u)^2 + y2*3*u^2*(1-u) + y3*u^3
' code label Resize,Draw,SetBars ' events label TimerEvent,hBarChange,vBarChange label OptionClick0,OptionClick1,OptionClick2,OptionClick3
' objects dim frmMain%:frmMain% = 0 dim picMain%:picMain% = 1 dim tmrMain%:tmrMain% = 2 dim grpOptions%:grpOptions% = 3 dim optP%(3),hBar%,vBar%
' vars dim OldWidth% ,OldHeight% dim FormWidth% ,FormHeight% dim ClientWidth%,ClientHeight% dim i%,id%,CurrentPoint% dim u,xx,yy dim x01,y01 ,x12,y12 ,x23,y23 dim xd10,yd10,xd21,yd21,xd32,yd32 dim x(3),y(3),xd(2),yd(2)
caption frmMain%,"Cubic Spline"
picture picMain% full_space picMain% 2d_target_is picMain% print_target_is picMain% 2d_clear
container_option grpOptions%:caption grpOptions%,"Move:" for i%=0 to 3 id%=grpOptions%+1+i%:optP%(i%)=id% option id%:parent id%,grpOptions%:caption id%,"Point " + str$(i%) next i% mark_on optP%(0)
hBar%=grpOptions%+5 track_bar hBar%:horizontal hBar% vBar%=hBar%+1 track_bar vBar%:vertical vBar%
gosub Resize
x(0)= 10 :y(0)= 10 x(1)= 20 :y(1)= height(picMain%)-30 x(2)= width(picMain%)-40:y(2)= height(picMain%)-30 x(3)= width(picMain%)-20:y(3)= 10
position hBar%,x(CurrentPoint%)*0.1 position vBar%,y(CurrentPoint%)*0.1
timer tmrMain% timer_interval tmrMain%,100
' events on_click optP%(0),OptionClick0 on_click optP%(1),OptionClick1 on_click optP%(2),OptionClick2 on_click optP%(3),OptionClick3 on_change hBar%,hBarChange on_change vBar%,vBarChange on_timer tmrMain%,TimerEvent
timer_on tmrMain%
' go in main eventloop end
' get client width and height of FORM frmMain% ' don't allow a window shorter then 320x200 Resize: full_space picMain% ClientWidth% = width(picMain%) while ClientWidth%<320 FormWidth% = FormWidth%+1 width frmMain%,FormWidth% full_space picMain% ClientWidth% = width(picMain%) end_while left picMain%,0:width picMain%,ClientWidth%-48 OldWidth%=FormWidth%
ClientHeight% = height(picMain%) while ClientHeight%<200 FormHeight% = FormHeight%+1 height frmMain%,FormHeight% full_space picMain% ClientHeight% = height(picMain%) end_while height picMain%,ClientHeight%-106 OldHeight%=FormHeight%
' bars left vBar%,ClientWidth%-48:top vBar%,0:height vBar%,height(picMain%) min vBar%,0:max vBar%,height(picMain%)*0.1 left hBar%,0:top hBar%,height(picMain%):width hBar%,width(picMain%) min hBar%,0:max hBar%,width(picMain%)*0.1 ' options top grpOptions%,height(picMain%)+48 width grpOptions%,width(picMain%) height grpOptions%,52 for i%=0 to 3 id%=optP%(i%) left id%,10+i%*60:top id%,16:width id%,60 next i% return
Draw: ' get deltas from current points for i%=0 to 2 xd(i%)=x(i%+1)-x(i%):yd(i%)=y(i%+1)-y(i%) next i%
2d_clear ' draw the text of the 4 points for i% = 0 to 3 print_locate x(i%),y(i%):print "P"+str$(i%) next i% ' draw the 4 points via lines 2d_pen_color 0,0,168 2d_pen_width 2 2d_poly_from x(0),y(0) for i% = 1 to 3 2d_poly_to x(i%),y(i%) next i% ' draw the cubic spline 2d_pen_color 0,168,0 2d_poly_from x(0),y(0) for u=0 to 1 step 0.01 x01 = x(0)+u*xd(0) : y01 = y(0)+u*yd(0) x12 = x(1)+u*xd(1) : y12 = y(1)+u*yd(1) x23 = x(2)+u*xd(2) : y23 = y(2)+u*yd(2) x01 = x01+u*(x12-x01): y01 = y01+u*(y12-y01) x12 = x12+u*(x23-x12): y12 = y12+u*(y23-y12) xx = x01+u*(x12-x01): yy = y01+u*(y12-y01) 2d_poly_to xx,yy next u return
' events TimerEvent: FormWidth% = width(frmMain%) FormHeight% = height(frmMain%) if (FormWidth%<>OldWidth%) or (FormHeight%<>OldHeight%) gosub Resize gosub Draw end_if return
OptionClick0: CurrentPoint%=0:goto SetBars OptionClick1: CurrentPoint%=1:goto SetBars OptionClick2: CurrentPoint%=2:goto SetBars OptionClick3: CurrentPoint%=3:goto SetBars
hBarChange: x(CurrentPoint%)=position(hBar%)*10:goto Draw vBarChange: y(CurrentPoint%)=position(vBar%)*10:goto Draw
SetBars: position hBar%,x(CurrentPoint%)*0.1 position vBar%,y(CurrentPoint%)*0.1 return
Dernière édition par d.j.peters le Jeu 19 Aoû 2010 - 15:54, édité 2 fois | |
|
Invité Invité
| Sujet: Re: numérique : Courbe de Bézier Jeu 19 Aoû 2010 - 15:07 | |
| Very good!!! |
|
jjn4
Nombre de messages : 2747 Date d'inscription : 13/09/2009
| Sujet: +++ Jeu 19 Aoû 2010 - 23:46 | |
| Super, voilà de belles mathématiques ! | |
|
Contenu sponsorisé
| Sujet: Re: numérique : Courbe de Bézier | |
| |
|