Move #08
18 июля 1997

algorithm - The algorithm to draw lines.

<b>algorithm</b> - The algorithm to draw lines.
                ALGORITHMS


         Algorithm for drawing a line
(C) Ars


    To display a straight line connecting
any two points can be used
algorithm Brezenhema. Its meaning is to
following: the line is regarded as a set
segments of two types: those that
located diagonally, and those who
arranged horizontally or vertically.
For lines with a slope of more than 1 direct
vertical segments, otherwise
they are horizontal. The first task of the algorithm
is to determine the slope. Then
calculated smoothing factor
which checks that a certain number of
straight segments had a greater length than
others. Finally, the cycle turns
output the diagonal and straight segments.
The equalizing factor in turn takes
is positive, then negative
values, noting what type of segment
displayed.

    LINE procedure displays a straight line
by 2 points, the coordinates are given in
Registers DE (top) and BC (the end).
PIXEL procedure takes a point with
coordinates in ref. DE (D-Y, E-X).

LM1 LD H, E

        JR PM1
LM2 LD L, C

        JR PM2
LM3 LD H, A; dY = 0, ie direct

        LD (ST_XY), HL; horizontal segments
        EXX; experimental

        LD C, L; greater distance

        LD L, H; reg.C in less than a

        JR PM3; Reg. L
LINE EXX

        LD DE, # 1514; Codes DEC D and INC D

        LD BC, # 1D1C; codes and DEC E INC E

        EXX

        LD A, B

        SUB D; check y.> Yn?

        EXX; if yes, then we take

        JR NC, LM1; code INC D, otherwise

        NEG; take the module races
        LD H, D; Toyan and code DEC D
PM1 EXX

        LD H, A; got y.-Yn

        LD A, C

        SUB E; X. verification> Xn?

        EXX; if yes, then we take

        JR NC, LM2; code INC E, otherwise

        NEG; take the module races
        LD L, B; Toyan and code DEC E
PM2 LD (DI_XY), HL; entry codes

        EXX

        LD L, A; received X.-Xn

        SUB H; determine the type of

        EXX; straight segments

        LD A, 0

        JR NC, LM3

        LD L, A; dX = 0, ie direct
PM0 LD (ST_XY), HL; vertical segments
        EXX; locally

        LD C, H; see ca. to LM3
PM3 LD B, A; A = 0!

        LD H, A; A = 0!

        ADD HL, HL; double the lesser

        LD (ST_CO +1), HL; distance

        SBC HL, BC; calculate:

        OR A; 2 x less than minus

        SBC HL, BC; 2 x greater

        LD (DI_CO +1), HL

        ADD HL, BC; loop counter in

        LD A, C; Reg. A = more
PIXEL PUSH HL; rasstoyaiyu

        BIT 7, H; HL-factor expression
        PUSH DE; smoothing if

        EX AF, AF '; H <0 (t.e H> 127)

        EX DE, HL; segment at the line
        LD A, H; my way -

        AND 7; diagonal

        OR # 40; in register DE -

        LD D, A; current coordinates
        RR H; coordinates

        RR H

        RR H

        LD A, H

        AND # 18

        OR D

        LD D, A

        LD A, H

        AND 7

        RRCA

        RRCA

        RRCA

        LD E, A; calculation bytes

        LD A, L; on the screen, where

        AND 7, will output
        LD C, A; Xia current point

        LD A, L

        SRL A

        SRL A

        SRL A

        OR E

        LD E, A

        LD HL, DATA_P; calculation of the pixel

        LD A, L; for the point

        ADD A, C

        LD L, A

        LD A, (DE)

        OR (HL)

        LD (DE), A; draw a point

        EX AF, AF '

        POP DE

        POP HL

        JR Z, DI_XY; the conclusion of direct
ST_XY DW 0; segments and
ST_CO LD BC, 0; conversion factor

        JR DECDIST; alignment
DI_XY DW 0; output diagonal
DI_CO LD BC, 0; segments and
DECDIST ADD HL, BC; conversion factor

        DEC A

        JP P, PIXEL; next point

        RET
DATA_P DB 128,64,32,16,8,4,2,1

The disadvantage of this procedure is
that the max length of the calculated line - 127
points. Data Block DATA_P should not
located on the border between the two sectors!





Other articles:

Entry - ZXNet in Minsk.

Event - On the second Minsk sisipnike.

Letter - the creative team of the newspaper MOVE.

Glance - dying Is Spectrum? On possible ways of further development.

Hackers - The structure of the standard track drive.

algorithm - The algorithm to draw lines.

Iron - Customize the signal INT.

Advertising - Advertising and announcements.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Vedem - Description, prohodilka games: Dizzy 1.
HARD and SOFT - Quenching of brightness when playing black. (Scheme)
BBS - list of stations BBS ZXNet.
Report - The first national festival komyuternogo ASCII art in 2001: NoViSeT tells how it was.

В этот день...   28 April