Author Topic: Very light alternative to PAINT  (Read 1000 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
Very light alternative to PAINT
« on: May 30, 2020, 03:52:40 pm »
Hi,

 In the beginning was Cobalt. He had a problem with the program. I couldn't find a problem either. Then came BPlus. And there was light. BPlus showed a recursive function and I sat on my ass.

As soon as he showed it in this thread https://www.qb64.org/forum/index.php?topic=2645.msg118600#msg118600
so I remembered my coloring program. It forms so quickly with recursion! I tried an old condition that I had in the original program: Color borders do not have to be the same color. And it works!

Code: QB64: [Select]
  1. o = _NEWIMAGE(320, 240, 256)
  2.  
  3. FOR x = 160 TO 0 STEP -50
  4.     LINE (x, x)-(x + 50, x + 50), 255 * RND, BF
  5.     LINE (x, x)-(x - 50, x + 50), 255 * RND, B
  6.     LINE (160 - x, 120 - x)-(x + 50, x - 50), 255 * RND, BF
  7.     CIRCLE (160, 120), x, 255 * RND
  8.  
  9.     IF _MOUSEBUTTON(1) = -1 THEN
  10.         Colorize _MOUSEX, _MOUSEY, 14
  11.     END IF
  12.  
  13. SUB Colorize (x, y, newc)
  14.     c = POINT(x, y)
  15.     IF c = newc THEN EXIT SUB
  16.     Find x, y, c
  17.  
  18. SUB Find (x, y, c) 'c is background color, which is rewrited
  19.     IF POINT(x, y) = c THEN
  20.         PSET (x, y), 14
  21.         Xp = x + 1: IF Xp > _WIDTH THEN Xp = _WIDTH
  22.         Xm = x - 1: IF Xm < 0 THEN Xm = 0
  23.         Yp = y + 1: IF Yp > _HEIGHT THEN Yp = _HEIGHT
  24.         Ym = y - 1: IF Ym < 0 THEN Ym = 0
  25.         Find Xp, y, c
  26.         Find Xm, y, c
  27.         Find x, Yp, c
  28.         Find x, Ym, c
  29.     END IF
  30.  
« Last Edit: May 30, 2020, 03:54:44 pm by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Very light alternative to PAINT
« Reply #1 on: May 31, 2020, 10:06:01 am »
Very nice use of recursion. :D
« Last Edit: May 31, 2020, 11:49:42 pm by Ashish »
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 SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Very light alternative to PAINT
« Reply #2 on: May 31, 2020, 03:37:38 pm »
Wow I never knew this either! Am trying to study it but will have to kinda tear it apart to figure out what some of this means.
Also by the way, if you don't know already, you don't need 2 lines for your first 2 lines you have there, just 1. All you need is this:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(320, 240, 256)