chiark / gitweb /
New option: movres.ignore_transience.
[e16] / sample-scripts / bouncingball.pl
1 #!/usr/bin/perl
2
3 # Copyright (C) 2000-2004 Carsten Haitzler, Geoff Harrison and various contributors
4
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to
7 # deal in the Software without restriction, including without limitation the
8 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 # sell copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11
12 # The above copyright notice and this permission notice shall be included in
13 # all copies of the Software, its documentation and marketing & publicity
14 # materials, and acknowledgment shall be given in the documentation, materials
15 # and software packages that this Software was used.
16
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 # This is a little script that will create a window that says
25 # "Follow the Bouncing Ball" and then drops it to the bottom of the
26 # screen and slowly bounces it around.
27 # then when it's done bouncing it gets rid of it.
28
29
30 $s = `eesh screen size`;
31 chomp($s);
32
33 ($crap,$width,$height) = split(/\s+/,$s);
34 if ($s =~ /.*size\s+(\d+)x(\d+)/) {
35   $width = $1; $height = $2;
36 }
37
38 `eesh dialog_ok \"Follow the Bouncing Ball\"`;
39 $ball = "Message";
40
41 $s = `eesh win_op $ball move "?"`;
42 if ($s =~ /.*:\s+(\d+)\s+(\d+)/) {
43   $ballx = $1; $bally = $2;
44 }
45 $s = `eesh win_op $ball size "??"`;
46 if ($s =~ /.*:\s+(\d+)\s+(\d+)/) {
47   $ballw = $1; $ballh = $2;
48 }
49 #print "x,y=$ballx,$bally wxh=$ballw x $ballh\n";
50
51 # now for the fun part.  make that baby bounce up and down.
52 # we're going to open a big pipe for this one and just shove data
53 # to it.
54
55 open IPCPIPE,"| eesh";
56
57 @fallspeed = (30,25,20,15,10,5,4,3,2);
58 $i = 0;
59 foreach(@fallspeed) {
60         $originalbally = $bally;
61         $fallspeed = $fallspeed[i];
62         while($bally < ($height - $ballh)) {
63                 if(($bally + $fallspeed + $ballh) < $height) {
64                         $bally += $fallspeed;
65                 } else {
66                         $bally = $height - $ballh;
67                 }
68                 print IPCPIPE "win_op $ball move $ballx $bally\n";
69                 system("usleep 20000");
70         }
71
72         if($fallspeed[i+1]) {
73                 $fallspeed = $fallspeed[i+1];
74         } else {
75                 $fallspeed = 1;
76         }
77
78         while($bally > ($originalbally + int($originalbally * (1/$#fallspeed)))) {
79                 if(($bally - $fallspeed) > 
80                                 ($originalbally + int($originalbally * (1/$#fallspeed)))) {
81                         $bally -= $fallspeed;
82                 } else {
83                         $bally = $originalbally + int($originalbally * (1/$#fallspeed));
84                 }
85                 print IPCPIPE "win_op $ball move $ballx $bally\n";
86                 system("usleep 20000");
87         }
88         $i++;
89 }
90
91 print IPCPIPE "win_op $ball close\n";
92 close IPCPIPE;
93
94 # that's all folks.