/usr/share/mozart/doc/demo/Bounce.oz is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | %%%
%%% Authors:
%%% Michael Mehl (mehl@dfki.de)
%%% Gert Smolka (smolka@dfki.de)
%%% Christian Schulte <schulte@ps.uni-sb.de>
%%% Joerg Wuertz (wuertz@dfki.de)
%%%
%%% Copyright:
%%% Michael Mehl, 1998
%%% Gert Smolka, 1998
%%% Christian Schulte, 1998
%%% Joerg Wuertz, 1998
%%%
%%% Last change:
%%% $Date: 1999-10-05 18:18:26 +0200 (Tue, 05 Oct 1999) $ by $Author: kornstae $
%%% $Revision: 12123 $
%%%
%%% This file is part of Mozart, an implementation
%%% of Oz 3
%%% http://www.mozart-oz.org
%%%
%%% See the file "LICENSE" or
%%% http://www.mozart-oz.org/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL
%%% WARRANTIES.
%%%
functor
import
Tk
Application(exit)
define
CanvasWidth = 400.0
CanvasHeight = 400.0
BallRadius = 50.0
XDelta = 5.0
YDelta = 5.0
Gravity = 3.0
Fraction = 0.9
RepeatTime = 100
Mouth = 30
MouthDelta = 5
BackColor = '#fffff0'
BallColors = if Tk.isColor then
red | blue | yellow | green |
plum | cyan | tan | bisque | BallColors
else
black | BallColors
end
class Ball
from Time.repeat Tk.canvasTag
prop final
attr
x: 0.0
xd: XDelta
y: 0.0
yd: YDelta
mouth: Mouth
d: ~MouthDelta
meth init(X Y Canvas Color)
Tk.canvasTag,tkInit(parent:Canvas)
{Canvas tk(crea arc X Y X+BallRadius Y+BallRadius
fill:Color start:30 extent:300 tag:self)}
x <- X
y <- Y
Time.repeat, setRepAll(action:bounce delay:RepeatTime)
thread
try {self go}
catch _ then skip
end
end
end
meth bounce
%% increment @x and @d
x <- @x + @xd
if @x =< 0.0 then
x <- 0.0
xd <- ~@xd
elseif @x>=CanvasWidth-BallRadius then
x <- CanvasWidth-BallRadius
xd <- ~@xd
end
%% increment @y and @yd
y <- @y - @yd
yd <- @yd - Gravity
if @y>=CanvasHeight-BallRadius then
y <- CanvasHeight-BallRadius
yd <- Fraction * ~@yd
end
Tk.canvasTag,tk(coords @x @y @x+BallRadius @y+BallRadius)
%% set the new mouth
mouth <- @mouth+@d
if @mouth>=Mouth then mouth <- Mouth d <- ~@d
elseif @mouth=<MouthDelta then mouth <- MouthDelta d <- ~@d
end
Tk.canvasTag,tk(itemconfigure start:@mouth extent:360-2*@mouth)
end
meth close
Time.repeat, stop
Tk.canvasTag, tkClose
end
end
class Manager
from Tk.canvas
prop final locking
attr
Balls: nil
Colors: BallColors
meth init(parent:P)
{self tkInit(parent:P bg:BackColor bd:3 relief:sunken
width:CanvasWidth height:CanvasHeight)}
{self tkBind(action: self # NewBall
event: '<1>'
args: [float(x) float(y)])}
{self tkBind(action: self # KillBall
event: '<3>')}
end
meth NewBall(X Y)
lock
C|Cr = @Colors
in
Balls <- {New Ball init(X Y self C)}|@Balls
Colors <- Cr
end
end
meth KillBall
lock
case @Balls of nil then skip
[] B|Br then {B close} Balls <- Br
end
end
end
end
Top = {New Tk.toplevel tkInit(title: 'Oz Bouncer'
delete: Application.exit # 0)}
{Tk.send pack({New Manager init(parent:Top)})}
end
|