Page 1 of 1

Filled bezier shape?

Posted: Sat May 17, 2008 7:17 pm
by Trond
Is it possible to draw a filled bezier shape (like PolyBezier_() api but filled) without brute force filling it with FillArea()? I am totally stumped in every single way possible. I do not even know how to draw a non-filled one...

Posted: Sat May 17, 2008 10:04 pm
by Derek
A bit rough but it works. :wink:

Code: Select all

OpenWindow(0,0,0,800,600,"",$ca0001) 
InitSprite() 
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0) 

*points=AllocateMemory(2*4*4) 
PokeL(*points,100);start 
PokeL(*points+4,100) 

PokeL(*points+8,300);control 
PokeL(*points+12,20) 

PokeL(*points+16,500);control 
PokeL(*points+20,580) 

PokeL(*points+24,700);end 
PokeL(*points+28,500) 
hdc=StartDrawing(ScreenOutput()) 

FrontColor(#White)
BeginPath_(hdc) 
PolyBezier_(hdc,*points,4) 
MoveToEx_(hdc,100,100,*points)
LineTo_(hdc,700,500)
SetPolyFillMode_(hdc,#ALTERNATE)
EndPath_(hdc)
FillPath_(hdc)
StopDrawing() 

Repeat 
Until WaitWindowEvent()=16 

Posted: Sat May 17, 2008 10:05 pm
by Trond
I'm interested in the algorithm behind it, so API won't work. :wink:

Posted: Sat May 17, 2008 10:08 pm
by Derek
Ah right, I thought you just wanted the end result. :(

Posted: Sat May 17, 2008 10:11 pm
by Fluid Byte
What is "brute force filling"?

Posted: Sun May 18, 2008 11:04 am
by Trond
It means, that you just draw the shape, and then use FillArea() inside it. FillArea() is dumb and simply fills pixels until it encounters a border. I imaginged the correct way to do it was to use maths to calculate whether a pixel should be coloured or not.

Posted: Sun May 18, 2008 6:54 pm
by Christian H
Derek wrote:

Code: Select all

*points=AllocateMemory(2*4*4) 
Why AllocateMemory :?:

Code: Select all

OpenWindow(0,0,0,800,600,"",$ca0001) ;  $ca0001?
InitSprite()
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)

Dim points.Point(4)

points(0)\x = 100 ;start
points(0)\y = 100

points(1)\x = 300 ;control
points(1)\y =  20

points(2)\x = 500 ;control
points(2)\y = 580

points(3)\x = 700 ;end
points(3)\y = 500


hdc=StartDrawing(ScreenOutput())

FrontColor(#White)
BeginPath_(hdc)
PolyBezier_(hdc,@points(),4)
MoveToEx_(hdc,100,100,@points())
LineTo_(hdc,700,500)
SetPolyFillMode_(hdc,#ALTERNATE)
EndPath_(hdc)
FillPath_(hdc)
StopDrawing()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Posted: Sun May 18, 2008 7:24 pm
by Derek
Just the way I did it. Different strokes. :wink:

Also $ca0001 is just short for #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget

Posted: Mon May 19, 2008 4:11 am
by pdwyer
Derek wrote:Ah right, I thought you just wanted the end result. :(
No, he just want's to know if it's possible! :twisted:

There's some good examples here http://en.wikipedia.org/wiki/B%C3%A9zier_curve which have animations on them being produced. This might help get your mind around the idea.