# Peano space-filling curve- a Rosetta Code task.

An interesting prescription to generate a line between two points- here at bottom left and right- that gets longer and longer, and never crosses itself. Eventually ( 'at infinity') it fills the square space. here are a whole range of such Peano curves. For the next resolution up you'd need a graphic near 3000 by 3000 and computation time gets rather long...

If you draw always in one colour, you end with a square of that colour via finer/more wriggly lines. Boring finish! So I added a cycling of colours and was pleased with the result!

## Code

One of a number of variations.

```
'   Rosetta Code -Peano Curve

'   http://rosettacode.org/wiki/Peano_curve

'   Produce a graphical representation of a Peano curve of at least order 3.

global c:     c     =0  '   for colour-sequencing drama!
global n:     n     =5
global order': order =3^n
global p

nomainwin

WindowWidth  =850
WindowHeight =780

open "Peano curve RC" for graphics_nsb as #wg

#wg "trapclose quit"
#wg "goto 5 745 ; down ; fill darkblue ; color cyan ; flush"
#wg "font 48"
'#wg "size "; n^2

for p =1 to 6
#wg "cls ; fill darkblue ; up ; goto 780 60 ; down ; color red ; backcolor darkblue"
#wg "\" +str\$( p)
#wg "up ; goto 5 745 ; down"
order   =3^p
call Peano 0, 0, order, 0, 0

timer 2000, [k]
wait
[k]
timer 0

#wg "flush ; getbmp scr 1 1 850 780"
bmpsave "scr", "screens/Peano" +str\$( p) +".bmp"

next p

#wg "flush"

wait

sub quit h\$
close #wg
end
end sub

sub Peano x, y, lg, i1, i2
scan
if lg = 1 then
r\$  =str\$( int( 55 +200 *( ( 1 +cos( c /530)) /2)))
g\$  =str\$( int( 55 +200 *( ( 1 +sin( c / 67)) /2)))
b\$  =str\$( int( 55 +200 *( ( 1 +cos( c / 47)) /2)))
#wg "color "; r\$; " "; g\$; " "; b\$
'#wg "color cyan"
xS      =x *243 *3 /3^p
yS      =y *243 *3 /3^p
#wg "goto "; int( 5 +xS); " "; 745 -int( yS)
c   =c +0.1
exit sub
end if

lg  =lg / 3

call Peano x + (2 * i1 * lg),        y + (2 * i1 * lg),          lg,     i1,         i2
call Peano x + ((i1 - i2 + 1) * lg), y + ((i1 + i2) * lg),       lg,     i1,         1 - i2
call Peano x + lg,                   y + lg,                     lg,     i1,         1 - i2
call Peano x + ((i1 + i2) * lg),     y + ((i1 - i2 + 1) * lg),   lg,     1 - i1,     1 - i2
call Peano x + (2 * i2 * lg),        y + (2 * (1 - i2) * lg),    lg,     i1,         i2
call Peano x + ((1 + i2 - i1) * lg), y + ((2 - i1 - i2) * lg),   lg,     i1,         i2
call Peano x + (2 * (1 - i1) * lg),  y + (2 * (1 - i1) * lg),    lg,     i1,         i2
call Peano x + ((2 - i1 - i2) * lg), y + ((1 + i2 - i1) * lg),   lg,     1 - i1,     i2
call Peano x + (2 * (1 - i2) * lg),  y + (2 * i2 * lg),          lg,     1 - i1,     i2
End Sub

```