(*Nasser Abbasi Feb 19, 2008 *) (*updated 8/12/14*) Manipulate[ tick; Module[{xStep, yStep}, xStep = signX*RandomReal[{0, dx}]; yStep = signY*RandomReal[{0, dy}]; x = x + xStep; y = y + yStep; If[x > 1 - r || x < r, If[x > 1 - r, signX = -1, signX = 1] ]; If[y > 1 - r || y < r, If[y > 1 - r, signY = -1, signY = 1] ]; If[state == "RUN", tick = Not[tick] ]; Graphics[Disk[{x, y}, r], ImageMargins -> 0, Frame -> True, ImagePadding -> 1, PlotRangeClipping -> False, PlotRange -> {{0, 1}, {0, 1}}] ], {{dx, 0.01, "x step size"}, .001, 0.1, .001, AppearanceElements -> All}, {{dy, 0.01, "y step size"}, .001, 0.1, .001, AppearanceElements -> All}, {{r, 0.1, "radius of ball"}, .05, 1, .01, AppearanceElements -> All}, Grid[{ {Button["run", state = "RUN"; tick = Not[tick]], Button["stop", state = "STOP"]} }], {{state, "STOP"}, None}, {{tick, False}, None}, {{signX, 1}, None}, {{signY, 1}, None}, {{x, .5}, None}, {{y, .5}, None}, ContinuousAction -> False, TrackedSymbols :> {tick} ]