v sine (fig graphics)

vsine

 

#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/
proginf = "v sine 2017 mn"
function rgbcolour r g b c
python
    figcgapal[c] = (r, g, b)
    fig
    fig
v 1
c 400
w 3.14159 divby 2
for r 490 175 -.125
    e w minus 0.00413367105263 swap e w # 3.14159 / 4 / (490 - 300)
    for p -3.14159 3.14159 .003067958984375
        t w cos times 380 divby 2 int
        rc r divby 2.5 int
        rd 256 minus rc rgbcolour rc rc 32 11
        e w sin times t times 2 plus r plus 7 divby 5
        x p times 2 cos times e plus c int
        y p times 2 sin times e plus r minus 50  int
        m 6.28 plus 1.57 divby 108.503 divby 2
        now v plus m swap now v
        rc r divby 4 int mod 2
        iftrue rc
            now v int mod 2 times 11 pset x y now
            y2 y minus 1 pset x y2 now
            fig
        next
    now display
    next
now display lineinput

 

floral (fig graphics)

floral

 

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

proginf "floral 2017 mn"

function rgbcolour r g b c
python
    figcgapal[c] = (r, g, b)
    fig
    fig

function qline c d e f g
    ## draw 4 lines, points go 2x2
    ## (cheap but avoids gaps)
    now line c d e f g
    d2 d plus 1
    f2 f plus 1
    now line c d2 e f2 g
    c2 c plus 1
    e2 e plus 1
    now line c2 d2 e2 f2 g
    now line c2 d e2 f g
    fig

while 
    rf randint 35 105 ## radius
    sf rf divby 2 int ## range of radius change
    xmin rf plus sf
    xmax xmin times -1 plus 800
    ymin rf plus sf
    ymax ymin times -1 plus 600
    pc randint 5 15      ## petal count
    xc randint xmin xmax ## horiz location
    yc randint ymin ymax ##  vert location
    while
        cr randint 32 248
        cg randint 32 248
        cb randint 32 248
        #fewer greens and dingy colors
        greenish cr plus cb minus cg times -1
        ifless greenish 0
            ifmore cr 160 
                break
                fig
            ifmore cg 160 
                break
                fig
            ifmore cb 160 
                break
                fig
            fig
        wend
    now display
    for p -3.14159 3.14159 0.00076698974609375 # 3.14159 / 2**12
        r p times pc sin times sf plus rf plus 7
        x p cos times r plus xc int
        y p sin times r plus yc int
        now line x y xc yc 15
        next
    for p -3.14159 3.14159 0.00076698974609375 # 3.14159 / 2**12
        r p times pc sin times sf plus rf
        x p cos times r plus xc int
        y p sin times r plus yc int
        now rgbcolour cr cg cb 14 qline x y xc yc 14
        next
    now display
    wend

now lineinput

 

 

gem seven (fig graphics)

gemseven

 

#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/
proginf = "gem seven 2017 mn"
function rgbcolour r g b c
python
    figcgapal[c] = (r, g, b)
    fig
    fig
v 1
c 400
w 3.14159 divby 2
xb
yb
for r 490 300 -.25
    e w minus 0.00413367105263 swap e w # 3.14159 / 4 / (490 - 300)
    for p 0 3.14159 0.44879857142857144 # 3.14159 / 7
        e w cos times 380 divby 2 int
        rc r divby 3 plus 40  int
        rd 256 minus rc rgbcolour rd rc 0 11
        x p times 2 cos times e plus c int
        y p times 2 sin times e plus r minus 50  int
        m 6.28 plus 1.57 divby 108.503 divby 2
        now v plus m swap now v
        rc r divby 4 int mod 2
        iftrue rc
            iftrue xb
                now v int mod 2 times 11 line xb yb x y now 
            else    
                now v int mod 2 times 11 pset x y now
                fig
            xb x
            yb y
            fig
        next
    now display
    next
now display lineinput

 

 

doublespiral (fig graphics)

doublespiral

 

#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/
proginf = "doublespiral 2017 mn"
function rgbcolour r g b c
python
    figcgapal[c] = (r, g, b)
    fig
    fig
v 1
c 400
w 3.14159 divby 2
for r 490 300 -.25
    e w minus 0.00413367105263 swap e w # 3.14159 / 4 / (490 - 300)
    for p -3.14159 3.14159 .003067958984375
        e w cos times 380 divby 2 int
        rc r divby 2 int
        rd 256 minus rc rgbcolour rc rc rc 11
        x p times 2 cos times e plus c int
        y p times 2 sin times e plus r minus 50  int
        m 6.28 plus 1.57 divby 108.503 divby 2
        now v plus m swap now v
        rc r divby 4 int mod 2
        iftrue rc 
            now v int mod 2 times 11 pset x y now
            y2 y minus 1 pset x y2 now
            fig
        next
    now display
    next
now display lineinput

 

 

spiral cone (fig graphics)

spiralcone

 

#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/
proginf = "spiralcone 2017 mn"
function rgbcolor r g b c
python
    figcgapal[c] = (r, g, b)
    fig
    fig
v 1
c 400
for r 490 110 -1
    for p -3.14159 3.14159 .003067958984375
        w r divby 5 plus 5 int
        rc r divby 2 int
        rd 256 minus rc rgbcolor rc 255 0 11
        x p times 2 cos times w plus c int
        y p times 2 sin times w plus r int
        m 6.28 plus 1.57 divby 108.503 divby 2
        now v plus m swap now v 
        now v int mod 2 times 11 pset x y now
        y2 y minus 1 pset x y2 now
        next
    now display
    next
now display lineinput

 

 

a super-quick overview of programming

you can get a good “overview” of programming from (i use 7) basic fundamental concepts:

variables — essentally a name, plus a piece of data.

  • assignment gives the name some data by mentioning the name and the data to assign:
  • x = 5
  • reference gets the data, just by using the name: x
  • arrays and lists hold more than one piece of data, so in addition to the name you use a number: x[2]

 

input — basically assigning a variable with data from a device, like a keyboard. or part of a file on the disk.

output — referencing a variable and putting its data onto a device, like a screen or a file on the disk.

basic math — unavoidable.

  • you dont have to be really good with math.
  • you can get the computer to do it for you.
  • you still have to tell it what you want to do.
  • much can often be abstracted with functions, but you will have to use numbers sometimes.

loops — think of a sandwich.

  • the two pieces of bread mark the top and bottom of the loop.
  • the “filling” is the code that runs (typically) more than once. can run once or 0 times.
  • the bottom piece of bread usually doesnt do much.
  • the top piece usually defines (briefly) how many times to loop, or what to wait for to stop.
  • can be simulated with functions, but its more work.

conditionals — code that runs if something is true (or alternatively, runs if not true)

  • can be simulated with a loop, because some loops can run (optionally) 0 times.
  • are a sandwich, like the loop is.
  • the bottom piece doesnt do much
  • the top piece usually defines whether the filling code should run or not
  • can be simulated with functions, but its more work

functions — basically assigning a name to a “paragraph” of program code

  • can make it less work to name/keep track of all your variables
  • can be called / used like any other command, so lets you “make your own commands.”
  • kind of the staple unit of programming– like a bar of notes, or a paragraph of prose.
  • the most difficult of these 7 concepts to really appreciate and understand– powerful but so deceptively simple, there has to be more to it (or it cant be that useful…)

 

fig examples:

# variables:
variable = 5

# input: (in this example, get typing from keyboard)
variable = lineinput

# output: (the ; is optional and can be ignored.)
now variable ; print

# basic math:
x = variable plus 5

# loops:
while
now “print keeps putting this on the screen!” print
wend

# conditionals:
variable = lineinput
ifequal variable, “hello”
now “hello yourself!” ; print
fig

# functions
function blank_the_screen
now cls
fig

variable = “hey there” ; blank_the_screen ; print
# above line blanks the the screen and puts “hey there” at the top.