fredag 2 januari 2009

Skriva brev

Såhär på nyårsdagen så måste man uppfylla sina löften. Jag lovade att bygga fler robotar, så här kommer en. Det är en plotter som håller på att skapas. Jag försöker skriva ut formen av ett brev, det går sådär. Jag skyller på min egen dåligt tillverkade skakiga hand. Byt ut den felande länken så kan du tänka dig hur snyggt det kunnat bli!

Video

måndag 22 december 2008

Skyskrapor i skyskrapor


Nä, nu går jag över till svenska. Se det som en hämnd mot alla japanska nörds ute i världen som fyller mina googlesvar med krumelurer jag inte förstår. Idag satt jag och R på världens bar och njöt av contextfreeart. Resultatet blev detta. Om du zoomar i bilden kan du se att varje fönster i skyskraporna också är en solnedgång.

startshape INIT

rule INIT {
SKYLINE {x -0.8}
SKYLINE {x 14.8 s -1 1}
SQUARE {x 7 y 5.5 sat 200 b 0.2 hue 180 s 16 11}
CIRCLE {hue 38 sat 1 b 0.81 x 5 y 6 s 3}
}

rule SKYLINE {
SQUARE {}
WINDOWS {s 0.1}
HOUSE {}
SKYLINE {x 0.9 s 0.9 0.8}
}

rule HOUSE {
WINDOWS {s 0.1}
HOUSE {y 1}
}

rule HOUSE 0.3 {}

# floor of house
rule WINDOWS {
SQUARE {x 3.5 y 4.5 s 10 10}
4 * {y 2.2 hue 10.5}
ROW {y 1.2 x 0.1 s 0.9}
}

rule ROW {
4 * {x 2.5 hue 10}
BRICK {}
}

rule BRICK {
S {s 0.125 sat 2.0}
}
rule S {
INIT {x -7 y -3}
}

rule BRICK 2 {}

tisdag 15 juli 2008

google are hosting sites

When seeing projects like appjet I guessed that google would come up with something similar. And so it seems, I just tried out app engine which is a Python framework for developing web applications with database store that google hosts.

About 1.5 hours later I've managed to convert my silly svg-wiki to "work" on app engine. It's here. It seems really nice.

Another thing I would like to try out is jaxer which aptana is making some similar hosting for, but which you have to pay for.

fredag 16 maj 2008

too many monkeys

Seems like both activerecord and sequel want to patch the mysql adapter, so if you want to use both in the same project simultaneously you need to monkeypatch the monkeypatches. Or rather replace the file lib/sequel_core/adapters/mysql.rb with this file.

Otherwise you seems to get empty results from activerecord find requests where all fields are nil. To many sticky fingers in the database jar.

fredag 7 mars 2008

drawing a tree with javascript and svg

Hmm, my back is hurting and I should stay away from the laptop, but instead I've been playing around with svg and javascript to create graphics from grammars, very similar to contextfreeart.

rule("start", 2,
line,
c("start", {x: 100, r: 15, s: 0.8}),
c("start", {x: 100, r: -35, s: 0.8}));

rule("start",
line,
c("start", {x: 100, s: 0.8}));

This is a small grammar to draw a tree. The first rule specify that we draw a line, and then we call the rule "start" twice, with two transformations (read more on contextfreeart to understand) that rotate the tree 15 degress right and 35 degrees left, creating two branches. The second rule specifies to draw a line and continue forward. (the s-parameter is used to scale down the tree, making the branches smaller and smaller).

I've created a page where you can create your own programs. Maybe I'll document it some more later.

rule("start",
square,
c("start", {x: 100, r:6, s: 1.01}));

start("start",
{x:300, y:300, s:0.01})

Here is a small example that creates a spiral (replace the existing code with this). It exemplifies that you can specify the start-position of the graph. Click on the step buttons to render more of the spiral. The available primitives are line, square, circle. The code is also available here.

Have fun!

Update: Added support for color. You can specify the start color as an optional third argument to start, and add color transforms when calling rules, adding and subtracting color values. Here is an example using colors.

rule("c", 0.2, circle)
rule("c", circle, c("c", {x:100, blue: 10}))

rule("s",
circle,
c("c", {x:100, red: 20}),
c("s", {y:100, x:30, r: 15, s:0.9})
)

start("s", {x:300, y:200, r:120, s:0.2},
{red: 200, blue: 10, green: 10})

söndag 2 mars 2008

what to do with 1 year old apple hardware.

It's a well known fact that the apple airport express has a lifetime of about a year, which nicely corresponds to when the warranty ends or just disappears in your shoebox of receipts. I googled for a guide on how to disassemble it and using my skills to fix it and found nothing. So, my alternative guide is how to transform it to a timelessly designed incense holder. You just need to drill a hole and it's done! Good luck!


  1. Buy an airport, wait a year.


  2. Buy a drill.


  3. Buy incense, and take deep breath.


fredag 29 februari 2008

Context free art in ruby in 3d in opengl


Since I'm a fan of contextfreeart.org and nodebox.net, I've made a small ruby program inspired by contextfreeart, using context free grammars in 3d with opengl. The only operations right now are:

  • cube - create a cube.
  • up/down/left/right/to/from(rule) - define what rule to continue with in the specified direction.
  • flip - rotate 90 degress
  • scale - scale with 0.9.

But it should be quite easy to add new primitives (and clean up the code). Here is an example of a tree. Install ruby-opengl gem, click and move mouse to rotate, q - new random seed value, w - increase rendering depth, e - decrease rendering depth.

load 'cfa3d.rb'
class Tree < CFG
rule :start do |s|
s.cube
s.up :x
end

rule :x do |s|
s.cube
s.right :x
end
rule :x do |s|
s.cube
s.flip
s.left :x
end
rule :x, 0.1 do |s|
s.cube
s.flip
s.right :x
s.flip
s.left :x
end
rule :x do |s|
s.cube
s.scale
s.up :x
end
end

render Tree

A keyhandler for svg

This is an example of a keyhandler for controlling an application in svg. It consists of three files.

class.js. This is an implementation of classes in javascript, ripped out of prototype's html guts and modified.
keyhandler.js. A class that propagates key-events between javascript objects and their corresponding svg-elements. Currently it only changes the fill color of the focused element to green.
example.svg. The demo svg with some simple svg-elements that you can switch focus between with left/right/up/down. Press enter to get the currently selected item.

A javascript object that can get key focus has the following properties:

  • It has a variable named dom that refers to a svg-element.
  • It can have the functions onFocus and onLeaveFocus that are called when it gets or leaves focus.


The api of the keyhandler.

  • setFocus(x) - give focus to object x.
  • leaveFocus(x) - leave focus from x. this will also trigger leaveFocus on any children of x.
  • addKey(x, "a", f) - add key listener function f (which is called in the scope of x) for key 'a' when x (or children of x that hasn't overloaded 'a') have focus.
  • focusStrip([a, b, c], "left", "right") - specify that you can move focus between a, b, c by using the keys left and right.