A programmable robotic mouse is placed at an intersection on a square grid, the borders of which are extendable as needed.
From its initial location the mouse moves one cell forward.
It turns right with its next move incrementing by 1.
This incremental process continues up to a certain constraint whereby the mouse resumes the process with a move of one space until that constraint is met again; continue this process until you either return to your starting position or you evidently will never return.
What generalisations can be made about how variations of the value of the constraint affect the path forced upon the mouse? |
|
Note:It will be necessary to test a range of constraining values.
I have taken a relook at the program that was my reference, and is within the published solution. I have condensed it according to what I understand as better programming practices. While I haven't followed this through, I believe that within "SUB plot", the value of "v" should be the target for constraint conditions that are in nikki's mind.
I trust that this structure is sufficiently coherent that more modern "languages" can address this with limited modification. And that my annotation truly reflects the coding.
DECLARE SUB startpos ()
DECLARE SUB plot ()
DECLARE SUB keyin ()
DECLARE SUB path ()
DECLARE SUB star ()
DIM SHARED move 'counts steps
DIM SHARED a 'For..Next label
DIM SHARED f 'For..Next label
DIM SHARED L 'sides of polygon
'Since Rt angle turns, L=4
DIM SHARED s 'For..Next label
DIM SHARED v 'Maximum steps (move)
'before iteration
DIM SHARED z 'Determines move length
DIM SHARED x 'horizontal coordinate
DIM SHARED y 'vertical coordinate
DIM SHARED gr 'mod value of or$ input
DIM SHARED or$
CLS
SCREEN 9
COLOR 15, 8
CLS
PRINT "No. from 1 to 20",
INPUT or$
IF or$ <> "*" THEN
startpos
plot
END IF
Keyin ‘holds screen display
SUB keyin
DO
LOOP WHILE INKEY$ <> CHR$(13)
END SUB
SUB path
FOR a = 1 TO s
SELECT CASE move 'this is C equiv. of switch
CASE 1 'up
LINE (x, y)-(x, y - z), 7
y = y - z
CASE 2 'left
LINE (x, y)-(x - z, y), 7
x = x - z
CASE 3 'down
LINE (x, y)-(x, y + z), 7
y = y + z
CASE 4
LINE (x, y)-(x + z, y), 7
x = x + z
END SELECT
star
NEXT a
END SUB
SUB plot
move = 1
FOR f = 1 TO L
FOR s = 1 TO v ‘v determines the shape
path
move = move + 1
IF move = 5 THEN move = 1
NEXT s
NEXT f
END SUB
SUB star
LINE (x - 1, y + 1)-(x + 1, y - 1), 14
LINE (x - 1, y - 1)-(x + 1, y + 1), 14
END SUB
SUB startpos
v = VAL(or$)
z = 18 'param for step size
z = INT(6 * z / v) '6 only reduces
'initial z value
'for convenience
x = 320 'centre of screen values
y = 200 'startpos may be offset.
gr = (v / 4 - INT(v / 4)) * 4
'determines the "mod" value
'of the spiral category
L = 4
IF v = 1 THEN gr = 1
IF gr = 0 THEN y = 60: x = 100
IF gr = 1 THEN y = 240: x = 350
IF gr = 2 THEN L = 2
IF gr = 3 THEN x = 300: y = 150
END SUB
Edited on January 26, 2008, 3:49 am
|
Posted by brianjn
on 2008-01-26 03:25:26 |