Posted: 10th Dec 2002 7:38
+ Code Snippet
dim BCurv(250,6)

BCurv(0,0)=100
BCurv(1,0)=200
BCurv(2,0)=1

BCurv(3,0)=150
BCurv(4,0)=50
BCurv(5,0)=0

BCurv(6,0)=200
BCurv(7,0)=400
BCurv(8,0)=0

BCurv(9,0)=250
BCurv(10,0)=50
BCurv(11,0)=0

BCurv(12,0)=300
BCurv(13,0)=200
BCurv(14,0)=0

BCurv(15,0)=350
BCurv(16,0)=50
BCurv(17,0)=1

DrawCurv()

do
sync
loop

end

Function DrawCurv()
C=1:D=0
VORB:
A=0:B=0:LX=BCurv(A,D):LY=BCurv(A+1,D):LM=0
BCurv(B,C)=LX:BCurv(B+1,C)=LY:BCurv(B+2,C)=1:INC B,3
while LM1
`Circle LX,LY,5
INC A,3
X=BCurv(A,D):Y=BCurv(A+1,D):M=BCurv(A+2,D)
if C=6 then Line LX,LY,X,Y
X2=LineSegX(LX,X):Y2=LineSegY(LY,Y)
BCurv(B,C)=X2:BCurv(B+1,C)=Y2:BCurv(B+2,C)=0:INC B,3
LX=X:LY=Y:LM=M
endwhile
BCurv(B,C)=X:BCurv(B+1,C)=Y:BCurv(B+2,C)=1
ink RGB(255,255,255),0:INC C,1:INC D,1:IF C7 then goto VORB
endfunction



Function LineSegY(Y,Y2)
if y>y2 then a=y:y=y2:y2=a
Y3=((Y2-Y)/2)+Y
endfunction Y3

Function LineSegX(X,X2)
if x>x2 then a=x:x=x2:x2=a
X3=((X2-X)/2)+X
endfunction X3
Posted: 13th Dec 2002 5:55
when I run it I dont see anything
Posted: 13th Dec 2002 7:48
See where it says if C&? its suppost to be if C=7 =P thank the message board
Posted: 13th Dec 2002 7:49
Grr agian the message board "C7" is suppost to be C=7
Posted: 14th Dec 2002 1:09
still nothing!
Posted: 15th Dec 2002 2:15
Darn it! what the hey!

OINE LAST TRY.. BTW This looks really crappy in DBPRO its the same result just it looks REALLY bad all the 2d dose.."

+ Code Snippet
dim BCurv(250,8)

BCurv(0,0)=10:BCurv(1,0)=300:BCurv(2,0)=1

BCurv(3,0)=100:BCurv(4,0)=100:BCurv(5,0)=0

BCurv(6,0)=200:BCurv(7,0)=10:BCurv(8,0)=0

BCurv(9,0)=250:BCurv(10,0)=50:BCurv(11,0)=0

BCurv(12,0)=300:BCurv(13,0)=200:BCurv(14,0)=0

BCurv(15,0)=350:BCurv(16,0)=250:BCurv(17,0)=0

BCurv(18,0)=500:BCurv(19,0)=40:BCurv(20,0)=1

DrawCurv()
print "done"

do
sync
loop

end

`Remove reminder marks to show how it works
Function DrawCurv()
C=1:D=0:Ink RGB(0,0,255),0
VORB:
A=0:B=0:LX=BCurv(A,D):LY=BCurv(A+1,D):LM=0
BCurv(B,C)=LX:BCurv(B+1,C)=LY:BCurv(B+2,C)=1:INC B,3
while LM<>1
ink rgb(255,0,0),0:Circle LX,LY,5
INC A,3
X=BCurv(A,D):Y=BCurv(A+1,D):M=BCurv(A+2,D)
Ink RGB(0,0,255),0:Line LX,LY,X,Y:Circle LX,LY,5:Circle X,Y,5
if C=8 then ink rgb(255,255,0),0:Line LX,LY,X,Y
X2=LineSegX(LX,X):Y2=LineSegY(LY,Y)
BCurv(B,C)=X2:BCurv(B+1,C)=Y2:BCurv(B+2,C)=0:INC B,3
LX=X:LY=Y:LM=M
endwhile
BCurv(B,C)=X:BCurv(B+1,C)=Y:BCurv(B+2,C)=1
ink RGB(255,255,255),0:INC C,1:INC D,1:IF C<>9 then goto VORB
endfunction

Function LineSegY(Y,Y2)
if y>y2 then a=y:y=y2:y2=a
Y3=((Y2-Y)/2)+Y
endfunction Y3

Function LineSegX(X,X2)
if x>x2 then a=x:x=x2:x2=a
X3=((X2-X)/2)+X
endfunction X3
Posted: 15th Dec 2002 17:48
it looks better when you turn the resoloution up, heres my take on the bezier curves(I use 1024x768 res and DBpro):-

+ Code Snippet
Rem Project: bezier-curved!
Rem Created: 15/12/2002 12:31:20

Rem ***** Main Source File *****

rem Standard Setup Code
sync on : sync rate 0
color backdrop rgb(0,0,128)
set text font "arial" : set text size 14 : set text transparent

rem number of lines to make up spline
linenumber=50

rem step value
step#=1.0/linenumber

rem create storage for variables
type cubic X as float Y as float endtype
dim spline(linenumber) as cubic
dim control(4) as cubic
dim distance(4)

gosub Setup_controls
gosub Create_spline_data
gosub Show_controls
gosub Show_spline

rem view loop
do
if mouseclick()=1
   if selected=1
   control(min).X=mousex()
   control(min).Y=mousey()
   else
      gosub Distance_check
   endif
   cls
   gosub Show_controls
   gosub Create_spline_data
   gosub Show_spline
else
selected=0
endif

text 0, 0, "Use mouse to move points around"
text 0, 15, "FPS: " + str$(screen fps())
sync
loop



Create_spline_data:
rem setup important values
a#=0.0
b#=1.0

rem generate bezier curve data
for m=0 to linenumber
if m > 0
   a# = a# + step#
   b# = b# - step#
endif
   spline(m).X = (control(1).X * a#^3) + (control(2).X * 3 * a#^2 * b#) + (control(3).X * 3 * a# * b#^2) + (control(4).X * b#^3)
   spline(m).Y = (control(1).Y * a#^3) + (control(2).Y * 3 * a#^2 * b#) + (control(3).Y * 3 * a# * b#^2) + (control(4).Y * b#^3)
next m

return


Show_spline:
rem show cubic spline
ink rgb(255,255,255), rgb(0,0,128)
for m=0 to linenumber-1
   line spline(m).X, spline(m).Y, spline(m+1).X, spline(m+1).Y
next m
return



Show_controls:
rem show control points
ink rgb(255,255,0), rgb(0,0,128)
box control(1).X-5.0, control(1).Y-5.0, control(1).X+5.0, control(1).Y+5.0
box control(4).X-5.0, control(4).Y-5.0, control(4).X+5.0, control(4).Y+5.0
ink rgb(255,0,0), rgb(0,0,128)
box control(2).X-5.0, control(2).Y-5.0, control(2).X+5.0, control(2).Y+5.0
box control(3).X-5.0, control(3).Y-5.0, control(3).X+5.0, control(3).Y+5.0
return


Setup_controls:
control(1).X=60.0 : control(1).Y=100.0
control(2).X=200.0 : control(2).Y=0.0
control(3).X=210.0 : control(3).Y=455.0
control(4).X=400.0 : control(4).Y=400.0
return


Distance_check:
X#=mousex() : Y#=mousey()
for n=1 to 4
   distance(n)=SQRT((X#- control(n).X)^2 + (Y#- control(n).Y)^2)
next n

if distance(1)<distance(2) and distance(1)<distance(3) and distance(1)<distance(4) then min=1
if distance(2)<distance(1) and distance(2)<distance(3) and distance(2)<distance(4) then min=2
if distance(3)<distance(2) and distance(3)<distance(1) and distance(3)<distance(4) then min=3
if distance(4)<distance(2) and distance(4)<distance(3) and distance(4)<distance(1) then min=4

if distance(min)<5 then selected=1
return