Bezeir Curve Maker

Community Forums/Showcase/Bezeir Curve Maker

Matt McFarland(Posted 2005) [#1]
Strict

Graphics 1024,768,32
SetBlend LIGHTBLEND
Global x1:Int=540   'pount 0  
Global y1:Int=125   'point 0
Global vx1:Int=200  '1  
Global vy1:Int=350  '1   
Global x2:Int=420   '2 
Global y2:Int=670   '2  
Global vx2:Int=700  '3   
Global vy2:Int=350  '3
Global StepSetting = .1
Global counter=0
Global point:Int=0
Global MouseWas
Global GridPlot
Global Gridy
Global swap_x1=x1
Global swap_x2=x2
Global swap_vx1=vx1
Global swap_vx2=vx2
Global swap_y1	=	y1
Global swap_y2	=	y2
Global swap_vy1	=	vy1
Global swap_vy2	=	vy2


Repeat
	Cls
	SetColor 130,130,140
	DrawLine 100,100,100,700
	DrawLine 100,100,800,100
	DrawLine 800,100,800,700
	DrawLine 800,700,100,700

	DrawLine 800,100,900,100
	DrawLine 800,700,900,700
	DrawLine 900,100,900,700
	
	SetColor 90,90,100
	For GridY= 1 To 18
		For GridPlot = 1 To 21
			Plot (GridPlot*32)+100,(GridY*32)+100
		Next
	Next
	SetColor 215,215,215
	Keys()
	
	drawbezier (x1,y1,vx1,vy1,x2,y2,vx2,vy2)

	SetColor 200,200,200
	DrawText "mouse:    "+(MouseX()-100)+","+(MouseY()-100),0,40
	SetColor 200,200,200
	DrawText "(R)everse (M)irror (F)lip (L)oop",0,70
	DrawText "Mouse Wheel Changes Selection - [W][A][S][D] and RIGHT MOUSE move point",250,15

	If point=0 Then SetColor 255,255,0 Else SetColor 200,200,200
	DrawText "p0 coord: "+(x1-100)+","+(y1-100)+" - Start",0,0
	DrawText "0 - Start",x1-2,y1-2
	If MouseDown(2) And point=0 Then 
	       x1=MouseX()
	       y1=MouseY()
	EndIf




	If point=1 Then SetColor 255,255,0 Else SetColor 200,200,200
	DrawText "p1 coord: "+(vx1-100)+","+(vy1-100),0,10
	DrawText "1",vx1-2,vy1-2
	If MouseDown(2) And point=1 Then 
		vx1=MouseX()
	    vy1=MouseY()
	EndIf
	If point=2 Then SetColor 255,255,0 Else SetColor 200,200,200
	DrawText "p2 coord: "+(x2-100)+","+(y2-100)+" - Finish",0,20
	DrawText "2 - Finish",x2-2,y2-2
	If MouseDown(2) And point=2 Then 
       x2=MouseX()
       y2=MouseY()
	EndIf
	If point=3 Then SetColor 255,255,0 Else SetColor 200,200,200
	DrawText "p3 coord: "+(vx2-100)+","+(vy2-100),0,30

	DrawText "3",vx2-2,vy2-2
	If MouseDown(2) And point=3 Then 
		vx2=MouseX()
		vy2=MouseY()
	EndIf
	SetColor 255,255,255
	
	If MouseZ() < MouseWas Then 	point=(point+1) Mod 4
	If MouseZ() > MouseWas Then 	point=(point-1) Mod 4
	If point = -1 point = 3 ; 	If point = 4 Then point = 0
	MouseWas = MouseZ()
	Flip
	FlushMem
	
Until KeyDown(KEY_ESCAPE)

End


Function drawbezier (x1,y1,vx1,vy1,x2,y2,vx2,vy2)
	counter = 0
	SetColor 50,50,100
	DrawLine x1,y1,vx1,vy1
	DrawLine x2,y2,vx2,vy2

	SetColor 255,50,50
	For Local t:Float=0 To 1 Step .001
		counter:+1
		Local pointx:Float = x1*(1-t)^3 + 3*vx1*(1-t)^2*t + 3*vx2*(1-t)*t^2 + x2*t^3
		Local pointy:Float = y1*(1-t)^3 + 3*vy1*(1-t)^2*t + 3*vy2*(1-t)*t^2 + y2*t^3
		SetColor t*10,00,00
		DrawRect pointx,pointy,2,2

		SetColor t*1000,t*90,t*90
		Plot pointx,pointy
		If Counter = Rnd(20,90)
			SetColor 50,50,255
			Plot pointx,pointy
		Counter = 0
		EndIf
	Next
End Function

Function Keys()
	If KeyHit(Key_S) 	
		If  point = 0 	Then y1:+1
		If  Point = 1 	Then vy1:+1
		If  Point = 2 	Then y2:+1
		If  Point = 3 	Then vy2:+1
	EndIf
	If KeyHit(Key_W) 	
		If  Point = 0 	Then y1:-1
		If  Point = 1 	Then vy1:-1
		If  Point = 2 	Then y2:-1
		If  Point = 3 	Then vy2:-1
	EndIf
	If KeyHit(Key_A) 	
		If  Point = 0 	Then x1:-1
		If  Point = 1 	Then vx1:-1
		If  Point = 2 	Then x2:-1
		If  Point = 3 	Then vx2:-1
	EndIf
	If KeyHit(Key_D) 	
		If  Point = 0 	Then x1:+1
		If  Point = 1 	Then vx1:+1
		If  Point = 2 	Then x2:+1
		If  Point = 3 	Then vx2:+1
	EndIf

	If KeyHit (Key_M)
		swap_x1		=	x1
		swap_x2		=	x2
		swap_vx1	=	vx1
		swap_vx2	=	vx2

		x1	=	swap_x2
		vx1	=	swap_vx2
		x2	=	swap_x1
		vx2	=	swap_vx1
	EndIf

	If KeyHit (Key_F)
		swap_y1		=	y1
		swap_y2		=	y2
		swap_vy1	=	vy1
		swap_vy2	=	vy2

		swap_x1		=	x1
		swap_x2		=	x2
		swap_vx1	=	vx1
		swap_vx2	=	vx2

		y1	=	swap_y2
		vy1	=	swap_vy2
		y2	=	swap_y1
		vy2	=	swap_vy1
	EndIf

	If KeyHit (Key_R)
		swap_y1		=	y1
		swap_y2		=	y2
		swap_vy1	=	vy1
		swap_vy2	=	vy2

		swap_x1		=	x1
		swap_x2		=	x2
		swap_vx1	=	vx1
		swap_vx2	=	vx2

		x1	=	swap_x2
		vx1	=	swap_vx2
		x2	=	swap_x1
		vx2	=	swap_vx1
		y1	=	swap_y2
		vy1	=	swap_vy2
		y2	=	swap_y1
		vy2	=	swap_vy1
	EndIf

	If KeyHit (Key_L)
		swap_y1		=	y1
		swap_y2		=	y2
		swap_vy1	=	vy1
		swap_vy2	=	vy2

		swap_x1		=	x1
		swap_x2		=	x2
		swap_vx1	=	vx1
		swap_vx2	=	vx2

		y1	=	swap_y2
		vy1	=	swap_vy1
		x1	=	swap_x2
		vx1	=	swap_vx2
		vx2	=	swap_vx1
		vy2	=	swap_vy1
	EndIf
	
EndFunction


This program will allow you to create bezier curves for any game that has an 800x600 resolution. (The editor is 1024x768 so you can see the entire game-field)

You can then write down the curve data it gives you. It is very flexible and has options like:

Mirror - Flips the Curve path horizontally
Flip - Flips the Curve path Vertically
Reverse - Swaps the Start and Finish point
Loop - Makeas the Curve start and finish at same point for "Loop" effect

I plan on building on it and adding more options, please share your feedback / modifications with me so we can make a great bezier curve maker!