Author Topic: Disappearing drawing  (Read 3232 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Disappearing drawing
« on: January 19, 2021, 03:15:49 pm »
Download the attached file and you will see a message for developers. Then delete the GOTO statement at the beginning and you can create your own messages. It's just a little thing I played with today.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2.  
  3. TYPE Pojnt
  4.     X AS INTEGER
  5.     Y AS INTEGER
  6. REDIM B(0) AS Pojnt
  7.  
  8.  
  9. GOTO loader 'erase this row for full program function after first run :)
  10.  
  11. ' in this block - draw something (bigger image is better) to screen
  12. ' -----------------------------------------------------------------
  13.     WEND
  14.     OMX = mx
  15.     OMY = my
  16.     mx = _MOUSEX
  17.     my = _MOUSEY
  18.     LB = _MOUSEBUTTON(1)
  19.     IF LB AND OMX <> mx OR LB AND OMY <> my THEN
  20.         B(i).X = mx
  21.         B(i).Y = my
  22.         i = i + 1
  23.         CircleFill mx, my, 5, &HFFFFFF00
  24.         REDIM _PRESERVE B(i) AS Pojnt
  25.     END IF
  26. ' --------------------------------------------------------------------
  27.  
  28.  
  29. ' in this block: Save your work as compressed binary file to harddrive
  30. ' --------------------------------------------------------------------
  31. DIM Save AS _MEM
  32. Save = _MEMNEW((i + 1) * 4)
  33. _MEMPUT Save, Save.OFFSET, B()
  34. uncompress$ = SPACE$(i * 4)
  35. _MEMGET Save, Save.OFFSET, uncompress$
  36. Compress$ = _DEFLATE$(uncompress$)
  37. OPEN "MizejiciText.sav" FOR BINARY AS ff
  38. PUT ff, 1, Compress$
  39. ' ---------------------------------------------------------------------
  40.  
  41. ' RESET ALL VALUES TO ZERO
  42. ' ------------------------
  43. loader:
  44. i = 0
  45. REDIM B(0) AS Pojnt
  46.  
  47.  
  48. ' Load Values from file to memory, decompress it and palce it back to array
  49. ' -------------------------------------------------------------------------
  50. OPEN "MizejiciText.sav" FOR BINARY AS ff
  51. Load$ = SPACE$(LOF(ff))
  52. GET ff, , Load$ '                      compressed string
  53. Uncompressed$ = _INFLATE$(Load$)
  54. i = LEN(Uncompressed$)
  55. DIM ArrMEM AS _MEM
  56. ArrMEM = _MEMNEW(i)
  57. _MEMPUT ArrMEM, ArrMEM.OFFSET, Uncompressed$
  58. i = i \ 4
  59. REDIM B(i) AS Pojnt
  60. ii = 0
  61. DO UNTIL ii = i
  62.     B(ii).X = _MEMGET(ArrMEM, ArrMEM.OFFSET + fill, INTEGER)
  63.     B(ii).Y = _MEMGET(ArrMEM, ArrMEM.OFFSET + fill + 2, INTEGER)
  64.     fill = fill + 4
  65.     ii = ii + 1
  66. _MEMFREE ArrMEM
  67. '---------------------------------------------------------------------------
  68.  
  69. '-------------- DRAW IT ------------
  70. lenght = 1000
  71. j = 0
  72.     Shift = 255 / lenght
  73.     DO UNTIL j = i
  74.         IF k > lenght THEN
  75.             alfa = 0
  76.             FOR sm = j TO j - lenght STEP -1
  77.                 IF sm > -1 AND sm < i - 1 THEN CircleFill B(sm).X, B(sm).Y, 5, _RGBA32(0, 0, 20, alfa)
  78.                 alfa = alfa + Shift
  79.             NEXT
  80.             j = j + 1
  81.         END IF
  82.         k = k + 1
  83.         IF k <= i - 1 THEN CircleFill B(k).X, B(k).Y, 5, &HFFFF0000
  84.         _LIMIT 100
  85.     LOOP
  86.     CLS
  87.     j = 0
  88.     k = 0
  89.  
  90.  
  91.  
  92. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  93.     ' CX = center x coordinate
  94.     ' CY = center y coordinate
  95.     '  R = radius
  96.     '  C = fill color
  97.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  98.     DIM X AS INTEGER, Y AS INTEGER
  99.     Radius = ABS(R)
  100.     RadiusError = -Radius
  101.     X = Radius
  102.     Y = 0
  103.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  104.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  105.     WHILE X > Y
  106.         RadiusError = RadiusError + Y * 2 + 1
  107.         IF RadiusError >= 0 THEN
  108.             IF X <> Y + 1 THEN
  109.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  110.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  111.             END IF
  112.             X = X - 1
  113.             RadiusError = RadiusError - X * 2
  114.         END IF
  115.         Y = Y + 1
  116.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  117.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  118.     WEND
  119.  

* MizejiciText.sav (Filesize: 5.9 KB, Downloads: 239)

FellippeHeitor

  • Guest
Re: Disappearing drawing
« Reply #1 on: January 19, 2021, 03:21:31 pm »
Thank you! ❤️

And that's a very cool effect!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Disappearing drawing
« Reply #2 on: January 19, 2021, 03:45:15 pm »
@FellippeHeitor  Thank you :)