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~
0.
1.
2. Initialize = RunStop(0), ; pop out Run button~pixactive(1), pixsize(320,240), Pixon, pixfill(0),~V0.(ran*160), V1.(ran*120), ; initialize starting X, Y~v2.(1), v3.(1), ; initialize direction flags~PixShapeSet(1, 1, 0, 0),~PixPatternSet(0, rgb(255,128,0), 0),~goto(me+1),~
3. Draw Shape = pixactive(1),~a.(v2), b.(v3), ; save current direction flags~v2.(edgedetect(v2, v0, 40, 320)), ; get new X direction flag~v3.(edgedetect(v3, v1, 40, 240)), ; get new Y direction flag~v0.(v0+(v2*IN1)), v1.(v1+(v3*IN2)), ; calculate new position~o.( iif( a==v2, 0, 1) + iif( b==v3, 0, 2)) ; get direction flags~Switch( o , me+1 , 0), ; image process on edge hit~PixShape(v0, v1, 40, 40, 9001,1), ; draw the shape~out(o) ; output flags if direction changed