View Single Post
  #143   Report Post  
Posted to uk.d-i-y
Gordon Henderson Gordon Henderson is offline
external usenet poster
 
Posts: 459
Default OT - Programming Languages

In article ,
Syd Rumpo wrote:
On 28/01/2015 21:48, Ferretygubbins wrote:
I know this is OT but I rather suspect that some of you will be able to
help.

Boy1 (13) is interested in learning how to write code and so I would
like to set him up with a toolkit for his PC (Windows) unfortunately my
programming days are somewhat in the past and restricted to MUMPS which
was archaic even back then. Has anyone any suggestions for a suitable
platform? As ever the cheaper the better.

Cheers

Mark


Whatever the choice, programming a version of Langton's Ant (see
Wikipedia) makes an interesting first project.


One I've not heard of - but since it was "invented" in 1986 and I started
programming almost 10 years earlier, it's no surprise (to me, anyway!)

So for a bit of fun in my BASIC:

// Langton's ant

// The rules are simple: Our ant starts in the middle then:
// At a white square, turn right, flip the square colour,
// move forward 1 square.
// At a black square, turn left, flip the square colour,
// move forward 1 square.


x = gwidth / 2
y = gheight / 2
direction = 0

cls

cycle

if getpixel (x, y) = black then
direction = direction + 1
if direction = 4 then direction = 0
colour = white
plot (x, y)
else
direction = direction - 1
if direction = -1 then direction = 3
colour = black
plot (x, y)
endif

proc updateAnt

update
repeat

def proc updateAnt
switch (direction)
case 0
y = y + 1
endcase

case 1
x = x + 1
endcase

case 2
y = y - 1
endcase

case 3
x = x - 1
endcase

endswitch
endproc

Seems to produce the desired output.

Note: spaced indentation is not significant, nor forced. It's there for
my convenience, not the computers!

That's quite a good one - nice and simple. Doesn't need an array if the
display device can be read back (not always possible or very inneficient
on some modern systems!)

Gordon