English
Source / code snippets

Algorithmus Bresenham line characters

 
Bresenham-Algorithmus [...]  line characters

Frabbing, URL=www.paules-pc-forum.de/forum/dlls-includes-units-prozeduren/118552-bresenham-algorhythmus.html, Zeitpunkt=23.08.2009
lines yourself to charge, Pixel for Pixel.
CompileMarkSeparation
Bresenham-Algorhythmus in XProfan
(c) Frank Abbing für http://www.paules-pc-forum.de/forum/xprofan/
Declare grid&
SYNTAX:
Bresenham(Farbe (RGB), Startpunkt links (in Pixel), Startpunkt oben, Endpunkt rechts, Endpunkt unten)
________________________________________________________________________________________________________________

Proc Bresenham

    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Parameters col&,x1&,y1&,x2&,y2&
    Declare x&,y&,z&,a&,b&,d&,dx&,dy&,dp&,dq&
    dx&=@abs(x2&-x1&)
    dy&=@abs(y2&-y1&)

    If ((dx&<>0) AND (dy&<>0))

        If ((dy&<dx&) OR (dy&=dx&))

            x&=x1&
            y&=y1&
            z&=x2&

            If (x1&<x2&) OR (x1&=x2&)

                a&=1

            Else

                a&=-1

            EndIf

            If (y1&<y2&) OR (y1&=y2&)

                b&=1

            Else

                b&=-1

            EndIf

            dp&=dy&+dy&
            d&=dp&-dx&
            dq&=dp&-(dx&+dx&)
            SetPixel x&,y&,col&
            AddString(grid&,Str$(x&)+"|"+Str$(y&))

            While (x&<>z&)

                x&=x&+a&

                If d&<0

                    d&=d&+dp&

                Else

                    y&=y&+b&
                    d&=d&+dq&

                EndIf

                SetPixel x&,y&,col&
                AddString(grid&,Str$(x&)+"|"+Str$(y&))

            EndWhile

        Else

            y&=y1&
            x&=x1&
            z&=y2&

            If (y1&<y2&) OR (y1&=y2&)

                a&=1

            Else

                a&=-1

            EndIf

            If (x1&<x2&) OR (x1&=x2&)

                b&=1

            Else

                b&=-1

            EndIf

            dp&=dx&+dx&
            d&=dp&-dy&
            dq&=dp&-(dy&+dy&)
            SetPixel x&,y&,col&
            AddString(grid&,Str$(x&)+"|"+Str$(y&))

            While y&<>z&

                y&=y&+a&

                If d&<0

                    d&=d&+dp&

                Else

                    x&=x&+b&
                    d&=d&+dq&

                EndIf

                SetPixel x&,y&,col&
                AddString(grid&,Str$(x&)+"|"+Str$(y&))

            EndWhile

        EndIf

    EndIf

    If ((dx&=0) OR (dy&=0))

        If ((dx&=0) AND (dy&<>0))                   achsenparallel x

            x&=x1&
            y&=y1&
            z&=y2&

            If (y1&<y2&) OR (y1&=y2&)

                b&=1

            Else

                b&=-1

            EndIf

            SetPixel x&,y&,col&
            AddString(grid&,Str$(x&)+"|"+Str$(y&))

            While y&<>z&

                y&=y&+b&
                SetPixel x&,y&,col&
                AddString(grid&,Str$(x&)+"|"+Str$(y&))

            EndWhile

        Else

            If ((dx&<>0) AND (dy&=0))                  achsenparallel y

                x&=x1&
                y&=y1&
                z&=x2&

                If (x1&<x2&) OR (x1&=x2&)

                    a&=1

                Else

                    a&=-1

                EndIf

                SetPixel x&,y&,col&
                AddString(grid&,Str$(x&)+"|"+Str$(y&))

                While x&<>z&

                    x&=x&+a&
                    SetPixel x&,y&,col&
                    AddString(grid&,Str$(x&)+"|"+Str$(y&))

                EndWhile

            EndIf

        EndIf

    EndIf

    x1&=x&
    y1&=y&

Endproc

Cls
Randomize
grid&=Create("GridBox", %hwnd, "X-Achse;1;56;Y-Achse;1;56", 2, 8, 8, 136, 408)

Whileloop 20

    Bresenham(RGB(Rnd(255),Rnd(255),Rnd(255)), Rnd(490)+150,Rnd(400), Rnd(490)+150,Rnd(400))

EndWhile

While 1

    WaitInput
    Case %key=2:ef='./../../references-fonction/XProfan/break/'>Break

Endwhile

End


who not self LinienPunkte to charge would like, but nevertheless Pixel for Pixel self draw would like, can itself the LineDDA-Api [...]  valet.
CompileMarkSeparation
def lineDDA(6) !"gdi32.dll","LineDDA"
cls
lineDDA(10,10,200,150,procAddr(myLineDDAProc,3),rgb(255,0,0))
waitInput
end

proc myLineDDAProc

    parameters x&,y&,c&
    setpixel x&,y&,c&
    return 1

endProc

 
08/24/09  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

4.218 Views

Untitledvor 0 min.
Frank04/16/21
Walter Meidl04/02/15
Ernst05/26/14

Themeninformationen

this Topic has 1 subscriber:

iF (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie