EDGEDETECT(current, position, size, outer, inner=0) = IIF(position <= inner, 1, IIF((position+size) >= outer, -1, current)) ~; current must be +/-1, returns current if not at edge~
3. Draw Shape = PixAutoRepaint(0), ; turn off auto repaint for flicker free animation~a.(v2), b.(v3), ; save current direction flags~v2.(edgedetect(v2, v0, 40, PixFrameWidth)), ; get new X direction flag~v3.(edgedetect(v3, v1, 40, PixFrameHeight)), ; get new Y direction flag~x.(v0), y.(v1), ; save previous x,y~v0.(v0+(v2*IN1)), v1.(v1+(v3*IN2)), ; calculate new position~c.(v4), v4.(newcolor(in3, v5, C)), v5.(IN3), ; new color if In3 changes~PixPenColor(c),~PixEllipse(x, y, 40, 40), ; erase the old one~PixPenColor(v4),~PixEllipse(v0, v1, 40, 40), ; draw the new one~PixRepaint, PixAutoRepaint(1), ; force repaint, restore default AutoRepaint~out( iif( a==v2, 0, 1) + iif( b==v3, 0, 2)) ; output flags if direction changed