Back to the SSWF project home page

Sample: morph.sswf

From: samples/morph

/* Animation for the SSWF web site -- written by Alexis Wilke for Made to Order Software Corp. (c) 2002-2007 */
/* encoding="iso8859-1" */
/* This animation shows a how one can morph a shape in another */

/*

Copyright (c) 2002-2007 Made to Order Software Corp.

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/


screen_width = 113 + 126 + 4;
screen_height = 94 + 62 + 12;

rectangle "screen" { 0, 0, screen_width, screen_height };

// edges for shape 0
edges "circle_edges" {
	  11.8,      0,   8.3,    8.3;
	  8.35,    8.3,     0,  11.75;
	  0.05,  11.75,  -8.3,   8.35;
	  -8.3,    8.3, -11.8,   0.05;
	-11.75,      0, -8.35,   -8.3;
	  -8.3,   -8.3, -0.05, -11.75;
	     0, -11.75,   8.3,  -8.35;
	   8.3,  -8.35, 11.75,      0;
};

// edges for shape 1
edges "square_edges" {
	  11.8,     0,  16.55,      0;
	     0,  16.6,      0,  11.75;
	     0,  11.7,      0,  16.65;
	-16.55,     0,  -11.8,      0;
	 -11.8,     0, -16.55,      0;
	     0, -16.6,      0, -11.75;
	     0, -11.7,      0, -16.65;
	 16.55,     0,   11.8,      0;
};




fill style "fill_black_to_yellow" { sswf.col.black, sswf.col.yellow; };
line style "line_red_to_green" { 0.5, 1.5; sswf.col.red, sswf.col.green; };

define shape "morphing" {
	// use the same rectangle for both shapes (otherwise repeat)
	rect { -60, -60, 60, 60 };

	//show_bounds: true;	// these show_... feature don't work yet with morphing shapes
	//show_origin: true;

	// the color goes from a black circle with a thin red edge
	// to a yellow square with a thicker green edge
	fill_black_to_yellow;
	line_red_to_green;

	// start both shapes at the same position (this is not a requirement)
	morph: 2;
	move: 0, -28.35;

	// draw shape 0
	morph: 0;
	circle_edges;

	// draw shape 1
	morph: 1;
	square_edges;
};



sequence "main"
{
	frame_rate = 30;
	use_network = true;
	compress = false;
	screen;

	set background color { sswf.col.white };

	// The shapes
	morphing;

	replace object {
		depth: 1;
		id: morphing;
		morph: 0;
		matrix { translate: screen_width / 2, screen_height / 2; scale: 2; };
	};
	show frame;

	max = 60;
	for(i = 1; i <= max; i + 1) {
		// a linear transformation
		replace object {
			depth: 1;
			morph: (i + 0.0) / max;
			matrix { translate: screen_width / 2, screen_height / 2; scale: 2; };
		};
		show frame;
	};

	show frame { 30 };

	for(i = 1; i <= max; i + 1) {
		// a non-linear transformation
		replace object {
			depth: 1;
			morph: cos(i * pi / max / 2.0) ** 2;
			matrix { translate: screen_width / 2, screen_height / 2; scale: 2; };
		};
		show frame;
	};

	show frame { 30 };
};

This sample source was last modified on Jul 04 2007