QB64.org Forum
Active Forums => Programs => Topic started by: Petr 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!
LINE (x
, x
)-(x
+ 50, x
+ 50), 255 * RND, BF
LINE (x
, x
)-(x
- 50, x
+ 50), 255 * RND, B
LINE (160 - x
, 120 - x
)-(x
+ 50, x
- 50), 255 * RND, BF
SUB Colorize
(x
, y
, newc
) Find x, y, c
SUB Find
(x
, y
, c
) 'c is background color, which is rewrited Xm
= x
- 1:
IF Xm
< 0 THEN Xm
= 0 Ym
= y
- 1:
IF Ym
< 0 THEN Ym
= 0 Find Xp, y, c
Find Xm, y, c
Find x, Yp, c
Find x, Ym, c
-
Very nice use of recursion. :D
-
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: