Example

Vector Graphics With Transformation Matrix (imported from LowRes Coder)

7

SP4CEBAR 2022-04-22 15:21 (Edited)

I just made transformation matrices in LowRes Coder, which allow rotation and scaling of pixel images and vector images. In terms of graphics, they rely on two things: drawing lines and flood filling.

Either way, I made a crappy drawing in my LowRes Coder paint program, the program recorded (logged) my drawing operations. Which I used as vectors in a vector image.

And then I used my oldest NX program to plot the lines. It is pretty slow, but I found a huge optimization which made it 5x faster. You can scale the image with the buttons (A: smaller, B: larger) and you can move it around with the arrows.

I also made a version with pixel graphics
Press pause to switch between a vector image and a pixel image

Vector Graphics.nx | Open in app
2022-04-23 07:37
Vector Graphics.nx | Open in app
2022-04-22 20:11
Vector Graphics.nx | Open in app
2022-04-22 18:48
Vector Graphics.nx | Open in app
2022-04-22 15:21

McPepic 2022-04-22 15:42

Super cool. If you implement a double buffering technique, you could hide the drawing of the lines, only showing the final image.


SP4CEBAR 2022-04-22 15:50 (Edited)

I'd rather improve the performance so that the lines are all drawn before VBL
Also, where can I buffer it to, I've already used all 256 characters (I'm not using rasters)


SP4CEBAR 2022-04-22 16:13 (Edited)

I think I can optimize a lot!
my current data modifications look like this:
.
.
.
.

    'DECODE CHARACTER DATA
    FOR I=0 TO 15
      FOR J=0 TO 1
        X$=MID$(D$,I+J*16+1,1)
        IF X$="F" THEN 
          W=15
        ELSE IF X$="E" THEN 
          W=14
        ELSE IF X$="D" THEN 
          W=13
        ELSE IF X$="C" THEN 
          W=12
        ELSE IF X$="B" THEN 
          W=11
        ELSE IF X$="A" THEN 
          W=10
        ELSE 
          W=VAL(X$)
        END IF
        FOR K=3 TO 0 STEP -1
          DAT2(K,0)= INT(W/(2^K))
          W=W-DAT2(K,0)*(2^K)
        NEXT K
        FOR K=0 TO 3
          DAT2(K,1)=DAT2(K,1)+DAT2(K,0)*(J+1)
        NEXT K
      NEXT J
      DAT((I MOD 2)*4  ,INT(I/2))=DAT2(3,1)
      DAT((I MOD 2)*4+1,INT(I/2))=DAT2(2,1)
      DAT((I MOD 2)*4+2,INT(I/2))=DAT2(1,1)
      DAT((I MOD 2)*4+3,INT(I/2))=DAT2(0,1)
      FOR K=0 TO 3
        DAT2(K,1)=0
      NEXT K
    NEXT I

    'ADD PIXEL X,Y TO THIS DATA
    IF OPERATION=0 THEN
      DAT(X MOD 8,Y MOD 8)=C
      REM PRINT X,X MOD 8,Y,Y MOD 8
    ELSE
      REM IT LOOKS LIKE IT ISN'T DECODED CORRECTLY, OR IT'S READING ON THE WRONG PLACE

      FOR J=0 TO 7
        FOR I=0 TO 7
          A=DAT3(I,J)
          DAT(I,J)=A+DAT(I,J)*ABS(SGN(A)-1)
        NEXT I
      NEXT J
    END IF


    'PRINT DECODED DATA
    IF 0 THEN
      BG 0
      FOR J=0 TO 7
        FOR I=0 TO 7
          PRINT DAT(I,J);
        NEXT I
        PRINT " "
      NEXT J
      PRINT " "
    END IF

    'ENCODE CHARACTER DATA
    FOR I=0 TO 15
      D0=DAT((I*4+4) MOD 8, INT(I/2))
      D1=DAT((I*4+5) MOD 8, INT(I/2))
      D2=DAT((I*4+6) MOD 8, INT(I/2))
      D3=DAT((I*4+7) MOD 8, INT(I/2))
      ARR2(I)=    (D3 MOD 2)+ (D2 MOD 2)*2+ (D1 MOD 2)*4+ (D0 MOD 2)*8
      ARR2(I+16)=  INT(D3/2)+  INT(D2/2)*2+  INT(D1/2)*4+  INT(D0/2)*8
    NEXT I

    REM PRINT ADDR

    'WRITE  CHARACTER DATA
    FOR I=0 TO 15
      V=ARR2(I*2)+16*ARR2(I*2+1)
      POKE $8000+I+16*ADDR,V
    NEXT I

.
.
.
.
I think I can just replace all that with

POKE A,PEEK(A) OR 2^N


SP4CEBAR 2022-04-22 18:49 (Edited)

500% performance update


SP4CEBAR 2022-04-22 20:12

New update, now it's almost realtime


SP4CEBAR 2022-04-22 20:57 (Edited)

Now I need to make a flood fill algorithm, but I'm already at the performance limit. The flood fill algorithm I made a while ago for minesweeper would start at a block and search for neighbors, which would each be filled and added to the queue array, each filled block would be marked as filled on the map array
My algorithm seems similar to the simplest one mentioned on wikipedia
It looks like there are flood filling algorithms that expand sideways in lines, I think those would work really well with our rasters (in a flood fill everything has the same color)
The only problem is that the raster will only go from the top of the screen to the bottom even though that flood fill may need to go the other way


SP4CEBAR 2022-04-23 20:05 (Edited)

I'm working on a new line drawing algorithm
The current algorithm repeats and increments the variable T (parametric) until T exceeds the length of the line
Inside each repeat loop it'll calculate X and Y coordinates based on T
It'll then plot a point at these coordinates

The line subprograms draws a line from X1,Y1 to X2,Y2

My new algorithm has a for loop for the Y coordinates (FOR Y1 TO Y2 STEP Y_DIRECTION) the step size is always 1 because that's the perfect fill (it won't leave gaps)
It then adds a delta X (which is X2-X1/Y2-Y1) to X on each loop
I can then write a function to draw horizontal lines


Optimizing processes isn't fun, you need to think really hard and the algorithm must perform better than the previous algorithm otherwise the time would be wasted
And it's easy to get caught up into details


SP4CEBAR 2022-04-23 20:11 (Edited)

Also I just wanted to show this, it can't draw lines with an upwards direction (don't worry I already fixed it), this gives it a shaded effect

By the way, my new algorithm is faster!

Vector Graphics.nx | Open in app
2022-04-23 20:11

SP4CEBAR 2022-04-23 20:51

The problem with my new algorithm is that the x step size approaches infinity when a line becomes horizontal


SP4CEBAR 2022-04-23 21:03

I call this: Art!

Vector Graphics.nx | Open in app
2022-04-23 21:03

SP4CEBAR 2022-04-25 06:31

It looks like it isn't going to be much faster, yet harder to implement


jr 2022-05-27 08:48

Someone could use this to make a version of Asteroids!


SP4CEBAR 2022-05-29 09:14

yes
unfortunately, the performance of these kinds of graphics in NX is pretty slow


SP4CEBAR 2022-08-03 14:42

Slight performance improvements by using my new plot() subprogram that uses tables, I also removed the "out of boundaries" check from the line function, this improved the performance


Log in to reply.