Squeak
  QotD    "The more I dig, the deeper I go, the more I realize how little I know" – Mayuresh A Kathe
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Bots Inc Experiments 1
Last updated at 5:56 am UTC on 16 February 2017

Experiments from the Book Programming with Robots

See Stéphane Ducasse, Programming with Robots .

This site is intended primarily for readers of the Bots Inc book, but not exclusivly, everybody can feel free to try out the code, experiment with different values ,colors ,images and enjoy the results. The readers of the book are strongly recommended to do the experiments by their self to obtain own solutions. Please feel free to add your own experiments code or send it to me for adding it via e-mail or which I prefer via snail-mail.



       Experiments Chapter 3          (Of Robots and men not ready :-) )
       Experiments Chapter 4          (Directions and Angles not ready :-) )
       Experiments Chapter 6          (Fun with robots)
       Experiments Chapter 7          (Looping not ready) )
       Experiments Chapter 8          (Variables not ready :-) )
       Experiments Chapter 10        (Loops and Variables )
       Experiments Chapter 12        (Methods: Named Message Sequences)
       Experiments Chapter 13        (Combining Methods)
       Experiments Chapter 14        (Parameters and arguments not ready :-) )
       Experiments Chapter 16        (Decomposing to recompose not ready :-) )
       Experiments Chapter 17        (Strings, and tools for understanding programs not ready :-) )
       Experiments Chapter 21        (Coordinates, points, and absolute moves :-) )




Experiments Chapter 6 (Fun with robots)

ladybug.gif
ladybug.frm

Experiments Chapter 6 (Fun with robots)       TOC

Experiment 10-1 (Placement of the Increment in the Loop)


" Experiment 10-1 (Placement of the Increment in the Loop)
  The Stair begins with 20 pixel when last line moved to the
  first line in the loop "


¦ pica treadLength ¦

pica
:= Bot new .
treadLength := 10 .

10 timesRepeat:
 [ treadLength := treadLength + 10 .
   pica go: treadLength .
   pica turnLeft: 90 .
   pica go: 5 .
   pica turnRight: 90 . ]



Experiment 10-2 (Another Bizarre Staircase)


" Experiment 10-2 (Another Bizarre Staircase ) "

¦ pica treadLength riseLength ¦

pica
:= Bot new .
treadLength := 10 .
riseLength := 5 .

10 timesRepeat:
 [ pica go: treadLength .
   pica turnLeft: 90 .
   pica go: riseLength .
   pica turnRight: 90 .
   riseLength := riseLength + 5 .
   treadLength := treadLength + 10 . ]



Experiment 10-3 (Simple Maze)


" Experiment 10-3 (Simple Maze) "

¦ pica increaseSquare ¦

pica
:= Bot new .
increaseSquare := 0 .

50 timesRepeat:
 [ pica go: 10 + increaseSquare .
   pica turnLeft: 90 .
   pica go: 10 + increaseSquare .
   pica turnLeft: 90 .
   increaseSquare := increaseSquare + 10 ] .

2  timesRepeat:
 [ pica go: increaseSquare + 10 .
   pica turnLeft: 90 ]
.


Experiment 10-3 (Picture from the beginning of chapter 10)


" Picture from the beginning of chapter 10 Loops and Variables, Experiment 10-3 (A Simple Maze). "

¦ pica increaseSquare ¦

pica
:= Bot new .
increaseSquare := 0 .

40 timesRepeat:
 [ pica go: 10 + increaseSquare .
   pica turnLeft: 90 .
   pica go: 10 + increaseSquare .
   pica turnLeft: 90 + 2 .
   increaseSquare := increaseSquare + 10 ]
.


Experiment 10-3 (A nice spiral)


" Experiment 10-3 (A nice spiral) "

¦ pica increaseTriangle ¦

pica
:= Bot new .
increaseTriangle := 0 .

90 timesRepeat:
 [ pica go: increaseTriangle + 10 .
   pica turnLeft: 120 + .
   increaseTriangle := increaseTriangle + 10 ] .



Experiment 10-4 (Russian Squares Simple Solution)


" Experiment 10-4 (Russian Squares Simple Solution
  the drawing of the figure whithout jumping and twice drawing of lines
  is so far not possible – evidence culpable "


¦ russquare squareLength ¦

russquare
:= Bot new .
squareLength := 10 .

30 timesRepeat:
 [ 4 timesRepeat:
   [ russquare go: squareLength .
     russquare turnLeft: 90 ] .
   squareLength := squareLength + 10 ] .

After a while of trying to draw the russian squares whithout jumping and draw lines twice one could believe it is not possible.The evidence of the impossibillity can be probably achieved thru the analysis of the seven bridges of Königsberg and the use of the graph theory to express the evidence mathematicaly. Please don't hestiate to draw a graph.


Experiment 10-5 (A Long Corridor)


" Experiment 10-5 (aLongCorridor) "

¦ corridor sideLength growth ¦

corridor
:= Bot new .
growth := 20 .
sideLength := growth .

30 timesRepeat:
 [ 4 timesRepeat:
   [ corridor go: sideLength .
     corridor turnLeft: 90 . ] .
    corridor west .
    corridor jump: growth / 2 .
    corridor south .
    corridor jump: growth / 2 .
    corridor east .
    sideLength := sideLength + growth ]
.



Experiment 10-6 (Squares)


"Experiment 10-6 (Squares)"

¦ squares ¦

squares
:= Bot new .

11 timesRepeat:
 [ squares go: 300 .
   squares west .
   squares jump: 300 .
   squares north .
   squares jump: 30 .
   squares east ] .

squares south .
squares jump: 30 .

11 timesRepeat:
 [ squares go: 300 .
   squares north .
   squares jump: 300 .
   squares east .
   squares jump: 30 .
   squares south ] .



Experiment 10-7 (Pyramid)


"Experiment 10-7 (Pyramid)"

¦ squares length ¦

squares
:= Bot new .
length := 400 .

9 timesRepeat:
 [ squares go: length .
   squares west .
   squares jump: length .
   squares north .
   squares jump: 50 .
   squares east .
   length := length - 50 ] .

squares := 400 .
squares south .
squares jump: 50 .

9 timesRepeat:
 [ squares go: length .
   squares north .
   squares jump: length - 50 .
   squares east .
   squares jump: 50 .
   squares south .
   length := length - 50 ] .



Experiments Chapter 10 ( Loops and Variables )       TOC


Experiment 12-1 (A Simple Abstract Design)


pattern

"Experiment 12-1 (A simple abstract design)"

self go: 100 ;
     turnLeft: 90 ;
     go: 100 ;
     turnLeft: 90 ;
     go: 50 ;
     turnLeft: 90 ;
     go: 100 ;
     turnLeft: 90 ;
     go: 25 ;
     turnLeft: 90 ;
     go: 25 ;
     turnLeft: 90 ;
     go: 50 ;


Experiment 12-2 (A Method for the Art Nouveau Picture Frame)


frame50

"Experiment 12-2 (A method for the art nouveau picture frame)"

4 timesRepeat:
  [self go: 100 ;
     turnLeft: 90 ;
     go: 100 ;
     turnLeft: 90 ;
     go: 50 ;
     turnLeft: 90 ;
     go: 100 ;
     turnLeft: 90 ;
     go: 25 ;
     turnLeft: 90 ;
     go: 25 ;
     turnLeft: 90 ;
     go: 50 ]


Experiments Chapter 12 ( Methods: Named Message Sequences )       TOC


Experiment 13-1 (Pattern four times)


pattern4

"Experiment 13-1 (pattern four times)"

4 timesRepeat:
  [self pattern ]



Experiment 13-2 (A Ferris Wheel)


tiltedPattern

"Experiment 13-2 (a ferris wheel)"

9 timesRepeat:
  [self pattern ;
        turnLeft: 10 ;
        go: 50 ]



Experiment 13-3 (Doubling the Frame)


doubleFrame

"Experiment 13-3 (Doubling the Frame)"

8 timesRepeat:
  [ self pattern .
    self turnLeft: 45 .
    self go: 100 ]


frame

Experiment 13-3 (Doubling the Frame)"

2 timesRepeat:
  [ self doubleFrame .
    self go: 100 ]

The result is not exact the same as in the picture in the book on page 151 but frame doubles the doubleFrame. In this experiment we can see how important it is to choose proper names for the methods which describes what the method does and not how the method does it. My example is a very bad solution we should avoid this art of programming


Experiment 13-4 (Some Boxes)


box

"Experiment 13-4 (Four squares = box)"

self square .
self go: 100 .
self square .
self north .
self go: 100 .
self east .
self square .
self west .
self go: 100 .
self east .
self square


boxRelative

"Experiment 13-4 (boxRelative)"

self square .
self go: 100 .
self square .
self turn: 90 .
self go: 100 .
self turn: -90 .
self square .
self turn: 180 .
self go: 100 .
self turn: -180 .
self square


boxCentered

"Experiment 13-4 (boxCentered)"

4 timesRepeat:
  [ self square .
    self turn: 90 ]

separatedBox

"Experiment 13-4 (separated Box)"

self square .
self jump: 100 .
self south .
self jump: 10 .
self east .
self square .
self north .
self jump: 100 .
self east .
self jump: 10 .
self square .
self north .
self jump: 10 .
self west .
self jump: 100 .
self east .
self square .


separatedBoxCentered

"Experiment 13-4 (separated Box Centered)"

4 timesRepeat:
  [ self square ; turn: 90 ; go: 10 ]



Experiment 13-5 (My Choice)


"Experiment 13-5 (My Choice I)"
¦ pica ¦
pica
:= Bot new .
pica north .
pica jump: 450 .
pica east .

12 timesRepeat:
   [ pica pattern .
     pica go: 10 .
     pica turn:
60 ] .

"Experiment 13-5 (My Choice II)"
¦ pica dally ¦

pica := Bot new penColor: Color red .
dally := Bot new penColor: Color blue .

pica north ; jump: ; east .
dally north ; jump: ; east .

12 timesRepeat: [ pica pattern ; go: 10 ;turn: 60 ] .
6 timesRepeat: [ dally pattern ; turn: 30 ] .

pica beInvisible .
dally beInvisible .


Experiment 13-6 (A Star)


starRight

"Experiment 13-6 (Star on the right hand)"

2 timesRepeat:
  [ self boxCentered ; turn: 45]

starLeft

"Experiment 13-6 (Star on the left hand)"

6 timesRepeat:
  [ self separatedBoxCentered ; turn: 15]


Experiments Chapter 13 ( Methods: Named Message Sequences )       TOC