Filled bezier shape?

Just starting out? Need help? Post your questions and find answers here.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Filled bezier shape?

Post 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...
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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 
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I'm interested in the algorithm behind it, so API won't work. :wink:
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Ah right, I thought you just wanted the end result. :(
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

What is "brute force filling"?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Christian H
New User
New User
Posts: 4
Joined: Sun May 18, 2008 6:46 pm
Location: Welschbillig Germany

Post 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
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply