fig example programs 2017

##########  arrlen.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

function re(z p)
    f = z ; split(f p) ; join(f "") ; return(f)
    fig

forin (p stdin)
    cr = 13 ; chr
    lf = 10 ; chr
    z = p ; re(z cr) ; re(z lf)
    p = z ; len ; prints ; " " ; prints
    p = z ; print
    next


##########  az.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

x : arr  : times 5
y : arr  : times 2
x : plus : y print
## arrays dont auto-zero


##########  c.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

python 
    def figpset(z, x, y, c): 
        figlocate(0, y, x)
        figcolortext(0, c)
        figprints("*")
    fig

for co 1 51 1
    xx randint 1 800
    yy randint 1 600
    c randint 9 14 

    for p -314 314 1
        xs p cos times 40 int plus xx
        ys p sin times 40 int plus yy 
        z pset xs ys c
        next
    next

x lineinput
##########  cat.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

python 
    def figpset(z, x, y, c): 
        figlocate(0, y, x)
        figcolortext(0, c)
        figprints("*")
    fig

function draw oldx oldy x y c
    z pset oldx oldy 0
    z pset x y c
    fig
x
y

function ri u l
    z randint u l return z
    fig

python
    draw(1,1,1,1,0)
    while 1:
        bx = x ; by = y
        d = [(1,1), (1,-1), (-1,1), (-1,-1)][ri(0, 3)]
        x += d[0] ; y += d[1]
        
        if x < 1: x = 1
        if y < 1: y = 1         if y > 80: y = 80
        if y > 80: y = 80
        draw(bx,by,x,y,10)
        figsleep(0,0.1)
    fig


##########  center.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 
width = 80
 text = "this text will center"
 quot = 34  chr
  txt = split text "'"  join txt quot  split txt " "

## center each ##
forin p txt
    half = p  len  times -1  plus width  divby 2  int  
      sp = " "  times half  prints
     now = p  print
    next
##########  dec.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

z : "type multiple lines of text, then ctrl-d to quit." print
z : "(windows users may need to use ctrl-c)" print
z : arrstdin
z : print


##########  dt.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

z "waiting 5 seconds..." print sleep 5
z "the date is: " prints date print
z "there are: " prints timer prints " sec. elapsed since 12:00:00 am" print
z "the time is: " prints time print


##########  edarr.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

ed arr plus 5
ed plus 7
ed print
ed arropen "edarr.fig" print


##########  efig1.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 
#
for cb 0 7 1

    for f 0 15 1
        z colortext f
        z f highlight cb prints
        next

    z "" highlight 0 print
    next 







##########  f.fig  ##########

# diagram may 2015
#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 
function spr p
    px get p #### http://creativecommons.org/publicdomain/zero/1.0/
    forin t px
    ifequal t "*"
        z " " highlight 5 prints highlight 0  
        else
        ifequal t "="
            z " " highlight 1 prints highlight 0
            else 
                s "'"
                ifequal t " "
                    z t prints
                else
                    z t split z "_" join z " " swap z t 
                    q 34 chr colortext 15
                    z t split z "'" join z q highlight 5 prints highlight 0
                    z colortext 7
                    fig
            fig
        fig
    nextin
    z "" print
    fig

p "  **********         *********************         *************    " spr p
p "  *_________**       *____________________**       *____________**  " spr p
p "  *____p______**=====*___'hello_world'______**=====*___print______**" spr p
p "  *_________**       *____________________**       *____________**  " spr p
p "  **********         *********************         *************    " spr p

#p "mtpaint -s # grab screencap" shell

#p "hello" mid 2 1 print
#p "HELLO" mid 2 2 print
#pppp print lineinput prints prints print print 
#p1 "okay" print













##########  figcolor.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

p 5.7  print  colortext 2 
t -12  print  
black        0 
blue         1 
green        2 
cyan         3 
red          4 
magenta      5 
brown        6 
white        7 
gray         8 
lightblue    9 
lightgreen  10 
lightcyan   11 
lightred    12 
pink        13 
yellow      14 
brightwhite 15 

p 5  colortext pink  print

while                                
    rcol  randint 1 15                   
    now "hello "  colortext rcol  prints 
    wend 


##########  figg.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

#!./fig
p "hello, world!" left 5 ucase locate 5 7 prints # comment
x int plus 5 times 7 colortext 11 highlight 1 prints 
y 32 highlight 0 colortext 10 chr prints 

while 

    y 10 print # these indents are optional, they don't do anything 

    iftrue y 
        # this command breaks from while, never from if:
        break 
        fig 

    wend 


##########  figp.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

function printhello
    #z cls # clear screen
    z "hello world" print
    fig
python
    # inline python feature
    for p in range(5):
        printhello()
    fig
z = "hello world, how are you today?" ; split(z, " ") ; print
z "hello world, how are you today?" split z " " print


##########  file.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

john "/tmp/readme" plus ".txt" open "w"
cleese "/tmp/readme2.txt" lcase open "w"

x john #open "w"
x cleese #open "w"

for z 1 5 1
    x z fprint john
    x z times 10 fprint "/tmp/readme2.txt"
    next

x john close prints ":closed" print
x cleese close prints ":closed" print

x "ok" print
x cleese open "r" 
z flineinput cleese prints "*" print
z flineinput cleese prints "*" print
z flineinput cleese prints "*" print
z flineinput cleese prints "*" print
z flineinput cleese prints "*" print
z flineinput cleese prints "*" print
x cleese close prints ":closed" print
x lineinput cls print







##########  funcs.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

function cheese x
    z x minus 1
    for r 0 z 1
        p r print 
        next
    fig

z cheese 5


##########  ge.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

x arr
x arrset 1 "hi"
z arrget x 1 print


##########  hello.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

forin x "hello!"
    z x print
    nextin


##########  hw.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

    # fig
    m = "hello, world!" ; print ; right(12)
    forin x, m
    z = x ; print
    next


##########  ins.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

x : "hey" : instr x "e" print


##########  meh.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

x = "hello, world" : left(2) : plus("y") : ucase : print


##########  mrk.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

p 50 print
p "hello" print 
p 5 arr plus 7 plus 12 print # array of [5, 7, 12]

function p
    z return 7
    fig

x p print # prints 7
p 256 print # and is a numeric again


##########  mtp.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 
p "mtpaint -s" shell
##########  nstr.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 
z : "ls" : arrshell
forin p z
    ck : instr p ".fig"
    iftrue ck 
        x : p : print
        fig
    nextin


##########  p3.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

function ckp ckfp
    ck get ckfp lcase
    b ""  ## leave only alpha
    forin l ck  

        forin a "abcdefghijklmnopqrstuvwxyz"
            ifequal l a
                z b plus l swap z b
                fig
            next

        next
    z b print
    d b reverse 

    ifequal b d 
        z ck print "is a palindrome" print 32 chr print
    else
        z ck print "is not a palindrome" print 32 chr print
        fig

    fig

p ckp "do nine men INTERPRET? nine men, i nod!"












##########  pix.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

python 
    def figpset(z, x, y, c): 
        figlocate(0, y, x)
        figcolortext(0, c)
        figprints("*")
    fig

while
    x randint 0 799
    y randint 0 768
    c randint 0 15
    z pset x y c sleep 0.0001
    wend


##########  rfig.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

cheese "hello" : ucase : left 2 : plus "y" # pipeline

for n 0 1 .1
    throwaway n prints # print has newline; prints, no.
    throwaway 32 chr prints # " " works too
    next # or fig; fig command unindents, next is alias

forin cheddar cheese
    c randint 9 14 colortext c # color uses ansi escapes
    z cheddar print
    next

python
    for p in range(5):
        print "last color value was:", c
fig

x "set x to the following: " prints lineinput 











##########  rs.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

while

    x "type in file to open - " prints lineinput
    ifequal x "quit"
        break
        fig

    p arropen x

    forin lines p
        words split lines " "

        forin z words
            x z sleep .15 print
            nextin

        nextin 

    fig


##########  slow.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

forin p stdin
    now p rtrim print sleep .05
    next


##########  tr.fig  ##########

#### license: creative commons cc0 1.0 (public domain) 
#### http://creativecommons.org/publicdomain/zero/1.0/ 

# this is a working fig program
function printhello
    z cls # clear screen
    z "hello world" print
    fig

python
    # inline python feature
    for p in range(5):
        printhello()
    fig

 

 

Advertisements

5 thoughts on “fig example programs 2017

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s