Author Topic: QuadDraw - Odd little drawing program.  (Read 5106 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
QuadDraw - Odd little drawing program.
« on: April 12, 2020, 10:04:52 pm »
Here's a quick little drawing program that draws in 4 sections of the screen at the same time.  After you draw your lines, you can fill the 4 sections (right click in them) at the same time.  Hard for me to explain it, you just have to try it I suppose.  Below is a sample of its limited capabilities, and my limited drawing skills.

- Dav

Note: Jump to latest version here:
https://www.qb64.org/forum/index.php?topic=2467.msg116978#msg116978

Code: QB64: [Select]
  1. '============
  2. 'QuadDraw.bas
  3. '============
  4. 'An odd little drawing program.
  5. 'Draws/paints in 4 sections of the screen at same time.
  6. 'Coded by Dav for QB64 APR/2020
  7.  
  8. 'Left click to draw on screen.
  9. 'Right click to fill enclosed sections with random color.
  10. 'Press space to clear screen and start over fresh.
  11.  
  12. SCREEN _NEWIMAGE(600, 600, 32)
  13.  
  14. cx = _WIDTH / 2: cy = _HEIGHT / 2 'center point of screen
  15.  
  16. w& = _RGB(255, 255, 255) 'used often, so variable it
  17. b& = _RGB(0, 0, 0)
  18.  
  19. PAINT (1, 1), w& 'start with white screen
  20.  
  21. 'show instruction at beginning
  22. PRINT "    Left click to draw, right click to fill color, space clears screen     "
  23.  
  24. size = 5 'size of circle (brush)
  25.  
  26.     t = _MOUSEINPUT
  27.     x = _MOUSEX: y = _MOUSEY
  28.  
  29.     'If left button, draw on screen
  30.         CIRCLE (x, y), size, b&: PAINT (x, y), b&, b&
  31.         CIRCLE (cx - x + cx, cy - y + cy), size, b&
  32.         PAINT (cx - x + cx, cy - y + cy), b&, b&
  33.         CIRCLE (x, cy - y + cy), size, b&
  34.         PAINT (x, cy - y + cy), b&, b&
  35.         CIRCLE (cx - x + cx, y), size, b&
  36.         PAINT (cx - x + cx, y), b&, b&
  37.     END IF
  38.     'if right click, fill sections with color
  39.         c = (RND * 100)
  40.         r = RND * 255: g = RND * 255: b = RND * 255
  41.         PAINT (x, y), _RGB(r, g, b), b&
  42.         PAINT (cx - x + cx, cy - y + cy), _RGB(r, g, b), b&
  43.         PAINT (x, cy - y + cy), _RGB(r, g, b), b&
  44.         PAINT (cx - x + cx, y), _RGB(r, g, b), b&
  45.         WHILE _MOUSEBUTTON(2) <> 0: n = _MOUSEINPUT: WEND
  46.     END IF
  47.     'scpace clears screen again
  48.     IF INKEY$ = CHR$(32) THEN CLS: PAINT (1, 1), w&
  49.  

 
quaddraw.jpg

 
stainedglass.jpg
« Last Edit: April 14, 2020, 09:11:11 pm by Dav »

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #1 on: April 12, 2020, 10:46:36 pm »
Cool, looks like stained glass.
In order to understand recursion, one must first understand recursion.

Offline gaslouk

  • Newbie
  • Posts: 29
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #2 on: April 12, 2020, 10:54:35 pm »
It's very good dav, I like it. :)
Untitled 13_4_2020 5_52_53 πμ.png
* Untitled 13_4_2020 5_52_53 πμ.png (Filesize: 36.98 KB, Dimensions: 600x600, Views: 265)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #3 on: April 13, 2020, 07:29:00 am »
With this, I can make some abstract art! :D
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #4 on: April 13, 2020, 12:02:37 pm »
The idea is brilliant. Nice work!

I was bothered by the points in the lines, so I adjusted it a bit.


Code: QB64: [Select]
  1. '============
  2. 'QuadDraw.bas
  3. '============
  4. 'An odd little drawing program.
  5. 'Draws/paints in 4 sections of the screen at same time.
  6. 'Coded by Dav for QB64 APR/2020
  7.  
  8. 'Left click to draw on screen.
  9. 'Right click to fill enclosed sections with random color.
  10. 'Press space to clear screen and start over fresh.
  11.  
  12. SCREEN _NEWIMAGE(600, 600, 32)
  13.  
  14. cx = _WIDTH / 2: cy = _HEIGHT / 2 'center point of screen
  15.  
  16. w~& = _RGB32(255, 255, 255) 'used often, so variable it
  17. b~& = _RGB32(0, 0, 0)
  18.  
  19. CLS , w~& 'start with white screen
  20.  
  21. 'show instruction at beginning
  22. PRINT "    Left click to draw, right click to fill color, space clears screen     "
  23.  
  24. size = 5 'size of circle (brush)
  25. NewColoredPen = swapColor(NIB, &HFFFFFFFF, b~&)
  26.  
  27.     t = _MOUSEINPUT
  28.     x = _MOUSEX: y = _MOUSEY
  29.  
  30.     'If left button, draw on screen
  31.  
  32.         _PUTIMAGE (x-11, y-11), NewColoredPen
  33.         _PUTIMAGE (cx - x + cx-11, cy - y + cy-11), NewColoredPen
  34.         _PUTIMAGE (x-11, cy - y + cy-11), NewColoredPen
  35.         _PUTIMAGE (cx - x + cx-11, y-11), NewColoredPen
  36.  
  37.     END IF
  38.     'if right click, fill sections with color
  39.         c = (RND * 100)
  40.         r = RND * 255: g = RND * 255: b = RND * 255
  41.         PAINT (x, y), _RGB32(r, g, b), b~&
  42.         PAINT (cx - x + cx, cy - y + cy), _RGB32(r, g, b), b~&
  43.         PAINT (x, cy - y + cy), _RGB32(r, g, b), b~&
  44.         PAINT (cx - x + cx, y), _RGB32(r, g, b), b~&
  45.         WHILE _MOUSEBUTTON(2) <> 0: n = _MOUSEINPUT: WEND
  46.     END IF
  47.     'scpace clears screen again
  48.     IF INKEY$ = CHR$(32) THEN CLS , w~&
  49.  
  50.     '    IF _MOUSEBUTTON(3) THEN
  51.     '    b~& = _RGB32(1 + RND * 255, 1 + RND * 254, 1 + RND * 255)
  52.     '    _FREEIMAGE NewColoredPen
  53.     '    NewColoredPen = swapColor(NIB, &HFFFFFFFF, b~&)
  54.     '    END IF
  55.  
  56.  
  57.     NIB = _NEWIMAGE(21, 21, 32)
  58.     _DEST NIB
  59.     CLS , &HFFFFFFFF
  60.     CIRCLE (10, 10), 10, &HFF000000
  61.     PAINT (10, 10), &HFF000000, &HFF000000
  62.     _CLEARCOLOR &HFFFFFFFF, NIB
  63.  
  64. FUNCTION swapColor& (oldHandle&, oldcolor~&, newcolor~&)
  65.     DIM m AS _MEM, c AS _UNSIGNED LONG
  66.     swapColor& = _COPYIMAGE(oldHandle&, 32)
  67.     _FREEIMAGE oldHandle&
  68.     m = _MEMIMAGE(swapColor)
  69.     DO UNTIL a& = m.SIZE - 4
  70.         a& = a& + 4
  71.         c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG)
  72.         IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  73.     LOOP
  74.     _MEMFREE m
  75.  

 
image.JPG

« Last Edit: April 13, 2020, 12:51:37 pm by Petr »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #5 on: April 13, 2020, 02:07:05 pm »
That program example looks like a real pane. A stained glass one.

I'll stick with SCREEN 0, because all I can draw is a conclusion.

Actually, it  reminds me of a cross between an Etch-a-Sketch and synchronized swimming. Very easy to use.

The designs posted took some effort.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #6 on: April 13, 2020, 02:31:01 pm »
Next version: Use mouse button 3 for pen color change. SUB SPAINT then solve coloring in different color borders.


Code: QB64: [Select]
  1. '============
  2. 'QuadDraw.bas
  3. '============
  4. 'An odd little drawing program.
  5. 'Draws/paints in 4 sections of the screen at same time.
  6. 'Coded by Dav for QB64 APR/2020
  7.  
  8. 'Left click to draw on screen.
  9. 'Right click to fill enclosed sections with random color.
  10. 'Press space to clear screen and start over fresh.
  11.  
  12. SCREEN _NEWIMAGE(600, 600, 32)
  13.  
  14. cx = _WIDTH / 2: cy = _HEIGHT / 2 'center point of screen
  15.  
  16. w~& = _RGB32(255, 255, 255) 'used often, so variable it
  17. b~& = _RGB32(0, 0, 0)
  18.  
  19. CLS , w~& 'start with white screen
  20.  
  21. 'show instruction at beginning
  22. PRINT "    Left click to draw, right click to fill color, space clears screen     "
  23.  
  24. size = 5 'size of circle (brush)
  25. NewColoredPen = swapColor(NIB, &HFF000000, b~&)
  26.  
  27.     t = _MOUSEINPUT
  28.     x = _MOUSEX: y = _MOUSEY
  29.  
  30.     'If left button, draw on screen
  31.  
  32.         _PUTIMAGE (x - 11, y - 11), NewColoredPen
  33.         _PUTIMAGE (cx - x + cx - 11, cy - y + cy - 11), NewColoredPen
  34.         _PUTIMAGE (x - 11, cy - y + cy - 11), NewColoredPen
  35.         _PUTIMAGE (cx - x + cx - 11, y - 11), NewColoredPen
  36.  
  37.     END IF
  38.     'if right click, fill sections with color
  39.         c = (RND * 100)
  40.         r = RND * 255: g = RND * 255: b = RND * 255
  41.         SPAINT x, y, _RGB32(r, g, b) '#, b~&
  42.         SPAINT cx - x + cx, cy - y + cy, _RGB32(r, g, b) ', b~&
  43.         SPAINT x, cy - y + cy, _RGB32(r, g, b) ', b~&
  44.         SPAINT cx - x + cx, y, _RGB32(r, g, b) ', b~&
  45.         WHILE _MOUSEBUTTON(2) <> 0: n = _MOUSEINPUT: WEND
  46.     END IF
  47.     'scpace clears screen again
  48.     IF INKEY$ = CHR$(32) THEN CLS , w~&
  49.  
  50.         b~& = _RGB32(1 + RND * 255, 1 + RND * 254, 1 + RND * 255)
  51.         _FREEIMAGE NewColoredPen
  52.         NewColoredPen = swapColor(NIB, &HFF000000, b~&)
  53.     END IF
  54.  
  55.  
  56. NIB = _NEWIMAGE(21, 21, 32)
  57. _DEST NIB
  58. CLS , &HFFFFFFFF
  59. CIRCLE (10, 10), 10, &HFF000000
  60. PAINT (10, 10), &HFF000000, &HFF000000
  61. _CLEARCOLOR &HFFFFFFFF, NIB
  62.  
  63. FUNCTION swapColor& (oldHandle&, oldcolor~&, newcolor~&)
  64. swapColor& = _COPYIMAGE(oldHandle&, 32)
  65. _FREEIMAGE oldHandle&
  66. m = _MEMIMAGE(swapColor)
  67. SELECT CASE _PIXELSIZE(swapColor&)
  68.     CASE 4
  69.         DO UNTIL a& = m.SIZE - 4
  70.             a& = a& + 4
  71.             c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG)
  72.             IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  73.         LOOP
  74.     CASE 1
  75.         DO UNTIL a& = m.SIZE - 1
  76.             a& = a& + 1
  77.             c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED _BYTE)
  78.             IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  79.         LOOP
  80.  
  81. SUB SPAINT (x AS INTEGER, y AS INTEGER, clr~&) 'Color everything in the X, Y position regardless of the border color.
  82. DIM m AS _MEM, m2 AS _MEM
  83.  
  84.  
  85.  
  86.     CASE 4 '                             image is 32 bit image
  87.         Virtual = _NEWIMAGE(W, H, 32)
  88.         m2 = _MEMIMAGE(Virtual)
  89.         Back~& = POINT(x, y)
  90.         Back2~& = _RGB32(1, 1, 1)
  91.         Empty~& = _RGBA32(0, 0, 0, 0)
  92.         DO UNTIL a& = m.SIZE - 4
  93.             a& = a& + 4
  94.             IF _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG) = Back~& THEN _MEMPUT m2, m2.OFFSET + a&, Back~& ELSE _MEMPUT m2, m2.OFFSET + a&, Back2~&
  95.         LOOP
  96.         d = _DEST
  97.         _DEST Virtual
  98.         PAINT (x, y), clr~&, Back2~&
  99.         _DEST d
  100.         a& = 0
  101.         DO UNTIL a& = m.SIZE - 4
  102.             a& = a& + 4
  103.             IF _MEMGET(m2, m2.OFFSET + a&, _UNSIGNED LONG) <> clr~& THEN _MEMPUT m2, m2.OFFSET + a&, Empty~&
  104.         LOOP
  105.         _CLEARCOLOR Back2~&, Virtual
  106.         _PUTIMAGE (0, 0), Virtual
  107.         _MEMFREE m
  108.         _MEMFREE m2
  109.         _FREEIMAGE Virtual
  110.     CASE 1 '                             image is 8 bit image (256 colors)
  111.         Virtual = _NEWIMAGE(W, H, 32)
  112.         m2 = _MEMIMAGE(Virtual)
  113.         Back~& = POINT(x, y)
  114.         Back2~& = _RGB(1, 1, 1)
  115.         Empty~& = _RGBA(0, 0, 0, 0)
  116.         DO UNTIL a& = m.SIZE - 1
  117.             a& = a& + 1
  118.             IF _MEMGET(m, m.OFFSET + a&, _UNSIGNED _BYTE) = Back~& THEN _MEMPUT m2, m2.OFFSET + a&, Back~& ELSE _MEMPUT m2, m2.OFFSET + a&, Back2~&
  119.         LOOP
  120.         d = _DEST
  121.         _DEST Virtual
  122.         PAINT (x, y), clr~&, Back2~&
  123.         _DEST d
  124.         a& = 0
  125.         DO UNTIL a& = m.SIZE - 1
  126.             a& = a& + 1
  127.             IF _MEMGET(m2, m2.OFFSET + a&, _UNSIGNED _BYTE) <> clr~& THEN _MEMPUT m2, m2.OFFSET + a&, Empty~&
  128.         LOOP
  129.         _CLEARCOLOR Back2~&, Virtual
  130.         _PUTIMAGE (0, 0), Virtual
  131.         _MEMFREE m
  132.         _MEMFREE m2
  133.         _FREEIMAGE Virtual
  134.  

 
image2.JPG

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #7 on: April 13, 2020, 09:33:37 pm »
Thanks for trying it out.  Glad you like it.

Nice additions, Petr!  I like them.  I was working up another version today using .png brushes, but I favor your versions better. Feel free to add your name to the code!

Sorry for replying to you all so late, the storms knocked off our power/internet last night and I had to come over to my dads today to check on him, check email, read forums, etc.  May be off for a few days I'm told, Ill be popping in less frequently.

Lol, Pete.  I always enjoy your humor.

- Dav

.
« Last Edit: April 13, 2020, 09:47:52 pm by Dav »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #8 on: April 14, 2020, 10:54:24 am »
Building on the great enhancements added by Petr, I've updated the program with more user control of settings to allow one to make more detailed drawings.

New:
1) You can now change brush size using keys +/-
2) You can specify how many quads to draw on, 1 to 4, by pressing keys 1,2,3,4.
3) Current settings are shown in programs TITLE bar.

With these changes you can make more than stained glass drawings

How about a QuadDraw art show?
 
- Dav

Code: QB64: [Select]
  1. '============
  2. 'QuadDraw.bas v1.1
  3. '============
  4. 'An odd little drawing program.
  5. 'Draws/paints in 4 sections of the screen at same time.
  6. 'Coded by Dav for QB64, APR/2020
  7.  
  8. 'CREDIT: Many code enhanchments by Petr.  Thanks Petr!
  9.  
  10. 'Follow this programs development here:
  11. 'https://www.qb64.org/forum/index.php?topic=2467.0
  12.  
  13. '----------
  14. 'HOW TO USE:
  15. '----------
  16.  
  17. 'Left click = draws on screen.
  18. 'Right click = fills with color.
  19. 'Middle click = sets new color
  20. 'Use the +/- keys to resize brush size (1 to 50 allowed)
  21. 'Press 1,2,3 or 4 to set how many quads to draw, default is 4.
  22. 'Space = clears screen and starts over.
  23. 'ESC = Ends program
  24.  
  25. SCREEN _NEWIMAGE(600, 600, 32)
  26.  
  27. cx = _WIDTH / 2: cy = _HEIGHT / 2 'center point of screen
  28.  
  29. w~& = _RGB32(255, 255, 255) 'used often, so variable it
  30. b~& = _RGB32(0, 0, 0)
  31.  
  32. CLS , w~& 'start with white screen
  33.  
  34. DIM SHARED size: size = 10 'size of circle (brush)
  35.  
  36. quads = 4 'defaut, use 4 drawing quads
  37.  
  38. '====
  39. main:
  40. '====
  41.  
  42. _TITLE "QuadDraw - Quads:" + STR$(quads) + "  Size:" + STR$(size)
  43.  
  44. NewColoredPen = swapColor(NIB, &HFF000000, b~&)
  45.  
  46.     t = _MOUSEINPUT
  47.     x = _MOUSEX: y = _MOUSEY
  48.  
  49.     'If left button, draw on screen
  50.         _PUTIMAGE (x - (size + 1), y - (size + 1)), NewColoredPen
  51.         IF quads > 1 THEN
  52.             _PUTIMAGE (cx - x + cx - (size + 1), cy - y + cy - (size + 1)), NewColoredPen
  53.         END IF
  54.         IF quads > 2 THEN
  55.             _PUTIMAGE (x - (size + 1), cy - y + cy - (size + 1)), NewColoredPen
  56.         END IF
  57.         IF quads > 3 THEN
  58.             _PUTIMAGE (cx - x + cx - (size + 1), y - (size + 1)), NewColoredPen
  59.         END IF
  60.     END IF
  61.  
  62.     'if right click, fill sections with color
  63.         r = RND * 255: g = RND * 255: b = RND * 255
  64.         SPAINT x, y, _RGB32(r, g, b) '#, b~&
  65.         IF quads > 1 THEN
  66.             SPAINT cx - x + cx, cy - y + cy, _RGB32(r, g, b) ', b~&
  67.         END IF
  68.         IF quads > 2 THEN
  69.             SPAINT x, cy - y + cy, _RGB32(r, g, b) ', b~&
  70.         END IF
  71.         IF quads > 3 THEN
  72.             SPAINT cx - x + cx, y, _RGB32(r, g, b) ', b~&
  73.         END IF
  74.         WHILE _MOUSEBUTTON(2) <> 0: n = _MOUSEINPUT: WEND
  75.     END IF
  76.  
  77.     'Select color
  78.         b~& = _RGB32(1 + RND * 255, 1 + RND * 254, 1 + RND * 255)
  79.         _FREEIMAGE NewColoredPen
  80.         NewColoredPen = swapColor(NIB, &HFF000000, b~&)
  81.     END IF
  82.  
  83.     'get keyboard input
  84.     key$ = INKEY$
  85.     IF key$ <> "" THEN
  86.         SELECT CASE key$
  87.             CASE CHR$(32): CLS , w~& 'scpace clears screen again
  88.             CASE "1": quads = 1
  89.             CASE "2": quads = 2
  90.             CASE "3": quads = 3
  91.             CASE "4": quads = 4
  92.             CASE "+"
  93.                 size = size + 1: IF size > 50 THEN size = 50
  94.             CASE "-"
  95.                 size = size - 1: IF size < 1 THEN size = 1
  96.             CASE CHR$(27): END
  97.         END SELECT
  98.         DO UNTIL INKEY$ = "": LOOP
  99.         GOTO main
  100.     END IF
  101.  
  102.     'FUNCTION by Petr
  103.     NIB = _NEWIMAGE(size * 2 + 1, size * 2 + 1, 32)
  104.     _DEST NIB
  105.     CLS , &HFFFFFFFF
  106.     CIRCLE (size, size), size, &HFF000000
  107.     PAINT (size, size), &HFF000000, &HFF000000
  108.     _CLEARCOLOR &HFFFFFFFF, NIB
  109.  
  110. FUNCTION swapColor& (oldHandle&, oldcolor~&, newcolor~&)
  111.     'FUNCTION by Petr
  112.     DIM m AS _MEM, c AS _UNSIGNED LONG
  113.     swapColor& = _COPYIMAGE(oldHandle&, 32)
  114.     _FREEIMAGE oldHandle&
  115.     m = _MEMIMAGE(swapColor)
  116.     SELECT CASE _PIXELSIZE(swapColor&)
  117.         CASE 4
  118.             DO UNTIL a& = m.SIZE - 4
  119.                 a& = a& + 4
  120.                 c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG)
  121.                 IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  122.             LOOP
  123.         CASE 1
  124.             DO UNTIL a& = m.SIZE - 1
  125.                 a& = a& + 1
  126.                 c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED _BYTE)
  127.                 IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  128.             LOOP
  129.     END SELECT
  130.     _MEMFREE m
  131.  
  132. SUB SPAINT (x AS INTEGER, y AS INTEGER, clr~&) 'Color everything in the X, Y position regardless of the border color.
  133.     'SUB by Petr
  134.     DIM m AS _MEM, m2 AS _MEM
  135.  
  136.     m = _MEMIMAGE(_DEST)
  137.     W = _WIDTH(_DEST)
  138.     H = _HEIGHT(_DEST)
  139.     P = _PIXELSIZE(_DEST)
  140.  
  141.  
  142.     SELECT CASE P
  143.         CASE 4 '                             image is 32 bit image
  144.             Virtual = _NEWIMAGE(W, H, 32)
  145.             m2 = _MEMIMAGE(Virtual)
  146.             Back~& = POINT(x, y)
  147.             Back2~& = _RGB32(1, 1, 1)
  148.             Empty~& = _RGBA32(0, 0, 0, 0)
  149.             DO UNTIL a& = m.SIZE - 4
  150.                 a& = a& + 4
  151.                 IF _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG) = Back~& THEN _MEMPUT m2, m2.OFFSET + a&, Back~& ELSE _MEMPUT m2, m2.OFFSET + a&, Back2~&
  152.             LOOP
  153.             d = _DEST
  154.             _DEST Virtual
  155.             PAINT (x, y), clr~&, Back2~&
  156.             _DEST d
  157.             a& = 0
  158.             DO UNTIL a& = m.SIZE - 4
  159.                 a& = a& + 4
  160.                 IF _MEMGET(m2, m2.OFFSET + a&, _UNSIGNED LONG) <> clr~& THEN _MEMPUT m2, m2.OFFSET + a&, Empty~&
  161.             LOOP
  162.             _CLEARCOLOR Back2~&, Virtual
  163.             _PUTIMAGE (0, 0), Virtual
  164.             _MEMFREE m
  165.             _MEMFREE m2
  166.             _FREEIMAGE Virtual
  167.         CASE 1 '                             image is 8 bit image (256 colors)
  168.             Virtual = _NEWIMAGE(W, H, 32)
  169.             m2 = _MEMIMAGE(Virtual)
  170.             Back~& = POINT(x, y)
  171.             Back2~& = _RGB(1, 1, 1)
  172.             Empty~& = _RGBA(0, 0, 0, 0)
  173.             DO UNTIL a& = m.SIZE - 1
  174.                 a& = a& + 1
  175.                 IF _MEMGET(m, m.OFFSET + a&, _UNSIGNED _BYTE) = Back~& THEN _MEMPUT m2, m2.OFFSET + a&, Back~& ELSE _MEMPUT m2, m2.OFFSET + a&, Back2~&
  176.             LOOP
  177.             d = _DEST
  178.             _DEST Virtual
  179.             PAINT (x, y), clr~&, Back2~&
  180.             _DEST d
  181.             a& = 0
  182.             DO UNTIL a& = m.SIZE - 1
  183.                 a& = a& + 1
  184.                 IF _MEMGET(m2, m2.OFFSET + a&, _UNSIGNED _BYTE) <> clr~& THEN _MEMPUT m2, m2.OFFSET + a&, Empty~&
  185.             LOOP
  186.             _CLEARCOLOR Back2~&, Virtual
  187.             _PUTIMAGE (0, 0), Virtual
  188.             _MEMFREE m
  189.             _MEMFREE m2
  190.             _FREEIMAGE Virtual
  191.     END SELECT
  192.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #9 on: April 14, 2020, 11:42:43 am »
Nice work, Dav!

 
image3.JPG

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #10 on: April 14, 2020, 11:50:59 am »
Hi
I think to observe the thread to see how far this demo will grow up.

I remember a similar paint game on android. Well done and good enanchments for now.
Go on great Dav and Petr.
Programming isn't difficult, only it's  consuming time and coffee

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #11 on: April 14, 2020, 09:10:11 pm »
Small update...Added an UNDO last change - Press U to do an UNDO.  A little needed function (for me at least).

- Dav

Code: QB64: [Select]
  1. '============
  2. 'QuadDraw.bas v1.2
  3. '============
  4. 'An odd little drawing program.
  5. 'Draws/paints in 4 sections of the screen at same time.
  6. 'Coded by Dav for QB64, APR/2020
  7.  
  8. 'CREDIT: Many code enhanchments by Petr.  Thanks Petr!
  9.  
  10. 'Follow this programs development here:
  11. 'https://www.qb64.org/forum/index.php?topic=2467.0
  12.  
  13. 'Added: UNDO last change by pressing U
  14.  
  15. '----------
  16. 'HOW TO USE:
  17. '----------
  18.  
  19. 'Left click = draws on screen.
  20. 'Right click = fills with color.
  21. 'Middle click = sets new color
  22. 'Use the +/- keys to resize brush size (1 to 50 allowed)
  23. 'Press 1,2,3 or 4 to set how many quads to draw, default is 4.
  24. 'Press U to undo last change
  25. 'Space = clears screen and starts over.
  26. 'ESC = Ends program
  27.  
  28. SCREEN _NEWIMAGE(600, 600, 32)
  29.  
  30. cx = _WIDTH / 2: cy = _HEIGHT / 2 'center point of screen
  31.  
  32. w~& = _RGB32(255, 255, 255) 'used often, so variable it
  33. b~& = _RGB32(0, 0, 0)
  34.  
  35. CLS , w~& 'start with white screen
  36.  
  37.  
  38. DIM SHARED size: size = 10 'size of circle (brush)
  39.  
  40. quads = 4 'defaut, use 4 drawing quads
  41.  
  42. '====
  43. main:
  44. '====
  45.  
  46. _TITLE "QuadDraw - Quads:" + STR$(quads) + "  Size:" + STR$(size)
  47.  
  48. NewColoredPen = swapColor(NIB, &HFF000000, b~&)
  49.  
  50.     t = _MOUSEINPUT
  51.     x = _MOUSEX: y = _MOUSEY
  52.  
  53.     'If left button, draw on screen
  54.  
  55.         undo& = _COPYIMAGE(_DISPLAY)
  56.  
  57.         DO
  58.             t = _MOUSEINPUT
  59.             x = _MOUSEX: y = _MOUSEY
  60.  
  61.             _PUTIMAGE (x - (size + 1), y - (size + 1)), NewColoredPen
  62.             IF quads > 1 THEN
  63.                 _PUTIMAGE (cx - x + cx - (size + 1), cy - y + cy - (size + 1)), NewColoredPen
  64.             END IF
  65.             IF quads > 2 THEN
  66.                 _PUTIMAGE (x - (size + 1), cy - y + cy - (size + 1)), NewColoredPen
  67.             END IF
  68.             IF quads > 3 THEN
  69.                 _PUTIMAGE (cx - x + cx - (size + 1), y - (size + 1)), NewColoredPen
  70.             END IF
  71.         LOOP UNTIL _MOUSEBUTTON(1) = 0
  72.  
  73.     END IF
  74.  
  75.     'if right click, fill sections with color
  76.  
  77.         undo& = _COPYIMAGE(_DISPLAY)
  78.  
  79.         r = RND * 255: g = RND * 255: b = RND * 255
  80.         SPAINT x, y, _RGB32(r, g, b) '#, b~&
  81.         IF quads > 1 THEN
  82.             SPAINT cx - x + cx, cy - y + cy, _RGB32(r, g, b) ', b~&
  83.         END IF
  84.         IF quads > 2 THEN
  85.             SPAINT x, cy - y + cy, _RGB32(r, g, b) ', b~&
  86.         END IF
  87.         IF quads > 3 THEN
  88.             SPAINT cx - x + cx, y, _RGB32(r, g, b) ', b~&
  89.         END IF
  90.         WHILE _MOUSEBUTTON(2) <> 0: n = _MOUSEINPUT: WEND
  91.     END IF
  92.  
  93.     'Select color
  94.         b~& = _RGB32(1 + RND * 255, 1 + RND * 254, 1 + RND * 255)
  95.         _FREEIMAGE NewColoredPen
  96.         NewColoredPen = swapColor(NIB, &HFF000000, b~&)
  97.     END IF
  98.  
  99.     'get keyboard input
  100.     key$ = UCASE$(INKEY$)
  101.     IF key$ <> "" THEN
  102.         SELECT CASE key$
  103.             CASE CHR$(32): CLS , w~& 'scpace clears screen again
  104.             CASE "1": quads = 1
  105.             CASE "2": quads = 2
  106.             CASE "3": quads = 3
  107.             CASE "4": quads = 4
  108.             CASE "+"
  109.                 size = size + 1: IF size > 50 THEN size = 50
  110.             CASE "-"
  111.                 size = size - 1: IF size < 1 THEN size = 1
  112.             CASE "U": _PUTIMAGE (0, 0), undo&
  113.             CASE CHR$(27): END
  114.         END SELECT
  115.         DO UNTIL INKEY$ = "": LOOP
  116.         GOTO main
  117.     END IF
  118.  
  119.  
  120.  
  121.     'FUNCTION by Petr
  122.     NIB = _NEWIMAGE(size * 2 + 1, size * 2 + 1, 32)
  123.     _DEST NIB
  124.     CLS , &HFFFFFFFF
  125.     CIRCLE (size, size), size, &HFF000000
  126.     PAINT (size, size), &HFF000000, &HFF000000
  127.     _CLEARCOLOR &HFFFFFFFF, NIB
  128.  
  129. FUNCTION swapColor& (oldHandle&, oldcolor~&, newcolor~&)
  130.     'FUNCTION by Petr
  131.     DIM m AS _MEM, c AS _UNSIGNED LONG
  132.     swapColor& = _COPYIMAGE(oldHandle&, 32)
  133.     _FREEIMAGE oldHandle&
  134.     m = _MEMIMAGE(swapColor)
  135.     SELECT CASE _PIXELSIZE(swapColor&)
  136.         CASE 4
  137.             DO UNTIL a& = m.SIZE - 4
  138.                 a& = a& + 4
  139.                 c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG)
  140.                 IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  141.             LOOP
  142.         CASE 1
  143.             DO UNTIL a& = m.SIZE - 1
  144.                 a& = a& + 1
  145.                 c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED _BYTE)
  146.                 IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  147.             LOOP
  148.     END SELECT
  149.     _MEMFREE m
  150.  
  151. SUB SPAINT (x AS INTEGER, y AS INTEGER, clr~&) 'Color everything in the X, Y position regardless of the border color.
  152.     'SUB by Petr
  153.     DIM m AS _MEM, m2 AS _MEM
  154.  
  155.     m = _MEMIMAGE(_DEST)
  156.     W = _WIDTH(_DEST)
  157.     H = _HEIGHT(_DEST)
  158.     P = _PIXELSIZE(_DEST)
  159.  
  160.  
  161.     SELECT CASE P
  162.         CASE 4 '                             image is 32 bit image
  163.             Virtual = _NEWIMAGE(W, H, 32)
  164.             m2 = _MEMIMAGE(Virtual)
  165.             Back~& = POINT(x, y)
  166.             Back2~& = _RGB32(1, 1, 1)
  167.             Empty~& = _RGBA32(0, 0, 0, 0)
  168.             DO UNTIL a& = m.SIZE - 4
  169.                 a& = a& + 4
  170.                 IF _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG) = Back~& THEN _MEMPUT m2, m2.OFFSET + a&, Back~& ELSE _MEMPUT m2, m2.OFFSET + a&, Back2~&
  171.             LOOP
  172.             d = _DEST
  173.             _DEST Virtual
  174.             PAINT (x, y), clr~&, Back2~&
  175.             _DEST d
  176.             a& = 0
  177.             DO UNTIL a& = m.SIZE - 4
  178.                 a& = a& + 4
  179.                 IF _MEMGET(m2, m2.OFFSET + a&, _UNSIGNED LONG) <> clr~& THEN _MEMPUT m2, m2.OFFSET + a&, Empty~&
  180.             LOOP
  181.             _CLEARCOLOR Back2~&, Virtual
  182.             _PUTIMAGE (0, 0), Virtual
  183.             _MEMFREE m
  184.             _MEMFREE m2
  185.             _FREEIMAGE Virtual
  186.         CASE 1 '                             image is 8 bit image (256 colors)
  187.             Virtual = _NEWIMAGE(W, H, 32)
  188.             m2 = _MEMIMAGE(Virtual)
  189.             Back~& = POINT(x, y)
  190.             Back2~& = _RGB(1, 1, 1)
  191.             Empty~& = _RGBA(0, 0, 0, 0)
  192.             DO UNTIL a& = m.SIZE - 1
  193.                 a& = a& + 1
  194.                 IF _MEMGET(m, m.OFFSET + a&, _UNSIGNED _BYTE) = Back~& THEN _MEMPUT m2, m2.OFFSET + a&, Back~& ELSE _MEMPUT m2, m2.OFFSET + a&, Back2~&
  195.             LOOP
  196.             d = _DEST
  197.             _DEST Virtual
  198.             PAINT (x, y), clr~&, Back2~&
  199.             _DEST d
  200.             a& = 0
  201.             DO UNTIL a& = m.SIZE - 1
  202.                 a& = a& + 1
  203.                 IF _MEMGET(m2, m2.OFFSET + a&, _UNSIGNED _BYTE) <> clr~& THEN _MEMPUT m2, m2.OFFSET + a&, Empty~&
  204.             LOOP
  205.             _CLEARCOLOR Back2~&, Virtual
  206.             _PUTIMAGE (0, 0), Virtual
  207.             _MEMFREE m
  208.             _MEMFREE m2
  209.             _FREEIMAGE Virtual
  210.     END SELECT
  211.  
  212.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: QuadDraw - Odd little drawing program.
« Reply #12 on: April 15, 2020, 06:20:27 pm »
You come up with some of the neatest, fun ideas for programs. They're always worth a look see.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Programming isn't difficult, only it's  consuming time and coffee