Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive Stuff Is Recursive Is Recursive is...
#31
Quote:Admin/mod, there seems to be a problem... I don't see an edit button beside Z!re's posts. :lol:
Hahaha =) poor you =)
Reply
#32
Quote:
Code:
SUB MakeRecursiveFunction(kind)
    code(kind)
    if AllKindsDone THEN RETURN -1
    FUNCTION=MakeRecursiveFunction(NewKind)
END SUB

Needless to say, I have found out the magic of recursive functions and am still learning, lol. As well as that Koch Curve, I made two filling functions, one of which works on only circles and the other which doesn't like large areas.

Keep this one in a small shape Wink
Code:
screenres 640,480
declare sub fill(x AS INTEGER, y AS INTEGER,c AS INTEGER)
circle (320,240),92,1
fill(320,240,1)
sleep
sub fill(x AS INTEGER, y AS INTEGER,c)
    if point(x,y)<>0 THEN EXIT SUB  
    PSET(x,y),c
    fill(x-1,y,c)
    fill(x,y+1,c)
    fill(x+1,y,c)
    fill(x,y-1,c)
end sub

[/code]

Well I tried that but it only fills if the c is greater then 0 and only fills areas that are color 0, how can that be changed?
Reply
#33
Quote:Well I tried that but it only fills if the c is greater then 0 and only fills areas that are color 0, how can that be changed?

This should work. The last argument of the sub is what color you want to fill. However, as was stated above, recursive functions take a lot of memory and aren't necessarily the best way to do this. As you will find, this code wont fill a shape thats much bigger than the one already there.

Code:
declare sub fill(x AS INTEGER, y AS INTEGER,c AS INTEGER, fc AS INTEGER)
screenres 640,480
circle (320,240),82,1
fill(320,240,1,0)
sleep
fill(320,240,4,1)
sleep
sub fill(x AS INTEGER, y AS INTEGER,c, fc)
    IF fc=c THEN EXIT SUB
    IF POINT(x,y)<>fc THEN EXIT SUB  
    PSET(x,y),c
    fill(x-1,y,c,fc)
    fill(x,y+1,c,fc)
    fill(x+1,y,c,fc)
    fill(x,y-1,c,fc)
end sub
[Image: freebasic.png]
Reply
#34
Code:
declare sub fill(x AS INTEGER, y AS INTEGER,c AS INTEGER, fc AS INTEGER)

'x = x coordinate
'y = y coordinate
'c = color to fill with
'fc = color to replace

fill(x%,y%,colour%,point (x%,y%))
sleep
sub fill(x AS INTEGER, y AS INTEGER,c, fc)
    IF fc=c THEN EXIT SUB
    IF POINT(x,y)<>fc THEN EXIT SUB  
    PSET(x,y),c
    fill(x-1,y,c,fc)
    fill(x,y+1,c,fc)
    fill(x+1,y,c,fc)
    fill(x,y-1,c,fc)
end sub

Well this is what I did and it works perfectly, exactly like the Fill funstion in Ms Paint.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)