1. virtual polygon() - to Jiri

Dear Jiri,

Nice to look your Gems demo!
I have tested your virtual graphic routine of v_polygon().
It's fast. two times faster than my routine that i wrote before.

i hope you can find time to improve (make it faster!) it soon.
In addition to this, one more thing. your v_polygon() often fails to
draw complete straight vertical edge (in case of filled polygon)...

Please run the example below. there will appear two polygons on the
screen. left one is drawn by my routine and right one is by yours.
In the polygon drawn by your routine, as you can see, some points on
the vertical edge deviate.

Bye! -- from Lee wooseob

p.s. Thanks for your good routines and nice demos!

----------------------------codes start here-------------------------
include graphics.e
include sort.e
include get.e
include vgraph.e -- Jiri's routine

procedure vpolygon(integer color, sequence points) -- my poor routine
    sequence x
    integer lp
    integer ystart,yend,yp,x1,y1,x2,y2,max,min

    points=floor(points+0.5)
    lp=length(points)
    ystart=points[1][2]
    yend=ystart
    for i=2 to lp do
        yp=points[i][2]
        if yp<ystart then ystart=yp end if
        if yp>yend then yend=yp end if
    end for

    for y=ystart to yend do
        x1=points[lp][1]
        y1=points[lp][2]
        x={}
        for i=1 to lp do
            x2=points[i][1]
            y2=points[i][2]
            if y1!=y2 then
                if y1>y2 then
                    max=y1
                    min=y2
                else
                    max=y2
                    min=y1
                end if
                if y>min and y<=max then
                    x=x&floor(x1+(x2-x1)/(y2-y1)*(y-y1)+0.5)
                end if
            elsif y=y1 then
                if x1>x2 then
                    max=x1
                    min=x2
                else
                    max=x2
                    min=x1
                end if
                mem_set(#A0000+y*320+min,color,max-min+1)
            end if
            x1=x2
            y1=y2
        end for
        x=sort(x)
        for j=1 to length(x) by 2 do
            mem_set(#A0000+y*320+x[j],color,x[j+1]-x[j]+1)
        end for
    end for
end procedure

-- test program
include get.e
include machine.e
sequence points
if graphics_mode(19) then end if

vpolygon(RED,points) -- my routine
v_polygon(RED,1,points+repeat({100,0},length(points))) -- Jiri's

if wait_key() then end if
if graphics_mode(-1) then end if
-----------------------------codes end here------------------------

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu