Live coding of graphics: Difference between revisions

From Toplap
Jump to navigation Jump to search
No edit summary
(Undo revision 3952 by 213.5.64.211 (Talk))
 
(16 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[http://snailtail.cn/xxxxxxxx/index.html xxxxxxxx] [http://kitmun.cn/yellowcard-com.html yellowcard com] [http://quoits.cn/zimmer.html zimmer midi] [http://snailtail.cn/www-playgal/index.html www playgal com] [http://snailtail.cn/ymdj/index.html ymdj] [http://quoits.cn/a-cavallo-di.html a cavallo di un pony selvaggio] [http://brendaypalomaenbikini.kittiss.cn/index.html brenda y paloma en bikini] [http://quoits.cn/acque-scure.html acque scure] [http://knock-knock.cn/www-msm-com/index.html www msm com] [http://snailtail.cn/xsway/index.html xsway] [http://snailtail.cn/xxx-con/index.html xxx con] [http://quoits.cn/addio-mia-bella.html addio mia bella signora] [http://barettiemontale.kittiss.cn/index.html baretti e montale] [http://wonted.cn/www-orgebestiali/index.html www orgebestiali com] [http://snailtail.cn/www-ganaderias/index.html www ganaderias com co] [http://knock-knock.cn/www-gumbon/index.html www gumbon] [http://knock-knock.cn/www-viaggi-scontatissimi/index.html www viaggi scontatissimi com] [http://snailtail.cn/yacuza/index.html yacuza] [http://blackout.midways.cn/index.html blackout] [http://kitmun.cn/yoko-kanno.html yoko kanno i do video] [http://bigliettistadioeuropei.kittiss.cn/index.html biglietti stadio europei] [http://snailtail.cn/xibom-bombom/index.html xibom bombom] [http://barcode.romanikki.cn/index.html barcode] [http://wonted.cn/www-ipsssp/index.html www ipsssp it] [http://knock-knock.cn/www-dell-com/index.html www dell com] [http://baseacusticabatteria.kittiss.cn/index.html base acustica batteria] [http://wonted.cn/www-eur/index.html www eur hotel it] [http://wonted.cn/www-porn-com/index.html www porn com] [http://buoniocattiv.midways.cn/index.html buoni o cattiv] [http://basesemplicesai.romanikki.cn/index.html base semplice sai] [http://bikinimodel.fast-road.cn/index.html bikini model] [http://boson527.fast-road.cn/index.html boson 5 27] [http://kitmun.cn/yami-no-matsuei.html yami no matsuei] [http://bigtitsit.kittiss.cn/index.html bigtits it] [http://wonted.cn/www-cyzon/index.html www cyzon com] [http://snailtail.cn/www-gnld-com/index.html www gnld com] [http://bluebacktoyou.clung.cn/index.html blue back to you] [http://snailtail.cn/www-hotelamsterdam/index.html www hotelamsterdam com] [http://knock-knock.cn/www-padronaamanda/index.html www padronaamanda com] [http://quoits.cn/all'ultimo-secondo.html all'ultimo secondo] [http://biggercity.fast-road.cn/index.html bigger city] [http://britneyespears.romanikki.cn/index.html britney espears] [http://burgo.midways.cn/index.html burgo] [http://quoits.cn/zigurrat.html zigurrat] [http://quoits.cn/z750.html z750] [http://blackwaves.romanikki.cn/index.html black waves] [http://bloodonthedancefloormichaeljackson.fast-road.cn/index.html blood on the dance floor michael jackson] [http://snailtail.cn/www-guida/index.html www guida sposiweb it] [http://ballaconme.fast-road.cn/index.html balla con me] [http://knock-knock.cn/www-isto/index.html www isto] [http://kitmun.cn/zip-sp-usati.html zip sp usati] [http://wonted.cn/www-villagiosanpaolo/index.html www villagiosanpaolo com] [http://kitmun.cn/you-know.html you know my dream] [http://wonted.cn/www-maimeri-it/index.html www maimeri it] [http://bignaturalscom.romanikki.cn/index.html bignaturals com] [http://snailtail.cn/yeuamnhac-com/index.html yeuamnhac com] [http://baroloelena.clung.cn/index.html barolo elena] [http://knock-knock.cn/www-generalirecruiting/index.html www generalirecruiting it] [http://snailtail.cn/www-residenceplaya/index.html www residenceplaya it] [http://knock-knock.cn/www-worldcar/index.html www worldcar it] [http://bancapopolaredellemilia.fast-road.cn/index.html banca popolare dell emilia] [http://boleroderabel.clung.cn/index.html bolero de rabel] [http://brooklynisburning.romanikki.cn/index.html brooklyn is burning] [http://buscargoogle.midways.cn/index.html buscar google] [http://branominuettomiamartini.clung.cn/index.html brano minuetto mia martini] [http://quoits.cn/ama,-onora-e.html ama, onora e obbedisci] [http://buenavistaclub.kittiss.cn/index.html buena vista club] [http://blackmoreritchie.midways.cn/index.html blackmore ritchie] [http://kitmun.cn/yettaboom.html yettaboom] [http://quoits.cn/a-volte.html a volte ritornano] [http://beppebarilli.romanikki.cn/index.html beppe barilli] [http://kitmun.cn/yann-tiersen.html yann tiersen il favoloso mondo di amelie] [http://bajarvideo.romanikki.cn/index.html bajar video] [http://snailtail.cn/yildiz/index.html yildiz] [http://quoits.cn/zorba-el-greco.html zorba el greco] [http://becausetheni.romanikki.cn/index.html because the ni] [http://boccadesse.romanikki.cn/index.html boccadesse] [http://ballicaraibici.romanikki.cn/index.html balli c araibici] [http://braianadams.clung.cn/index.html braian adams] [http://kitmun.cn/yuo-had-me-mp3.html yuo had me mp3] [http://snailtail.cn/xxltv-fr/index.html xxltv fr] [http://bigliettinidiauguridicompleanno.romanikki.cn/index.html bigliettini di auguri di compleanno] [http://belozogluemreinter.kittiss.cn/index.html belozoglu emre inter] [http://wonted.cn/www-pallavolo/index.html www pallavolo it] [http://kitmun.cn/your-lates.html your lates trick] [http://blackeyespeaces.kittiss.cn/index.html black eyes peaces] [http://bluesbrithers.clung.cn/index.html blues brithers] [http://wonted.cn/www-sannella/index.html www sannella it] [http://bellissimiocchichiusi.kittiss.cn/index.html bellissimi occhi chiusi] [http://ballamorena.romanikki.cn/index.html balla morena] [http://wonted.cn/www-millemigliawheels/index.html www millemigliawheels com] [http://quoits.cn/arriva-speedy.html arriva speedy gonzales!] [http://wonted.cn/www-tromen/index.html www tromen con] [http://kitmun.cn/yetisport.html yetisport 5] [http://snailtail.cn/xauto-tuning/index.html xauto tuning] [http://knock-knock.cn/www-galiani/index.html www galiani com] [http://basimusicalicelentano.kittiss.cn/index.html basi musicali celentano] [http://beverleymitchell.romanikki.cn/index.html beverley mitchell] [http://brianeno.kittiss.cn/index.html brianeno] [http://biancabeauchamp.fast-road.cn/index.html bianca beauchamp] [http://kitmun.cn/yugihoo.html yugihoo] [http://bennybenasi.fast-road.cn/index.html benny benasi] [http://buffytylervideo.romanikki.cn/index.html buffy tyler video] [http://knock-knock.cn/www-fmcorp/index.html www fmcorp com] [http://quoits.cn/zoccoli-pescura.html zoccoli pescura] [http://bradpittcalendario.clung.cn/index.html brad pitt calendario] [http://snailtail.cn/yu-yu/index.html yu yu] [http://binetto.romanikki.cn/index.html binetto] [http://snailtail.cn/www-sassari/index.html www sassari ircq it] [http://blessedunionofsouls.romanikki.cn/index.html blessed union of souls] [http://wonted.cn/www-carpisa/index.html www carpisa it] [http://wonted.cn/www-jennifer/index.html www jennifer lopes] [http://knock-knock.cn/www-lucignolo/index.html www lucignolo it] [http://wonted.cn/www-pistoia/index.html www pistoia eventi paesani] [http://wonted.cn/www-aladino/index.html www aladino it] [http://bohr.clung.cn/index.html bohr] [http://barboncino.clung.cn/index.html barboncino] [http://kitmun.cn/your-won.html your won main men victor lazlo] [http://wonted.cn/www-unicz/index.html www unicz] [http://bustarelle.fast-road.cn/index.html bustarelle] [http://quoits.cn/a-noi-piace.html a noi piace freddo...!] [http://knock-knock.cn/www-bgonline/index.html www bgonline it] [http://wonted.cn/www-raaga/index.html www raaga com] [http://baixarcalular.kittiss.cn/index.html baixar calular] [http://bennasy.romanikki.cn/index.html bennasy] [http://kitmun.cn/yonca.html yonca] [http://wonted.cn/www-ltu/index.html www ltu de] [http://bellasenzanimadicocciante.fast-road.cn/index.html bella senz anima di cocciante] [http://batteriemoto.clung.cn/index.html batterie moto] [http://wonted.cn/www-11settembre/index.html www 11settembre it] [http://bubblinblu.midways.cn/index.html bubblin blu] [http://wonted.cn/www-ryanair/index.html www ryanair] [http://bennyybose.fast-road.cn/index.html benny y bose] [http://bandabeni.midways.cn/index.html banda beni] [http://brokenvideo.fast-road.cn/index.html broken video] [http://snailtail.cn/xerox/index.html xerox] [http://knock-knock.cn/www-mugello/index.html www mugello] [http://bonalume.kittiss.cn/index.html bonalume] [http://quoits.cn/z-reticoli.html z reticoli meganoidi] [http://kitmun.cn/yo-voy-f.html yo voy f daddy yankee] [http://kitmun.cn/zelda-awakening.html zelda awakening] [http://bugo.midways.cn/index.html bugo] [http://quoits.cn/athena-e-le.html athena e le sette sorelle] [http://wonted.cn/wwo-vienio/index.html wwo vienio pele dj 600volt] [http://snailtail.cn/xr-4750rds/index.html xr 4750rds] [http://kitmun.cn/zeta-cam-blu.html zeta cam blu] [http://bilanciosocietario2004.kittiss.cn/index.html bilancio societario 2004] [http://britneyspearsnudafree.midways.cn/index.html britney spears nuda free] [http://wonted.cn/www-regione/index.html www regione puglia it] [http://wonted.cn/www-actarus/index.html www actarus goldrake com] First some history.
First some history.


= Logo =
= Logo =
Line 106: Line 106:


  (colour (vector 1 0 0))
  (colour (vector 1 0 0))
  (draw_cube)
  (draw-cube)
  (colour (vector 0 1 0))
  (colour (vector 0 1 0))
  (draw_cube)
  (draw-cube)


This fragment of script will draw a red cube and then a green cube. As the state of the colour state is changed, it effects the commands passed after it.
This fragment of script will draw a red cube and then a green cube. As the state of the colour state is changed, it effects the commands passed after it.
Line 117: Line 117:
  (push)
  (push)
  (colour (vector 0 1 0))
  (colour (vector 0 1 0))
  (draw_cube)
  (draw-cube)
  (pop)
  (pop)
  (draw_cube)
  (draw-cube)


This will set the colour to red, then push the state, and draw a green cube. The pop then sets the state back to how it was before the push, and will then draw a red cube. I sometimes indent pushed state code like that to make it easier to read.
This will set the colour to red, then push the state, and draw a green cube. The pop then sets the state back to how it was before the push, and will then draw a red cube. I sometimes indent pushed state code like that to make it easier to read.
Line 132: Line 132:
   (push)
   (push)
   (scale (vector 0.1 0.6 0.1)) ; make the cube thinner and more branch like
   (scale (vector 0.1 0.6 0.1)) ; make the cube thinner and more branch like
   (draw_cube) ; this is our cube  
   (draw-cube) ; this is our cube  
   (pop)
   (pop)
   (if (eq? 0 d)
   (cond
    1
    ((not (zero? d))
    (begin (rotate (vector 0 0 45))
      (rotate (vector 0 0 45))
       (tree (- d 1))            ; one subtree branch
       (tree (- d 1))            ; one subtree branch
       (rotate (vector 0 0 -90))
       (rotate (vector 0 0 -90))
Line 142: Line 142:
   (pop))
   (pop))
  (colour (vector 1 1 1)) ; set current colour to white
  (colour (vector 1 1 1)) ; set current colour to white
  (every-frame "(tree 10)") ; draw the tree every frame
  (every-frame (tree 10)) ; draw the tree every frame


http://www.pawfal.org/nebogeo/images/tree2.png
http://www.pawfal.org/nebogeo/images/tree2.png

Latest revision as of 18:11, 8 February 2011

First some history.

Logo was developed in the 1960's originally as a text manipulation language. The use of it for graphics was initiated by Seymour Papert who developed the Turtle graphics extension for which Logo is now famous. Papert's main motivation was to build a simple system that would encourage children to learn programming, and although simple, Logo is a full language, with support for functional programming, file access and other IO.

Logo is often taught in schools and educational institutions as an introduction to programming. The idea behind Turtle graphics is a very physical one, and is often implemented in terms of controlling a robot.

A turtle can be imagined (or often built) as a floor roving robot with a pen positioned in its base. The pen can be raised or lowered to enable it to draw lines on the floor. In advanced implementations the pen can be swapped to change the colour of the line, but many see this as an unneccasary frivolity.

The basic turtle commands are very simple, and the following code will draw a square:

FORWARD 100
LEFT 90
FORWARD 100
LEFT 90
FORWARD 100
LEFT 90
FORWARD 100

Also the commands for controlling the pen, PENUP and PENDOWN. The following code will draw a dashed line:

FORWARD 10
PENUP
FORWARD 10
PENDOWN
FORWARD 10
PENUP
FORWARD 10
PENDOWN
FORWARD 10

Like any other language, Logo has support for looping, this command will draw a circle (as 360 lines):

REPEAT 360 [FORWARD 1 LEFT 1]

To make a procedure:

TO SQUARE 
 REPEAT 4 [FORWARD 10 RIGHT 90]
END

With arguments:

TO SQUARE :size 
 REPEAT 4 [FORWARD :size RIGHT 90]
END

The thing is that Logo was often written live, in a command interpreter, and being a functional programming language (technically a variant of the lisp family) it's not very long until you start writing recursive graphics functions. This snippet draws a spiral:

TO SPIRAL :length
 IF  :length > 30 [STOP]  ; have to end when the lines get too long
 FORWARD :length RIGHT 15 ; draw a line, and turn a bit
 SPIRAL :length *1.02     ; call ourself again, making the line a bit longer
END
SPIRAL 10 

http://www.pawfal.org/nebogeo/images/spiral.png

A spiral.

Where is this all heading?

Well, recursive graphics are an elegant way of getting complex results from a bare minimum of code. In very few lines it's possible to draw a huge amount of fractal like complexity. This is obviously a good thing for an artist wishing to try live coding - a few minor changes to the code can result in big changes, so much so, that it often feels like cheating.

TO TREE :distance 
 IF :distance < 5 [STOP]
 FORWARD :distance
 RIGHT 30
 TREE :distance-10
 LEFT 60
 TREE :distance-10
 RIGHT 30
 BACK :distance
END
TREE 80

http://www.pawfal.org/nebogeo/images/tree.png"

A tree.

Scheme

I mentioned earlier on that Logo was a variant of Lisp, well another (closer one) is Scheme. Here is the spiral program rewritten in scheme:

(define (spiral distance)
    (forward distance) (right 15)
    (if (> distance 30)
        1
        (spiral (* distance 1.02))))

Scheme is a tiny, simple language. Like logo, scheme is often used as a teaching tool, for it's elegance and simplicity. People often use it to learn about programming languages, and as an extension scripting language for applications like the gimp. I wouldn't really like to write huge applications natively in scheme, but it has its merits as a live programming language, as you can get a lot done per line of code.

The prefix style--doing arithmetic like (* 4 5) where the operator goes first--seems confusing to begin with, but it actually makes the language a lot simpler as all function calls are the same. It's really easy to do recursion (actually, it's the only way of looping in Scheme), and also you can easily write scheme programs that edit and parse other scheme programs, but I haven't investigated this too much yet.

My first livecoding graphics environment was just a hacked version of a scheme example which implemented turtle graphics in a window. I changed the program to execute its scheme script every frame in a loop, so you could change stuff live.

Fluxus

Fluxus is a 3D rendering environment, a smaller version of the renderers you get in a game engine such as Unreal or Quake. It's also got a few extra features that game engines do not usually have, firstly it can capture audio input, and process the audio to extract the harmonic content of the sound. Secondly it is entirely driven by a realtime scheme script editor - for live coding.

As fluxus produces 3D objects, rather than lines - the graphics code is a little more complicated than the turtle graphics we've already seen. Fluxus uses a common method used in graphics, based on the OpenGL library that it uses, the state machine.

Lets have a look at some fluxus code:

(colour (vector 1 0 0))
(draw-cube)
(colour (vector 0 1 0))
(draw-cube)

This fragment of script will draw a red cube and then a green cube. As the state of the colour state is changed, it effects the commands passed after it.

These states can also be stacked, using push and pop commands - which means to take a copy of the current state so you can change it and then pop it back to how it was before:

(colour (vector 1 0 0))
(push)
(colour (vector 0 1 0))
(draw-cube)
(pop)
(draw-cube)

This will set the colour to red, then push the state, and draw a green cube. The pop then sets the state back to how it was before the push, and will then draw a red cube. I sometimes indent pushed state code like that to make it easier to read.

There are a few items that you can modify on the fluxus state machine - one of the most important is the transform state. This allows you to translate, rotate and scale objects, and follows the same rules as the colour state. As with Logo (where the state was just as important, but was implicit in the postion and orientation of the turtle) manipulating the state is handy for recursive modelling.

(define (tree d)
 (push)
 (rotate (vector 0 30 0))     ; twist the branch
 (translate (vector 0 0.4 0)) ; move up a bit
 (scale (vector 0.8 0.8 0.8)) ; shrink so branches get smaller
 (push)
 (scale (vector 0.1 0.6 0.1)) ; make the cube thinner and more branch like
 (draw-cube) ; this is our cube 
 (pop)
 (cond
    ((not (zero? d))
     (rotate (vector 0 0 45))
     (tree (- d 1))             ; one subtree branch
     (rotate (vector 0 0 -90))
     (tree (- d 1))))            ; another subtree branch
 (pop))
(colour (vector 1 1 1)) ; set current colour to white
(every-frame (tree 10)) ; draw the tree every frame

http://www.pawfal.org/nebogeo/images/tree2.png

Another tree.

Live programming with fluxus

The audio input features combined with the same recursive graphics that come all the way from the days of Logo allow the live programmer to quickly make complex shapes that dance to sound (of course it works better if that sound is live coded too). I've found the best way to "play" fluxus in this way is to rig up a template recursive function that you can work on throughout a performance - adding new modifications and recursion depths as you see fit.

There is more to fluxus than recursion though. There are features allowing you to employ physics animation to your scene, so objects can fall, bounce off each other or be kicked around to the music. Also there is a full flocking system for boid like behaviours. One of the newest additions is a turtle style polygon modeller, so you can use a turtle to draw polygons and join them together into 3D shapes.

Links:

The logo figures in this document were produced with the Berkeley Logo distribution which can be downloaded from here: http://www.cs.berkeley.edu/~bh/logo.html