Programming - “colored” dots and lines, gradient fill, conversion to 256 colors.

Deja Vu #0A
__________________________________________

(C) Max/CYBERAX Software/BDA
    Some GFX by Alex/CBX/BDA
__________________________________________

  _____________ __________               _____
  ___  __ __(_)_  /___  /_ _____ __________(_)____________ _
  __  / / /_  /_  __/_  __ _  _ __  ___/_  /_  __ _  __ `/
  _  /_/ /_  / / /_ _  / / //  __/_  /   _  /_  / / /  /_/ /
  /_____/ /_/  __/ /_/ /_/ ___/ /_/    /_/ /_/ /_/___, /
                   _______ __ _____________         /____/
                   ____/ // /___  __ _|__ 
                   _ _  _  __/_  / / /___/ /
                   /_  _  __/ / /_/ /_  __/
                    /_//_/    ____/ /____/


   Yeah... The second part is somehow poorly written
it's going on.  If the first one along with the source code I
filled in a week, then work on the continuation
it dragged on for as much as half a year... It’s a waste,
then there’s no time... Well, okay, let’s get started.

   This time I'll load you up next
things:

- "colored" dots and lines
- gradient fill
- "256-color" graphics
- conversion 256 colors -> 2 & 4 colors
- examples of using this technology

  Before reading, I recommend contacting
the first part of the opus, which can be found in
7th number DEJA VU.Basically, the second
part of the article is nothing new
represents and is, as it were, a consequence
first.


1) Color dots

   Of course, I went a little overboard with this
term.   There will still be 2 points
colored.They will simply be placed with
probability proportional to the "color".  Color
ours will vary from 0 to 64.
 Let us need to depict a point with a color
volume 25.  Let's fill the usual Spectrum
screen texture with number 25 (textures
us 8x8).  Turn on the pixel on another screen
with the required coordinates.  Now if two
fold these screens along AND, we get
the so-called "color" point.
   In practice, of course, it is better to use
create another algorithm that nevertheless gives
similar result.  Let us assume that it is necessary
you can put a point with coordinates (X,Y) and
color C.  The sequence of actions will be
the child is like this:

1) Find the remainder of the division of the coordinate X
 to 8 (MX=X AND 7)

2) Similarly with the coordinate Y (MY=Y AND 7)

3) From the matrix D8 we extract the number N with the coordinate
dinata (MX,MY)

4) If C>N, then turn on the pixel with the coordinate
 natami (X,Y), otherwise - turn off

   In fact, this is nothing more than an algorithm
rhythm of image conversion from DV#07.

             Now the source:

;---------------------------------------
;IN: A - COLOR (0...64)
;       B - X, C - Y

DOT EX AF,AF
 LD H,DOT_TAB+1
 LD L,B;        X-coordinate
 LD A,(HL);     A=X/8
INC H
 LD L,C;        Y-coordinate
 OR (HL);мл. байт адреса
        LD    E,A
        INC   H
        LD    D,(HL);     ст. байт адреса
        INC   H
        LD    H,(HL);     строка матрицы
        LD    L,B;        X-координата
        EX    AF,AF;      цвет
        CP    (HL)
        RET   C;          не ставим точку
        LD    H,DOT_TAB
        LD    A,(DE);     извлекаем бит
        OR    (HL);       ставим точку
        LD    (DE),A
        RET

;Эту штуку надо вызвать для инициализации:

DOT_INI LD    HL,DOT_TAB*256
        LDA,#80
DOT1    LD    (HL),A;     таблица битов
        RRCA
        INC   L
        JR    NZ,DOT1
        INC   H
DOT2    LD    A,L;        (HL)=L/8
        RRCA
        RRCA
        RRCA
        AND   31
        LD    (HL),A
        INC   L
        JR    NZ,DOT2
        INC   H
        LD    DE,#4000
        LD    B,#C0
DOT3    LD    (HL),E;     таблица адресовINC   H
        LD    (HL),D
        DEC   H
        INC   D
        LD    A,D
        AND   7
        JP    NZ,$+13
        LD    A,E
        ADD   A,32
        LD    E,A
        JR    C,$+6
        LD    A,D
        SUB   8
        LD    D,A
        INC   L
        DJNZ  DOT3
DOT4    LD    (HL),E
        INC   H
        LD    (HL),E
        DEC   H
        INC   L
        JR    NZ,DOT4
        INC   H
        INC   H
DOT5    LD    A,L;        таб. ст. адресов
        AND   7           строк матрицы
        ADD   A,H
        INC   A
        LD    (HL),A
        INC   L
        JR    NZ,DOT5
        INC   H
        EX    DE,HL
        LD    HL,MATRIX
        LD    C,8
DOT6    PUSH  BC,DE;      каждую строку
        LD    C,8матрицы повто-
        LDIR              ряем 8 раз
        EX    (SP),HL
        LD    C,#F8
        LDIR
        POP   HL,BC
        DEC   C
        JR    NZ,DOT6
        RET

MATRIX  DB    1,33,9,41,3,35,11,43
        DB    49,17,57,25,51,19,59,27
        DB    13,45,5,37,15,47,7,39
        DB    61,29,53,21,63,31,55,23
        DB    4,36,12,44,2,34,10,42
        DB    52,20,60,28,50,18,58,26
        DB    16,48,8,40,14,46,6,38
        DB    64,32,56,24,62,30,54,22

DOT_TAB EQU #C0;        st. adr. tables
;---------------------------------------

   "What kind of crap is he pushing here? Is it really
are these colored dots?  - some will say.
   Yes, one such point is not called colored
stuff. But when there are a lot of them, it’s a different matter!
   So I took ALK's source code from Oberon for
construction of the Mandelbrot fractal, replaced
in it the attribute point on its own and received
this picture:

2) Color lines

   Color lines - this is not just any
a toy, and the drawing procedure is “colored”
lines.  It's different from the regular line.
only that the point procedure is replaced
to the “colored” point procedure.
   This implementation is no different
speed, therefore for practical
It is advisable to optimize its use,
or better yet, write it from scratch.
   To simplify (or complicate - to whom
how...) experiments line coordinates and
colors are taken from BASIC (user function
body).  Therefore, do not forget to bring them to
the whole species!

;---------------------------------------
 ORG #8000
 ENT
CALL  DOT_INI
        EXX
        PUSH  HL
        LD    HL,(#5C0B);  адрес пар-ров
        LD    BC,4
        ADD   HL,BC
        LD    D,(HL);      Выковыриваем X1
        LD    C,8
        ADD   HL,BC
        LD    E,(HL);      Y1
        ADD   HL,BC
        LD    A,(HL);      X2
        EX    AF,AF
        ADD   HL,BC
        LD    A,(HL);      Y2
        ADD   HL,BC
        LD    B,(HL);      C
        LD    L,A
        EX    AF,AF
        LD    H,A
        LD    A,B
        LD    (COLOR+1),A
        LD    (COLOR1+1),A
        LD    (COLOR2+1),A
        EX    DE,HL
        CALL  LINE
        POP   HL
        EXX
        RET

DOT     LD    H,DOT_TAB+1
        LD    L,B
        LD    A,(HL)
        INC   H
        LD    L,C
        OR    (HL)
        LD    E,A
        INC   H
        LD    D,(HL)
        INC   H
        LD    H,(HL)
        LD    L,B
COLOR   LD    A,63
        CP    (HL)
        RET   C
        LD    H,DOT_TAB
        LD    A,(DE)
        OR    (HL)
        LD    (DE),A
        RET

LINE    LD    A,E
        SUB   L
        JR    NC,NOEXCH
        EX    DE,HL
        NEG
NOEXCH  LD    C,A;  Y2-Y1
        LD    LX,0
        ORG   $-1
        INC   D
        LD    A,D
        SUB   H
        JR    NC,X_OK
        LD    LX,0
        ORG   $-1
        DEC   D
        NEG
X_OK    EX    DE,HL
        CP    C
        JR    C,DY>DX
DX>DY   LD    B,A; B=A=X2-X1, C=Y2-Y1
        OR    A
        JR    Z,NO_LIN1
        RRA
        LD    H,B
        EX    AF,AF
        LD    A,LX
        LD    (COM1),A
        EX    AF,AF
DRW_LP1 EX    AF,AF
        PUSH  DE
        EXX
        POP   BC
        LD    H,DOT_TAB+1
        LD    L,B
        LD    A,(HL)
        INC   H
        LD    L,C
        OR    (HL)
        LD    E,A
        INC   H
        LD    D,(HL)
        INC   H
        LD    H,(HL)
        LD    L,B
COLOR1  LD    A,64
        CP    (HL)
        JR    C,NODOT1
        LD    H,DOT_TAB
        LD    A,(DE)
        OR    (HL)
        LD    (DE),A
NODOT1  EXX
COM1    INC   D
        EX    AF,AF
        SUB   C
        JR    NC,NOINC1
        ADD   A,H
        INC   E
NOINC1  DJNZ  DRW_LP1
NO_LIN1 PUSH  DE
        EXX
        POP   BC
        CALL  DOT
        EXX
        RET

DY>DX   LD    B,C
        LD    C,A
        LD    A,B; B=A=Y2-Y1, C=X2-X1
        OR    A
        JR    Z,NO_LIN2
        RRA
        LD    H,B
        EX    AF,AF
        LD    A,LX
        LD    (COM2),A
        EX    AF,AF
DRW_LP2 EX    AF,AF
        PUSH  DE
        EXX
        POP   BC
        LD    H,DOT_TB+1
        LD    L,B
        LD    A,(HL)
        INC   H
        LD    L,C
        OR    (HL)
        LD    E,A
        INC   H
        LD    D,(HL)
        INC   H
        LD    H,(HL)
        LD    L,B
COLOR2  LD    A,63
        CP    (HL)
        JR    C,NODOT2
        LD    H,DOT_TAB
        LD    A,(DE)
        OR    (HL)
        LD    (DE),A
NODOT2  EXX
        INC   E
        EX    AF,AF
        SUB   C
        JR    NC,NOINC2
        ADD   A,H
COM2    INC   D
NOINC2  DJNZ  DRW_LP2
NO_LIN2 PUSH  DE
        EXX
        POP   BC
        CALL  DOT
        EXX
        RET

DOT_INI LD    A,#C9
        LD    (DOT_INI),A

; The rest of the initializer is the same,
;as for the point, so I don’t give it.
        LD HL,DOT_TAB*256
 LD A,#80
 ...
 ...
 RET

MATRIX ...
 ...
 ...


DOT_TAB EQU #C0
;---------------------------------------


     Here is an example of the above working
      procedures (gradient filling).
  Something like this is used as
       textures for menus in DEJA VU.

   This is built using the following
next program (preliminary
but load the file col_line.C,
which contains the procedure itself
lines):

1 DEF FN L(A,B,C,D,E)=USR 32768
2 LET Y=0 : LET X1=256-64 : LET
  X2=X1 : LET Y1=0 : LET Y2=0
3 LET C=40+14*SIN (PI*Y/32)+12*
  SIN (PI*Y/20)
4 RANDOMIZE FN L(X1,Y1,X2,Y2,
  INT C)
5 IF X2=255 THEN LET Y2=Y2+1
6 IF Y1=191 THEN LET X1=X1+1
7 LET Y=Y+1 : IF X2<255 THEN
  LET X2=X2+1
8 IF Y1<191 THEN LET Y1=Y1+1
9 IF X1<256 THEN GO TO 3
10 PAUSE 0

   BASIC, конечно, это ламерст-
во, но для черновых эксперимен-
тов и так сойдет...



              Еще примерчик:

Делаем надпись на pC
или  chr-шрифтами на
Спектруме (печаталка
by Delirium Tremens-
RULEZ!):

Генерируем градиент-
ную текстуру:



 Складываем обе кар-
тинки по AND:

              А можно и так:


Берем исходное изо-
бражение:


Поочередно сдвигаем
его во все 4 сторо-
ны и складываем ре-
зультаты  по  OR  с
исходнымimage:

We proxy half-
compared with the original
image:



Generating the texture:



Add by AND
texture and original
picture:


Add up the results
tats of the 3rd and 5th
steps by OR:


   I'm still thinking about doing it for myself
some kind of Photoshop editor
gradient fill so as not to be distorted
in BASIC with sines.  Those. you set the value
brightness decrease at several points, and mainly
In general, it is interpolated automatically.
Splines are very suitable for this task.
Bezier (see Rush #02).   In general, splines -
convenient thing.  Applications can be found in
in a variety of areas, especially in graphics.
   Okay, let's move on.  I haven't yet-
so many examples.

   This is an example of a pseudo-3D image:




   If you change the phase of the sine, you can semi-
create some good animation (albeit in realtime)
this is unlikely to happen).



         And this is something like a flag:

   Pay attention to smooth transitions
illumination, which is actually not
It’s not illumination, but just sinusoidal
distant additive to color.
   Those. this technology allows very
simple means to achieve are not so
and bad results.  Moreover, everything happened
dit without using PC/Amiga and without manual
labor in a graphic editor (although not
a big edit wouldn't hurt anyway).


3) 256 colors

   Let's summarize some results.  All the above described
sled in the presence of a certain imagination
allows you to create quite an impression
flashing pictures. However the method has one
disadvantage - after rendering from the image
it is difficult to perform any manipulations
lation due to its two-color nature.  Those.
The rendering of the image must occur in
one pass and all effects must be re-
implemented immediately.
   Therefore, we can complicate the data somewhat
nal method.  Nothing (except memory capacity)
makes it difficult to put points in the intermediate ek-
early buffer, and for one point you can
allocate a whole byte.

   Here's what it gives:

1) 256 colors (more precisely, grayscale) per
   point.  Or you can make 64 colors,
   and the remaining2bits should be used either
   as a mask, or as an alpha channel (4 gra-
   transparency).

2) You can do multi-pass rendering.

3) The possibility of interchange appears
   grayscale pictures with the same pC.

   The disadvantage is the need to
Convert everything carefullyinto a bitmap in order to semi-
give an idea of the created picture.


   The image creation process can be
like this:

- convert from any platform or geo-
  nerable by some algorithm is impossible
  Rarely on Spectrum 256-color
  textures.

- we place one of the textures in the buffer in
  as background.

- we build on a background texture, for example,
  3D object and overlay it on its faces
  other textures, it is possible taking into account the lighting
  (fortunately, in chunks all this is already real-
  lyzed). You can at least fill Phong for-
  release, or ray tracing...

- if necessary, do BLUR or ANTI-
  ALIASING

- then you can play around with the resulting
  image in 2D, for example:

  a) run some filter
  b) deform
  c) according to some law add with another
     image, incl. and using
     using the transparency map.
  d) make, say, inscriptions with a maske) overlay (overlay :) lighting
     tion (eg bump light).
  e) in general, see Adobe Photoshop, menu
     filters :)

- after all these procedures (if, of course,
  something will remain from the picture...) necessary
  dimo convert it all into a bitmap or
  in 2-screen interlaced mode.

   I foresee remarks like: “Ah-ah, bullshit, I
I can play all this on my PC in half an hour!”
Yes, of course, if there is one. If not -
read on.

   Of course, you will have to sleep on this whole matter.
I started coding because... this is just a theory.
There will be only two procedures from me, which
which will be useful to you at the final stage
creating cool pictures - conversion.
   In general, for conversion you can use the above-
the given point procedure. It's true she doesn't
understands colors with code >64, but this is not
scary.  Just divide the 8-bit color code
to 4 and call this program.
   However, you can convert to 2 bitplana
(seeDithering #1,two-plane textures).
To do this, I wrote a procedure 193-xcolor
points.  Here you can no longer make do with division,
so it falls evenly across the plate
display color range 0...255 in 0...
192, and only then put a dot.

;---------------------------------------
 ORG #6000
 ENT

;IN: A - COLOR (0...255)
;       B - X, C - Y
;Before using the point procedure, do not
;passed once:
;- call INIT
;- clear the screen of the 5th bank
;  (PAPER=0, INK=X, BRIGHT=1, FLASH=0)
;- clear the screen of the 7th bank
;  (PAPER=0, INK=X, BRIGHT=0, FLASH=0)
;- turn on the 7th bank (and do not remove it
;  when calling PSET!)

PSET EXX
 LD L,A
 LD H,DOT_TAB+#18
 LD A,(HL)
 EX AF,AF
        INC   H
        LD    C,(HL)
        EXX
;
        LD    H,DOT_TAB+12
        LD    L,B
        LD    A,(HL)
        INC   H
        LD    L,C
        OR    (HL)
        LD    E,A
        INC   H
        LD    D,(HL)
        INC   H
        LD    H,(HL)
        LD    L,B
        EX    AF,AF
        CP    (HL)
;
        EXX
        LD    A,C
        EXX
        LD    H,A
        LD    A,(DE)
        JR    C,NO_DOT
        INC   H
        INC   H
NO_DOT  OR    (HL)
        LD    (DE),A
        SET   7,D
        INC   H
        LD    A,(DE)
        OR    (HL)
        LD    (DE),A
        RET

INIT    LD    HL,DOT_TAB*256
        CALL  DOT1
        CALL  DOT1
        CALL  DOT1
        CALL  DOT2

        CALL  DOT1
        CALL  DOT2
        CALL  DOT2
        CALL  DOT1

        CALL  DOT2
        CALL  DOT1
        CALL  DOT2
        CALL  DOT2

;+12
DOT3    LD    A,L
        RRCA
        RRCA
        RRCA
        AND   31
        LD    (HL),A
        INC   L
        JR    NZ,DOT3

;+13
        INC   H
        LD    DE,#4000
        LD    B,#C0
DOT4    LD    (HL),E
        INC   H
        LD    (HL),D
        DEC   H
        INC   D
        LD    A,D
        AND   7
        JP    NZ,DOT4_1
        LD    A,E
        ADD   A,32
        LD    E,A
        JR    C,DOT4_1
        LD    A,D
        SUB   8
        LD    D,A
DOT4_1  INC   L
        DJNZ  DOT4

;+15
        INC   H
        INC   H
        LD    L,B
DOT5    LD    A,L
        AND   7
        ADD   A,H
        INC   A
        LD    (HL),A
        INC   L
        JR    NZ,DOT5

;+16
        INC   H
        EX    DE,HL
        LD    HL,MATRIX
        LD    C,8
DOT6    PUSH  BC,DE
        LD    C,8
        LDIR
        EX    (SP),HL
        LD    C,#F8
        LDIR
        POP   HL,BC
        DEC   C
        JR    NZ,DOT6
;+24
        EX    DE,HL
        LD    BC,DOT_TAB*256
        LD    A,#80
        LD    DE,#FFC0
DOT7    LD    (HL),C
        INC   H
        LD    (HL),B
        DEC   H
        SUB   E
        JR    NC,$+4
        ADD   A,D
        INC   C
        EX    AF,AF
        LD    A,C
DOT9    SUB   65
        JR    C,DOT8
        INC   A
        LD    C,A
        INC   B
        INC   B
        INC   B
        INC   B
        JR    DOT9
DOT8    EX    AF,AF
        INC   L
        JR    NZ,DOT7
        RET

DOT1    XOR   A
DOT1_1  LD    (HL),A
        INC   L
        JR    NZ,DOT1_1
        INC   H
        RET

DOT2    LD    A,#80
DOT2_1  LD    (HL),A
        RRCA
        INC   L
        JR    NZ,DOT2_1
        INC   H
        RET

MATRIX  DB    1,33,9,41,3,35,11,43
        DB    49,17,57,25,51,19,59,27
        DB    13,45,5,37,15,47,7,39
        DB    61,29,53,21,63,31,55,23
        DB    4,36,12,44,2,34,10,42
        DB    52,20,60,28,50,18,58,26
        DB    16,48,8,40,14,46,6,38
        DB    64,32,56,24,62,30,54,22

DOT_TAB EQU   #70
;---------------------------------------

   Here's how to convert the full palette
colors 0...255 using two screens
new:



   The second procedure is for us -
256-color brightness and contrast triples
images.  You can use it either
as a filter, i.e. applying to the image in
buffer, or by building it into the conversion procedure
(in this case, it will only affect the re-
the result of the conversion but not to the original card-
teen).
   The result of her work is very close to the real
as a result of a similar option in
Adobe Photoshop.  The differences are due to inaccuracy
by calculating the contrast table.

;---------------------------------------
 ORG #6000
 ENT

BRG_TAB EQU #7000; Brightness table
CTR_TAB EQU #7100; Contrast table

        CALL INIT
;The initializer must be called every
;times after changing the brightness/contrast values
;ta (variables BRIGHT and CONTRST).

;After initialization, you can use pre-
;education:

        LD L,100;Pixel color
;                    (for example 100)
;Convert:
        LD H,BRG_TAB&H
 LD D,CTR_TAB&H
 LD E,(HL)
 LD A,(DE)
;Now the battery contains a converter
;named pixel color.

;So you need to run everything pixel by pixel
;image.
        RET

BRIGHT DB 0-60&L
;The variable specifies the value of the brightness increment
;bones. If the number is greater than zero (1...127) -
;brightness increases;  if less than zero
;(-128...-1) - decreases;  0 - no change -
;there is.

CONTRST DB 200
;And this contains a change in contrast.
;Contrast can only be increased.  Than
;the smaller this number, the more contrasting the result
;tat.   Value 255 the picture is almost no less
;yay.

INIT    LD    HL,BRG_TAB
        LD    A,(BRIGHT)
        LD    B,A
        LD    A,#FF
        SUB   B
        RLA
        SBC   A,A
        LD    C,A
MK_BRG1 LD    A,L
        ADD   A,B
        LD    (HL),A
        RRA
        XOR   B
        RLA
        JR    NC,$+3
        LD    (HL),C
        INC   L
        JP    NZ,MK_BRG1

        LD    HL,CTR_TAB
        XOR   A
MK_CTR1 LD    (HL),A
        INC   L
        JP    P,MK_CTR1
        CPL
MK_CTR2 LD    (HL),A
        INC   L
        JR    NZ,MK_CTR2
        LD    B,H
        LD    C,L

        LD    A,(CONTRST)
        LD    E,A
        LD    D,0
        LD    A,#FF
        SUB   E
        SRL   A
        LD    H,A
        LD    L,D

MK_CTR3 LD A,C
 LD C,H
 LD (BC),A
 LD C,A
 ADD HL,DE
 INC C
 JP NZ,MK_CTR3
 RET
;---------------------------------------

   To illustrate how the procedure works, the following is given:
Here's an example. An image was taken on the PC
in the format BMP grayscale.Then using
above procedure and procedure
"colored" dots are converted to different meanings
Brightness/contrast values:



   And everything looks really cool on two
bitplanes (we used a two-
planning point):



   We'll probably stop there. End-
but, one could also talk about visualization
tions of 3D graphs of functions like SIN (R)/R with
calculation of lighting at each point (see
is simply drop dead!) or about the genera-
tions of backgrounds, but howthey say, ho-
little by little...
   Somewhere in the depths of the application you will find
several programs.   In addition to the basics,
rendering some pictures from this
articles for XAS fans there are also
these files:

BRG_CTR.X - adjusting brightness and contrast
COL_DOT.X - point source
2BP_DOT.X - source of a two-bit plan point
COL_LINE.X - line source
col_line.C - compiled line

-----------------< 08/27/2000, Kemerovo >-
 Chapter 6.
 Write, Shura, write!

   For all questions related to CSE write
to the editor.  If you desperately need some...
or a function (for example, copying pieces
sample to the buffer and back) - write.   If
I think your idea is rational and I have
If I have time and desire, I will provide support.
   If any glitches suddenly appear
(especially fatal ones) - don’t be lazy and
please let me know.
   INIn principle, I can help with adaptation
sound player to another music player
to the editor (PSC, ST PRO, FT, GT, ASM..),
although I don’t know who this might cause
problems.
   Yes, I completely forgot!   If you make it convenient
fast and fast disk interface - built-in
bark!

Share your thoughts about the article