LJ Archive

Using Python with RAYZ

Drew Perttula's Python grid squares program (called creategrid) defines sections of an envelope image that appear to break apart in water. As the envelope shatters, the images undergo warps and other distortions in RAYZ. The text output of the Python program is pasted into RAYZ, but not as you might expect into a text box. “The clever RAYZ magic is the way it lets me paste text from anywhere right into its GUI, and that the result of a paste is actual GUI nodes and connections”, says Perttula.

#!/usr/bin/python

import pygame, pygame.image
from pygame.locals import *

pygame.init()

white = [255]*3
surf = pygame.Surface( (600,350), SWSURFACE )

xcells=6
ycells=4

for xi in range(0,xcells):
   for yi in range(0,ycells):

      surf.fill( 0 )
      surf.fill( white,
         Rect([[xi*1.0/xcells*600,yi*1.0/ycells*350],
              [600.0/xcells,350.0/ycells]]) )

      filebase = "grid%02i-%02i" % (xi,yi)
      pygame.image.save(surf, filebase+".bmp" )

      print """
"%s" = imagein(  )
{
  full.file_info.file_id: "fish/%s.bmp";
  full.flip: 0;
  user_size.width ( !user_set ): 600;
  user_size.height ( !user_set ): 350;
  add_alpha: 1;
  sequence_range: undefined 0.5@0.5 linear
                  1000.5@1000.5 undefined;
}""" % ( filebase, filebase )

It outputs this, 24 times, with varying names
(instead of grid00-00):

"grid00-00" = imagein(  )
{
  full.file_info.file_id:
    "/40g/video/fish/grid00-00.bmp";
  full.flip: 0;
  user_size.width ( !user_set ): 600;
  user_size.height ( !user_set ): 350;
  add_alpha: 1;
  sequence_range: undefined 0.5@0.5 linear
                  1000.5@1000.5 undefined;
}
LJ Archive