Functional Art

blenderFractal

Functional Art

This is a post about computational art, and what I’m calling “Functional Art”, which I see as functional programming for creative code. First off, let’s look at a definition I found on the internet about what function programming is:

Functional programming (often abbreviated FP) is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and application state flows through pure functions.

If that doesn’t really make any sense, that’s ok, since no one really knows how to define functional programming; if you ever wanted to start a fight at a party full of nerds, just ask, one person will answer, and then everyone else will pile on to tell them why they are wrong. Another way to define functional programming is by using the terms imperative and declarative, but now you need to figure out what that means.

Declarative programming (like sql) is when you say what you want, but not how to do it ; it can then be optimized on the back end doing the work in imperative code.

Imperative programming is a programming paradigm that describes computation in terms of statements that change a program state. The declarative programs can be dually viewed as programming commands or mathematical assertions.

To break that down Declarative programming is like your manager telling you what they want you to do, and Imperative programming is you doing that work however you feel fit. In functional programming, you use declarative programming, so you just tell your program at a high level what you want, and boom, it figures it out for you.

So what is functional art then? It is using a declarative language to create art; something like openscad (see below), or something I’m working on which will end up either being some sort of declarative DSL’ish that can create patterns.

Building thing with openscad

printedFractal

Another pretty picture, to keep your attention.

The above image was created using openscad. You can find the code here. One thing about openscad is that it outputs everything you create (well duh right?), but what if you want to only print one cube out of many that is on the screen? To accomplish such magic with openscad, you need to wall off each part you make and call them individually, I accomplish this with Makefiles and If statements:

At the top of my openscad file, I list out all the parts that I want to be able to turn on and off:

_bigBox=false;
_smallBox=false;

and then at the end of the openscad file, I put in the logic to build the part if it is on:

if (_bigBox) { bigBox(cs=_cs);  }
if (_smallBox) { smallBox(cs=_cs); }

Then I have a Makefile, which can toggle each option on and build the part:

bin=/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD
fn=box-fractal.scad

define create-part
	$(bin) -o $(@).stl $(fn)
endef

# _bigBox : box that can hold other boxes
# _smallBox : fits into bigBox

box1_60:
	$(create-part) -D "_cs=60" -D "_bigBox=true" 

box2_30:
	$(create-part) -D "_cs=30" -D "_bigBox=true"

box3_15:
	$(create-part) -D "_cs=15" -D "_smallBox=true"

all: box1_60 box2_30 box3_15

clean:
	rm *.stl

Work In progress

If you looked at the image of the printed fractal, you might notice holes all over it. The Thought is I’m going to come back and fill in all the holes with LEDs. In my first attempt, I was using different colored leds to get a nice rainbow effect, but found that different leds have different requirements for power/resistors and ended up blowing out 3 of them while testing it, so in version 2 I’m going to use all blue leds. To connect the leds, I’m using a wire wrapper, and a little dab of hot glue to hold them in.

Blender Code

The Image at the top of the page was made in blender. I was going to export the DXF from openscad, but the time to render the entire fractal was taking way too long, so I decided to figure out blenders built in scripting system to do the same thing (note: blender uses python, and python is an imperative language.)

import bpy

def draw_boxes(x,y,z,bs,cs):
    bpy.ops.mesh.primitive_cube_add(size=bs, enter_editmode=False, align='WORLD', location=(x, y, z), scale=(1, 1, 1))

    if cs > 0:
        b2 = bs-bs/4
        draw_boxes(x+b2, y,z, bs/2, cs-1)    
        draw_boxes(x, y+b2,z, bs/2, cs-1) 
        draw_boxes(x, y,z+b2, bs/2, cs-1) 

        draw_boxes(x-b2, y,z, bs/2, cs-1)    
        draw_boxes(x, y-b2,z, bs/2, cs-1) 
        draw_boxes(x, y,z-b2, bs/2, cs-1) 

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

draw_boxes(0,0,0, 100,4)

Bottom of the page

This post is still a work in progress in a few places; first I need to add a bunch of leds to the 3dprint (or hide it somewhere and forget about it…) But more importantly, I’m still working on language you can use to create patterns.


Home