<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use X11::Protocol;
use IO::Select;

$pi = 3.1415926535898;
$r = 1;
$theta = 0;
$size = 250;

$x = X11::Protocol-&gt;new;
$win = $x-&gt;new_rsrc;
$x-&gt;CreateWindow($win, $x-&gt;root, 'InputOutput', $x-&gt;root_depth,
		 'CopyFromParent', (0, 0), 2 * $size, 2 * $size, 1,
#		 'backing_store' =&gt; 'Always',
		 'background_pixel' =&gt; $x-&gt;white_pixel);
$x-&gt;ChangeProperty($win, $x-&gt;atom('WM_NAME'), $x-&gt;atom('STRING'), 8,
		   'Replace', "Animation test");
$x-&gt;MapWindow($win);
$pm = $x-&gt;new_rsrc;
$x-&gt;CreatePixmap($pm, $win, $x-&gt;root_depth, 2 * $size, 2 * $size);
$gc = $x-&gt;new_rsrc;
$x-&gt;CreateGC($gc, $pm, 'foreground' =&gt; $x-&gt;black_pixel,
	     'graphics_exposures' =&gt; 0);
$egc = $x-&gt;new_rsrc;
$x-&gt;CreateGC($egc, $pm, 'foreground' =&gt; $x-&gt;white_pixel,
	     'graphics_exposures' =&gt; 0);
$x-&gt;PolyFillRectangle($pm, $egc, [(0, 0), 2 * $size, 2 * $size]);

$sel = IO::Select-&gt;new($x-&gt;connection-&gt;fh);

sub r2p {
    my($x, $y) = @_;
    $x -= .5;
    $x *= .75;
    $y -= .5;
    return [-atan2($y, $x), sqrt($x*$x + $y*$y)];
}

$P = [[['Simple', $gc],
       [r2p(0, 0),
	r2p(.75, 0),
	r2p(1, .25),
	r2p(.75, .5),
	r2p(.15, .5),
	r2p(.15, 1),
	r2p(0, 1)]],
      [['Convex', $egc],
       [r2p(.15, .15),
	r2p(.75, .15),
	r2p(.85, .25),
	r2p(.75, .35),
	r2p(.15, .35)]]];

$E = [[['Simple', $gc],
       [r2p(0, 0),
	r2p(1, 0),
	r2p(1, .2),
	r2p(.2, .2),
	r2p(.2, .4),
	r2p(.75, .4),
	r2p(.75, .6),
	r2p(.2, .6),
	r2p(.2, .8),
	r2p(1, .8),
	r2p(1, 1),
	r2p(0, 1)]]];

$R = [[['Simple', $gc],
       [r2p(0, 0),
	r2p(.75, 0),
	r2p(1, .25),
	r2p(.75, .5),
	r2p(1, 1),
	r2p(.85, 1),
	r2p(.6, .5),
	r2p(.15, .5),
	r2p(.15, 1),
	r2p(0, 1)]],
      [['Convex', $egc],
       [r2p(.15, .15),
	r2p(.75, .15),
	r2p(.85, .25),
	r2p(.75, .35),
	r2p(.15, .35)]]];

$L = [[['Simple', $gc],
       [r2p(0, 0),
	r2p(.2, 0),
	r2p(.2, .8),
	r2p(1, .8),
	r2p(1, 1),
	r2p(0, 1)]]];

for (;;) {
    for $img ($P, $E, $R, $L) {
	$r = 5;
	while ($r &lt; 6.25 * $size) {
	    @polys = ();
	    for $poly (@$img) {
		@a = ($poly-&gt;[0]);
		for $p (@{$poly-&gt;[1]}) {
		    push @{$a[1]}, $size +
			$r * $p-&gt;[1] * sin($theta + $p-&gt;[0]);
		    push @{$a[1]}, $size +
			$r * $p-&gt;[1] * cos($theta + $p-&gt;[0]);
		}
		push @polys, [@a];
	    }
	    for $poly (@old_polys) {
		$x-&gt;FillPoly($pm, $egc, $poly-&gt;[0][0], 'Origin', @{$poly-&gt;[1]})
		    if $poly-&gt;[0][1] != $egc;
	    }
	    for $poly (@polys) {
		$x-&gt;FillPoly($pm, $poly-&gt;[0][1], $poly-&gt;[0][0], 'Origin',
			     @{$poly-&gt;[1]});
	    }
	    $x-&gt;CopyArea($pm, $win, $gc, (0, 0), 2 * $size, 2 * $size, (0, 0));

	    # On my Linux/x86 2.0, anything less than 1/100 sec causes
	    # other things (e.g., mouse tracking) to slow down terribly. 
	    $x-&gt;flush();
	    select(undef, undef, undef, 1/99);

	    @old_polys = @polys;
	    $r *= 1.05;
	    $theta += .1;
	    $x-&gt;handle_input if $sel-&gt;can_read(0);
	}
    }
}

</pre></body></html>