Graphics over code in Impromptu
Andrew posted some code in the Impromptu mailing list showing how to add graphics (and various other things) on top of a code ‘image’. As usual I regret not having a whole free day to play with this, but just by messing around with some parameters the effects are so cool!
>>>

>>>
..the code from Andrew is the following:
(gfx:start-live-video)
(define canvas (gfx:make-canvas 640 480))
(define gl (gl:make-opengl))
(gl:open-opengl gl '(0 0 640 480))
;; draw code behind a rotating cube
;; if you wanted you could now call gfx:start-movie-capture
;; and pass the gl context where canvas usually goes.
(define loop-gl
(lambda (beat)
(let* ((code (gfx:get-code-image))
(flipped (gfx:flip-image code))
(width (car (gfx:get-image-size code)))
(height (cdr (gfx:get-image-size code))))
(gl:clear gl (+ *gl:color-buffer-bit* *gl:depth-buffer-bit*))
(gl:window-pos gl 0 0 .99)
(gl:draw-pixels gl width height *gl:rgba* *gl:unsigned-byte*
flipped)
(gl:load-identity gl)
(gl:translate gl 0 0 .5)
(gl:rotate gl (* beat 10) 1 1 1)
(gl:color gl 1 1 1 1)
(glut:wire-cube gl 0.5)
(gl:flush gl)
(gl:update-backing-image gl)
(objc:release (+ (now) 5000) code flipped)
(callback (*metro* (+ beat (* .5 1/6))) 'loop-gl (+ beat
1/6)))))
(loop-gl (*metro* 'get-beat 4))8
;; define an image to use as layer3
(define layer3 (gfx:make-image 640 480))
;; draw paths to layer3
(define draw-on-layer3
(lambda (beat)
(gfx:clear-image layer3)
(dotimes (i 10)
(gfx:path2image (gfx:make-circle (cosr 320 200 (/ i 100))
(sinr 240 200 (/ i 100))
20)
layer3
'() (list (/ i 5) 0 1 1)))
(callback (*metro* (+ beat (* .5 1/6))) 'draw-on-layer3 (+ beat
1/6))))
(draw-on-layer3 (*metro* 'get-beat 4))
;; draw video and layer3 transparently into the opengl bitmap
;; then render the opengl bitmap to the canvas
;;
;; You could easily replace
;; (gl:get-image-from-opengl gl) with (gfx:get-code-image)
;; if you didn't want to use any opengl
(define capture-code
(lambda (time)
(let ((video (gfx:get-live-frame))
(opengl (gl:get-image-from-opengl gl)))
(gfx:image2image video opengl .3)
(gfx:image2image layer3 opengl 1)
(gfx:draw-image time canvas opengl .9)
(objc:release (+ time 5000) opengl video))
(callback (+ time 2000) 'capture-code (+ time 5000))))
(capture-code (now))
;; start-movie-capture takes a canvas OR an opengl context
;; so you could call (gfx:start-movie-capture gl ...
;; as long as your gl code calls gl:update-backing-image
(gfx:start-movie-capture canvas "~/tmp/my.mov" #t)
;(gfx:stop-movie-capture canvas)
Django 1.1: LogOut links apparently broken
I lost quite a few hours on this, but the solution was simple. The other day I realized that all the Log-in / Log-out hyperlinks in the admin were messing things up in various ways. Either by inserting a mysterious ‘None’ string in the url, or by adding the necessary url terminations (/logout, /login) to the wrong place (e.g. /admin/application_name/logout instead of /admin/logout). Tried to google this a bit, found some results but nothing was apparently related..
Basically what happened is that when upgrading to Django 1.1. I didn’t update also the base.html file in my templates/admin … small thing really, but as I said it did manage to give me a headache.
So, advice is, when upgrading make sure to update all the admin templates you’re making use of (e.g. for customizing them)!. Follows an example of how the upgrade has changed things in base.html..
# in admin/base.html
# used to be:
<a href="{{ root_path }}logout/">{% trans 'Log out' %}</a>
# instead now is:
{% url admin:logout as logout_url %}
>>>
Wittgenstein’s Tractatus
Shameless self-plug: some time ago I made an alternative visualization of Wittgenstein’s Tractatus Logico-Philosophicus. No special reason, just because I wanted to do some experimentation with a text I was already working on. Well today I sort of run into it by change, and I really liked it! Isn’t that a good feeling when you realize the things you’ve done in the past did actually make some sense?
>>>

Impromptu: If-mod macro
hey there – this morning I checked out the nice screencast by Ben Swift and was struck by the if-mod construct he’s using. It’s a really useful shortcut that saves you from writing a few (possibly distracting) parenthesis, so I tried to recreate it myself.
To recap.. normally with Impromptu if you wanted to play some notes on certain beats with you’d have to set up a metronome first and then check for the right beat using the modulo function. For example, something like this will play a C every first beat of a 4/4 measure:
(define *metro* (make-metro 100))
(define test
(lambda (beat)
(if (equal? (modulo beat 4) 0)
(play dls 60 60 3))
(callback (*metro* (+ beat (* 1/2 1/4))) 'test (+ beat 1/4))))
(test (*metro* 'get-beat 4))
>>>
Another way of doing this is by using case. Same concept, but probably faster to code. Moreover, it also lets you specify multiple beats very easily:
(define test2
(lambda (beat)
(case (modulo beat 4)
((0)
(play dls 60 60 3))
((2 5/2)
(play dls 67 60 1/2)))
(callback (*metro* (+ beat (* 1/2 1/4))) 'test2 (+ beat 1/4))))
(test2 (*metro* 'get-beat 4))
>>>
Still quite a few parenthesis though… and especially when playing live this might mean more chances to fuck up
. So when I saw Ben’s video I thought a macro there wouldn’t do no harm! Here we go:
(define-macro (if-mod x y args)
`(for-each (lambda (step)
(if (equal? (modulo beat ,x) step)
,args))
(if (list? ,y)
,y
(list ,y))))
>>>
Now the example above can be written like this:
(define test2-new
(lambda (beat)
(if-mod 4 0 (play dls 60 60 3))
(if-mod 4 '(2 5/2) (play dls 67 60 1/2))
(callback (*metro* (+ beat (* 1/2 1/4))) 'test2-new (+ beat 1/4))))
(test2-new (*metro* 'get-beat 4))
>>>
Notice that the if-mod construct can take either a list of beats or a single one.
Comments?
Yolk : Python packages index
Yolk is a Python tool for obtaining information about packages installed by distutils, setuptools and easy_install and querying packages on PyPI (Python Package Index a.k.a. The Cheese Shop).
Yolk can list all the packages installed by distutils or setuptools on your system by >=Python2.5 or packages installed by setuptools if you have <=Python2.4. You can see which packages are active, non-active or in development mode and show you which have newer versions available by querying PyPI.
$ yolk -l
List all installed Python packages
$ yolk -a
List only the activated packages installed (Activated packages are normal packages on sys.path you can import)
$ yolk -n
List only the non-activated (–multi-version) packages installed
$ yolk -l -f License,Author nose==1.0
Show the license and author for version 1.0 of the package `nose`
$ yolk –entry-map nose
Show entry map for the nose package
$ yolk –entry-points nose.plugins
Show all setuptools entry points for nose.plugins
>>>
e.g.:
[mac]@mac99:~>yolk -l
BzrTools - 1.18.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages)
Conch - 0.8.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Django - 1.0.2-final - active
Loom - 1.4.0dev0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages)
PIL - 1.1.6 - active
PyRSS2Gen - 1.0.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Python - 2.5.1 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload)
Twisted Lore - 0.3.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted Mail - 0.4.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted Names - 0.4.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted News - 0.3.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted Runner - 0.2.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted Web - 0.7.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted Words - 0.5.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
Twisted - 2.5.0 - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
altgraph - 0.6.8.dev - active development (/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python)
antlr-python-runtime - 3.0.1 - non-active


