[PD] GridFlow CGI

Mathieu Bouchard matju at sympatico.ca
Sun Feb 9 18:36:35 CET 2003


Just a note to say I've run GridFlow inside a CGI script yesterday.

It is a 40-line Ruby script that shows a checkerboard (@checkers)
transformed by a "complex squaring" (@complex_sq). It allows a translation
parameter; when you get farther from the origin you see the natural moire
effect that occurs as the checker squares become as small (or
smaller) than the pixel lattice. The result is then encoded in JPEG (which
is a silly idea for a two-tone picture... sorry)

I'm not putting it alive on the web because I don't have much experience
in securing CGI scripts (e.g. preventing DoS attacks...). However I'll
post the script itself here.

Now it would be nicer if GridFlow could emulate jMax/PD to the point of
loading .jmax/.pd files...



#!/opt/bin/ruby

begin # to catch exceptions ...

ENV["HOME"]="/"
STDERR.reopen "/dev/null", "w"
require "cgi"
require "gridflow"
include GridFlow

$param = Integer(CGI.new.params['offset'][0])
#puts "Content-type: text/plain", "", $param; exit

class Foo < FPatcher
  FObjects = [
    "@for {0 0} {16 16} {1 1}",
    "@checkers",
    "@ * 2",
    "@ - 128",
    "@store",
    "@out jpeg file /dev/stdout",
    "@for {-128 -128} {128 128} {1 1}",
    "@ + #{$param}",
    "@complex_sq",
    "@ >> 8",
  ]
  Wires = [-1,0,0,0, 0,0,1,0, 1,0,2,0, 2,0,3,0, 3,0,4,1, 4,0,5,0,
    -1,0,6,0, 6,0,7,0, 7,0,8,0, 8,0,9,0, 9,0,4,0]
  def initialize() super(FObjects,Wires,1) end
  install "foo", 1, 0
  def [](i); @fobjects[i]; end
end

puts "Content-type: image/jpeg", ""
STDOUT.flush
f=Foo.new
f.send_in 0
f[5].send_in 0, :close



rescue Exception => e # goes with 'begin' above...
  puts "Content-type: text/plain", ""
  puts $!.inspect, $!.backtrace
end


________________________________________________________________
Mathieu Bouchard                       http://artengine.ca/matju






More information about the Pd-list mailing list