Drawing text along wavy paths...

I've always found the programmatic generation of images to be great fun!

This was a fun task for people getting to grips with JustBASIC ( or Liberty BASIC), suggested by Rod, administrator and frequent contributor.

LB allows extra niceties- such as transparent backgounds for each letter, and rotating the orientation of the letters. Then you can make animations that REALLY wave around.Left as an 'exercise for the reader'!

The first code generates the chosen text character-by-character along a sine-wave line. The other variation is one where instead the path is a r-theta spiral with decreasing font size. I suppose I could add random font choice too!

Note the time delay can be remmed-out, and there is a button to save nice results as a bitmap image with a name based on the current time. Other frills easily added.


Sine/cosine wave version

nomainwin

WindowWidth  =600
WindowHeight =640

graphicbox #w.gb, 40, 40, 500, 500
button #w.b1. "Draw Me", [drawMe], LR, 280, 20
button #w.b2. "Save Me", [saveMe], LR, 180, 20
button #w.b3. " QUIT ",  [quit],   LR,  80, 20

text$ ="tenochtitlanuk on diga.me.uk!"
Lng   =len( text$)
pi    =3.14159265

open "Spiral text" for window as #w

#w "trapclose [quit]"
#w.gb "down ; fill 100 100 100"

wait

[drawMe]
x        =  0                     '   x-position at start
c$       =randomCol$()            '   generate RGB string for a random colour
i        =  1                     '   position of character in the string
radius   =240                     '   radius from centre
fSize    = 60                     '   initial font size
stepAngle=10 +20 *rnd( 1)         '   angle per step

xOld =250: yOld =250 +radius

#w.gb "backcolor "; c$
#w.gb "font arial "; fSize; " bold"
#w.gb "fill "; c$                 '   rem out if want different letter- and box background colour

#w.gb "up ; goto 250 "; 250 +radius; " ; down"

for theta =0 to 3600 step stepAngle         '   1 to len( text$)
    x =250 +radius *sin( theta *pi /180)    '   specify x & y from radius and angle ( radians)
    y =250 +radius *cos( theta *pi /180)

    #w.gb "place "; x; " "; y
    #w.gb "color "; randomCol$()
    #w.gb "\"; mid$( text$, i, 1)

    i       =i +1: if i >Lng then i =1      '   keep cycling through the characters
    radius  =radius *0.980                  '   decrease the radius...
    fSize   =fSize  *0.970                  '      ... and the font size
    if fSize <6 then fSize =6
    #w.gb "font arial "; int( fSize); " bold"

    #w.gb "color black ; down ; line "; xOld; " "; yOld; " "; x; " "; y
    xOld =x: yOld =y

    timer 40, [onward]                      '   delete this delay for fast results!
    wait
    [onward]
    timer 0
next theta

wait

[quit]
close #w
end

[saveMe]
    #w.gb, "getbmp gb 0 0 500 500"
    bmpsave "gb", "demo" +str$( time$( "seconds")) +".bmp"
wait

function randomCol$()   '   returns random amounts of RGB
    randomCol$ =str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1)))
    print randomCol$
end function

Here's the spirals version.


nomainwin

WindowWidth  =600
WindowHeight =640

graphicbox #w.gb, 40, 40, 500, 500
button #w.b1. "Draw Me", [drawMe], LR, 280, 20
button #w.b2. "Save Me", [saveMe], LR, 180, 20
button #w.b3. " QUIT ",  [quit],   LR,  80, 20

text$ ="tenochtitlanuk on diga.me.uk!"
Lng   =len( text$)
pi    =3.14159265

open "Spiral text" for window as #w

#w "trapclose [quit]"
#w.gb "down ; fill 100 100 100"

wait

[drawMe]
x        =  0                     '   x-position at start
c$       =randomCol$()            '   generate RGB string for a random colour
i        =  1                     '   position of character in the string
radius   =240                     '   radius from centre
fSize    = 60                     '   initial font size
stepAngle=10 +20 *rnd( 1)         '   angle per step

xOld =250: yOld =250 +radius

#w.gb "backcolor "; c$
#w.gb "font arial "; fSize; " bold"
#w.gb "fill "; c$                 '   rem out if want different letter- and box background colour

#w.gb "up ; goto 250 "; 250 +radius; " ; down"

for theta =0 to 3600 step stepAngle         '   1 to len( text$)
    x =250 +radius *sin( theta *pi /180)    '   specify x & y from radius and angle ( radians)
    y =250 +radius *cos( theta *pi /180)

    #w.gb "place "; x; " "; y
    #w.gb "color "; randomCol$()
    #w.gb "\"; mid$( text$, i, 1)

    i       =i +1: if i >Lng then i =1      '   keep cycling through the characters
    radius  =radius *0.980                  '   decrease the radius...
    fSize   =fSize  *0.970                  '      ... and the font size
    if fSize <6 then fSize =6
    #w.gb "font arial "; int( fSize); " bold"

    #w.gb "color black ; down ; line "; xOld; " "; yOld; " "; x; " "; y
    xOld =x: yOld =y

    timer 40, [onward]                      '   delete this delay for fast results!
    wait
    [onward]
    timer 0
next theta

wait

[quit]
close #w
end

[saveMe]
    #w.gb, "getbmp gb 0 0 500 500"
    bmpsave "gb", "demo" +str$( time$( "seconds")) +".bmp"
wait

function randomCol$()   '   returns random amounts of RGB
    randomCol$ =str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1)))
    print randomCol$
end function

I'm looking forward to other people's responses! e-mail me if you want further explanation of wehat's being done here.