[Xbubble-commits] xbubble/data/themes/plain/scripts bubble.h,NONE,1.1 convert-bubble.scm,NONE,1.1 explosion.h,NONE,1.1 render_bubbles.sh,NONE,1.1 scene.h,NONE,1.1

Martin Quinson xbubble-devel@lists.alioth.debian.org
Mon, 06 Dec 2004 07:59:05 +0000


Update of /cvsroot/xbubble/xbubble/data/themes/plain/scripts
In directory haydn:/tmp/cvs-serv21563/data/themes/plain/scripts

Added Files:
	bubble.h convert-bubble.scm explosion.h render_bubbles.sh 
	scene.h 
Log Message:
Import from savanah

--- NEW FILE: convert-bubble.scm ---
; GIMP script-fu
; Ivan Djelic <ivan@savannah.gnu.org>
; convert-bubble converts a povray-generated animation frame to an
; XBubble sprite PNG image.

(define (convert-bubble source dest static-bubble)
  (set!	image (car (gimp-file-load TRUE source source )))
  (gimp-image-undo-disable image)
  (set! layer (car (gimp-image-flatten image )))
  (gimp-layer-add-alpha layer)
  (gimp-by-color-select layer '(0 0 0) 0 REPLACE FALSE FALSE 0 FALSE)
  (if (= static-bubble TRUE )
      (begin
	;; add a 2 pixel wide black border
	(gimp-selection-invert image)
	(gimp-selection-grow image 2)
	(gimp-selection-invert image)))
  (gimp-edit-cut layer)
  (if (= static-bubble FALSE )
      (begin 
	;; add a sparkle effect
	(set! color '(127 127 127))
	(gimp-palette-set-background color)
	(set! layer (car (gimp-image-flatten image )))
	(plug-in-sparkle TRUE image layer 0.001 0.5 20 4 -1 0.25 0 0 0 0 0 0 0)
	(gimp-layer-add-alpha layer)
	(gimp-by-color-select layer color 0 REPLACE FALSE FALSE 0 FALSE)
	(gimp-edit-cut layer)))
  (set! width 320)
  (set! height 240)
  (gimp-image-scale image width height)
  (if  (= static-bubble TRUE )
       (begin
	 (plug-in-autocrop TRUE image layer)
	 ;; ensure image size is right
	 (gimp-image-scale image 90 90)))
  (if  (= static-bubble FALSE )
       (begin
	 ;; dirty hack for computing translation required after auto-cropping
	 (set! pixel (cons-array 4 'byte))
	 (aset pixel 0 255)
	 (aset pixel 1 255)
	 (aset pixel 2 255)
	 (aset pixel 3 255)
	 ;; put a white pixel in lower right corner and auto-crop
	 (gimp-drawable-set-pixel layer (- width 1) (- height 1) 4 pixel )
	 (plug-in-autocrop TRUE image layer)
	 (set! cx (- width (car (gimp-image-width image))))
	 (set! cy (- height (car (gimp-image-height image))))
	 (set! tx (- (/ width 2) cx ))
	 (set! ty (- (/ height 2) cy ))
	 (aset pixel 0 0)
	 (aset pixel 1 0)
	 (aset pixel 2 0)
	 (aset pixel 3 0)
	 ;; erase pixel & auto-crop
	 (set! width (car (gimp-image-width image)))
	 (set! height (car (gimp-image-height image)))
	 (gimp-drawable-set-pixel layer (- width 1) (- height 1) 4 pixel )
	 (plug-in-autocrop TRUE image layer)
	 ;; convert image to indexed palette (smaller size)
	 (gimp-convert-indexed image 2 MAKE-PALETTE 255 TRUE 0 "" )
	 ;; ouput translation coordinates
	 (gimp-message (string-append (number->string tx) " " 
				      (number->string ty)))))
  (file-png-save TRUE image layer dest dest FALSE 9 0 0 0 0 0 )
  (gimp-image-delete image))
--- NEW FILE: render_bubbles.sh ---
#!/bin/sh

# Render bubble sprite frames using POV-Ray & the GIMP

nb_frames=10
width=480
height=360
script=explosion.pov
colors="black blue red magenta brown green yellow white"
good_frames="02 03 04 05 06 07 08 09"
bad_frames="01 10"

s=$(( $( date +%s ) + 3600 ))

# Render explosions using POV-Ray
for color in $colors; do
    cat scene.h > $script
    echo "#declare bubble_color = pigment { pigment_$color }" >> $script
    cat bubble.h >> $script
    echo "#declare random_seed = $RANDOM" >> $script
    cat explosion.h >> $script
    povray -W$width -H$height +KFF$nb_frames -GA +V -I$script +FN -O$color
done

# Convert images with the GIMP
gimp_commands="$( cat convert-bubble.scm )"

for color in $colors; do
    # use first frame as static bubble image
    file=\"$( pwd )/${color}01.png\"
    file2=\"$( pwd )/${color}.png\"
    conversion="(convert-bubble $file $file2 1)"
    gimp_commands="$gimp_commands $conversion"
    for frame in $good_frames; do
	file=\"$( pwd )/$color$frame.png\"
	conversion="(convert-bubble $file $file 0)"
	gimp_commands="$gimp_commands $conversion"
    done
done

# GIMP batch call
echo
echo
echo "Invoking the GIMP..."
echo
gimp -i -d -b "(begin $gimp_commands)" "(gimp-quit TRUE)" 2>&1 |\
{
# Make  animation text files
for color in $colors; do
    echo -n "converting $color "
    echo "# Image	file	X   Y	delay" > $color.txt
    echo "$color.png 45 45 40" >> $color.txt
    for frame in $good_frames; do
	read line
	tx=$( echo $line | sed -e 's@[^0-9]*\([0-9]\+\).*@\1@' )
	ty=$( echo $line | sed -e 's@[^0-9]*[0-9]\+[^0-9]*\([0-9]\+\).*@\1@' )
	echo "$color$frame.png $tx $ty 40" >> $color.txt
	echo -n "."
    done
    echo
done
}

# cleanup
rm -f $script
for color in $colors; do
    for frame in $bad_frames; do
	rm -f "$( pwd )/$color$frame.png"
    done
done

t=$( date -d "$s seconds ago" +"%Hh%Mmn" )
echo "Rendering + conversion took $t."

--- NEW FILE: scene.h ---
// POV-Ray header for XBubble

#include "colors.inc"

#declare pigment_dead =    pigment { color rgbf <0.2, 0.2, 0.2, 0.9> }
#declare pigment_black =   pigment { color rgbf <0.5, 0.5, 0.5, 0.9> }
#declare pigment_blue =    pigment { color rgbf <  0, 0.5,   1, 0.9> }
#declare pigment_magenta = pigment { color rgbf <  1,   0,   1, 0.9> }
#declare pigment_green =   pigment { color rgbf <  0,   1, 0.2, 0.9> }
#declare pigment_red =     pigment { color rgbf <  1,   0,   0, 0.9> }
#declare pigment_yellow =  pigment { color rgbf <  1,   1,   0, 0.9> }
#declare pigment_brown =   pigment { color rgbf <  1, 0.5,   0, 0.9> }
#declare pigment_white =   pigment { color rgbf <  1,   1,   1, 0.9> }

global_settings { assumed_gamma 1.3 ambient_light 1.0 }

camera {
  location < 0, 0, -16.8 >
  look_at  < 0, 0, 0 >
}

light_source { <4, 5, -5> color White }

--- NEW FILE: bubble.h ---
// POV-Ray header for XBubble

#declare bubble_size = 6
#declare bubble = 
object {
  sphere { <0, 0, 0>, bubble_size/2 }
  texture { 
    pigment { bubble_color }
    finish  {
      ambient 2.0
      diffuse 0.1
      reflection 0.7
      refraction 1
      ior 1.45
      specular 0.8
      roughness 0.003
      phong 1.0
      phong_size 400
    }
  }
  hollow
}


--- NEW FILE: explosion.h ---
// POV-Ray script for XBubble explosion

#declare R1 = seed( random_seed )

// number of pieces = resolution ^ 3
#declare resolution = 4
// start shrinking pieces when clock >= disappear
#declare disappear = 0.5

#if ( clock <= 0) 
object { bubble }
#else
#if ( clock < disappear )
#declare anim_scale = 1
#else
#declare xx = ( clock - disappear )/( 1 - disappear )
#declare anim_scale = max( 0, 1 - xx*xx ) + .001
#end

#declare piece_size = bubble_size / resolution;
#declare piece =
object {
  box { < -0.5, -0.5, -0.5 >, < 0.5, 0.5, 0.5 > }
  scale anim_scale * piece_size
}
#declare prange = 0.5 * bubble_size - 0.5 * piece_size

// rotation amplitude
#declare rotation = 120
// pieces velocity
#declare velocity = 1.0

union {

// loop on piece location
#declare px = -prange 
#while ( px <= prange )         
#declare py = -prange 
#while ( py <= prange )
#declare pz = -prange
#while ( pz <= prange )

#declare vpiece = velocity * vnormalize( < px, py, pz > )
// add randomness in velocity length & direction
#declare perturbation = < rand(R1), rand(R1), rand(R1) > - 0.5
#declare vpiece = vpiece * ( 1 + 1.3*perturbation )
#declare perturbation = < rand(R1), rand(R1), rand(R1) > - 0.5
#declare vpiece = vrotate( vpiece, 40*perturbation )

// add randomness in rotation
#declare perturbation = < rand(R1), rand(R1), rand(R1) > - 0.5
#declare rpiece = rotation * (1 + perturbation )

// select a small piece of bubble
object {
  bubble
  clipped_by { 
    piece
    // add some randomness in piece size & orientation
    scale ( 1 + 1.6*( < rand(R1), rand(R1), rand(R1) > - 0.5 ))
    rotate 300 * ( 1 + ( < rand(R1), rand(R1), rand(R1) > - 0.5 ))
    translate < px, py, pz >
  }
  // center piece for rotation
  translate < -px, -py, -pz >
  rotate rpiece * clock
  // final translation
  translate < px, py, pz > + ( vpiece * clock )
}

#declare pz = pz + piece_size
#end
#declare py = py + piece_size
#end
#declare px = px + piece_size
#end
} // end of union
#end