You are on page 1of 21

SQUARE

Sides: 4 Angle: 90 degree (90 = 360 / 4 = 360 / Sides) Length: 100 or any other

Repeat 4 [fd 100 rt 90] OR Repeat 4 [fd 100 rt 360/4]

Hexagon/Polygon

Sides: 4 Angle: 60 degree (60 = 360 / 6 = 360 / Sides) Length: 100 or any other

Repeat 4 [fd 100 rt 60] OR Repeat 4 [fd 100 rt 360/6]

Hassan:

Edit “Square

To Square :sides :length

Repeat :sides[fd :length rt 360/:sides]

End

On commander window call procedure as:

Square 4 100

Introducing REPCOUNT AND SETFC

REPCOUNT is always equal to the number of times the REPEAT loop has run.

REPEAT 5 [PRINT REPCOUNT WAIT 10]


Stick Man Figure
December 23, 2017Object

to stickman
  circle 10 pu bk 10 pd bk 10
  lt 45 bk 20 fd 20
  rt 90 bk 20 fd 20
  lt 45 bk 25
  lt 30 bk 30 fd 30
  rt 60 bk 30 lt 30
end

Boat and a Man Rowing it…


December 23, 2017Object

to boat
  rt 90 fd 100 lt 60 fd 20 lt 120 fd 120 lt 120 fd 20 lt 60 fd 20 lt 90
  pu fd 10 setfc [255 0 0] fill fd 8
  pd setpensize [2 2]
  fd 30 pu fd 10 pd
  circle 10
  pu bk 20 rt 135 fd 20 bk 20 pd fd 20 fd 10 rt 135 lt 135 lt 90
  setpc [165 65 65 ] setpensize [3 3]
  fd 10 fd 10 bk 50 bk 20
  setpensize [5 5]
  fd 10 lt 45
  pennormal
end

Sun with Rays…


December 22, 2017Object

to sun
  setfc [255 255 0] setpc [255 255 0] setpensize [2 2]
  circle 50 fill
  repeat 12 [fd 75 bk 75 rt 360/12]
end

Village WELL
December 21, 2017Object

to well
  setfc [255 0 0] setpc [255 255 180]
  rect 60 120
  rt 45 pu fd 10 fill bk 10 lt 45 pd
  rect 50 120 rect 40 120 rect 30 120 rect 20 120 rect 10 120

  fd 60 lt 90 rt 180


  repeat 3[fd 30 rt 90 fd 10 bk 10 lt 90] bk 90
  lt 90 bk 10 rt 90
  repeat 2[fd 40 rt 90 fd 10 bk 10 lt 90] bk 80
  lt 90 bk 10 
  rt 90 repeat 3[fd 30 rt 90 fd 10 bk 10 lt 90] bk 90
  lt 90 bk 10 rt 90 repeat 2[fd 40 rt 90 fd 10 bk 10 lt 90] bk 80
  lt 90 bk 10 rt 90 repeat 3[fd 30 rt 90 fd 10 bk 10 lt 90] bk 90
  lt 90 bk 10 rt 90 repeat 2[fd 40 rt 90 fd 10 bk 10 lt 90] bk 80

  setpc [0 0 0] lt 90 bk 10
  rect 120 120 fd 120 rt 90 fd 60
  lt 90
  setpc [255 255 180] setpensize [2 2]
  fd 5 bk 5
  setpc [255 255 180] setpensize [6 6]
  fd 5 bk 10
  setpensize [2 2]
  bk 55
  pennormal
end

to bucket
  setpc [0 0 0] pd
  rt 90 fd 20 lt 60 fd 30 lt 120 fd 50
  rt 90
  arc2 180 25 pu arc2 180 25 pd lt 90

  lt 120 fd 30 lt 120 pu fd 20


  setfc [125 125 125] fill
  bk 20
  lt 30
end

to RECT :H :W
  REPEAT 2 [ FD :H RT 90 FD :W RT 90 ]
end
Designing a real life TREE
December 21, 2017Objectcoding, kabir mathur, mslogo, procedure, tree

Tree Design
Save the procedures and invoke it using “Tree <size>“. E.g. Tree 100

to tree :n
  setpc [165 65 65]   setpensize [6 6]
  fd :n  lt 60
  repeat 5 [branch :n rt 30]
  lt 90 pennormal
end

to branch :n
  setpc [165 65 65]  setpensize [3 3]
  fd :n  lt 60
setpensize [2 2]
repeat 5 [fd :n/2 leaf :n/4
  setpc [165 65 65]  setpensize [2 2]
  bk :n/2 rt 30]
lt 90  bk :n
end

to leaf :n
  setpc [0 165 0]  setpensize [1 1]
  lt 30
  repeat 7 [fd :n bk :n rt 10]
  lt 40
end
Car with Fancy Wheel
Spokes & Smoke
December 23, 2017Object

to car
  pu fd 20 pd fd 40 rt 90 fd 40 lt 60
  fd 40 rt 60
  fd 80 rt 60
  fd 40 lt 60
  fd 80 rt 90
  fd 40 lt 90 bk 80

  circle 20
  repeat 24 [ fd 20 bk 20 rt 360/ 24 ]
  bk 120
  circle 20
  repeat 24 [ fd 20 bk 20 rt 360/ 24 ]
  bk 40 lt 90
 rect 40 240

  pu
  rt 90
  fd 10 lt 90 fd 10
  setfc [255 0 0 ] fill
  rt 90 fd 80 lt 90 fd 40
  setfc [ 0 0 165 ] fill
  pu bk 50
  lt 90 fd 60 fd 40 fd 30
  pd
  cloud 5 2

  pu bk 10 
  setfc [ 50 50 50 ] fill
  bk 5
  setfc [ 50 50 50 ] fill
  pu fd 50 pd
  cloud 5 2
  pu bk 10
  setfc [ 50 50 50 ] fill
  bk 5
  setfc [ 50 50 50 ] fill
end

to RECT :H :W
  REPEAT 2 [ FD :H RT 90 FD :W RT 90 ]
end

to CLOUD :N :LOOP
  REPEAT 2 [ ARC2 180 :N LT 90 REPEAT :LOOP [ ARC2 180 :N LT 180 ] RT 90]
end

Village Scenery
December 24, 2017Theme
Village scenery code base is provided below. Save these procedures in the MS Logo
Editor. From the commander window call the procedure main.

to boat
rt 90 fd 100 lt 60 fd 20 lt 120 fd 120 lt 120 fd 20
lt 60 fd 20 lt 90
pu fd 10 setfc [255 0 0] fill fd 8
pd setpensize [2 2] fd 30
pu fd 10 pd circle 10
pu
bk 20 rt 135 fd 20
bk 20 pd fd 20 fd 10 rt 135lt 135 lt 90
setpc [165 65 65 ]
setpensize [3 3]
fd 10 fd 10 bk 50 bk 20
setpensize [5 5]
fd 10 lt 45
pennormal
end

to branch :n
pd
setpc [165 65 65]
setpensize [3 3]
fd :n
lt 60
setpensize [2 2]
repeat 5 [fd :n/2 leaf :n/4
setpc [165 65 65]
setpensize [2 2]
bk :n/2 rt 30]
lt 90
bk :n
end

to bucket
setpc [0 0 0]
pd
rt 90 fd 20 lt 60 fd 30 lt 120 fd 50
rt 90
arc2 180 25 pu arc2 180 25 pd lt 90

lt 120 fd 30
lt 120
pu fd 20
setfc [125 125 125] fill
bk 20
lt 30
end

to CLOUD :N :LOOP
REPEAT 2 [ ARC2 180 :N LT 90 REPEAT :LOOP [ ARC2 180 :N LT 180 ] RT 90]
end

to crop :n
setpensize [ 2 2 ]
setpc [ 0 165 0 ]
fd :n
lt 30
repeat 3 [ fd :n*3/4 bk :n*3/4 rt 30 ] lt 60
bk :n
end

to field
pennormal pd
pd repeat 10 [ pd
repeat 10 [crop 10 pu rt 90 fd 15 lt 90 pd] crop 10
pu lt 90 fd 150 rt 90 bk 20 ]

end
to house
pennormal
pd
rect 100 100
fd 100
rt 30 fd 100
rt 120
fd 100
lt 90
rt 45
lt 15
bk 100
lt 90
bk 100
rt 90
fd 40
lt 90
lt 90
fd 10
rt 90
rect 60 40
pu
fd 200
bk 100
fd 20
setfc [165 65 65] fill
setfc [0 165 0] fill
bk 40
setfc [200 100 100] fill
rt 90
fd 10
lt 90
bk 40
setfc [165 65 65] fill
end

to leaf :n
pd
setpc [0 165 0]
setpensize [1 1]
lt 30
repeat 7 [fd :n bk :n rt 10]
lt 40
end

to main

pu
bk 350
lt 90 fd 500
rt 90
pd rect 500 1000
rt 90
fd 500
lt 90

arc2 90 500
pu arc2 270 500
pd rt 90 fd 150 lt 90

arc2 90 350
pu home
setfc [32 224 63]
fill
rt 90
rt 45
fd 300
setfc [32 224 63]
fill
bk 100
setfc [167 202 255]
fill
lt 90
lt 90
lt 30
rt 15
pennormal
pd
boat
pu
rt 90
fd 200
rt 90
fd 50
lt 180
rt 45
lt 30
rt 15
pennormal
pd
boat
pu
fd 20
setfc [255 255 0]
fill
rt 90
fd 20
fd 10
setfc [255 255 0]

fill
pu
home
bk 200
bk 50
bk 100
rt 90
fd 50
lt 90
fd 20
lt 75

pennormal pd
lt 15
rt 10
lt 5
pu

bk 20
rt 90
fd 20
lt 90
rt 5
pennormal
pd boat
pu
fd 20
setfc [0 0 255]
fill
rt 90
fd 50
setfc [0 0 255]
fill
pu
home
lt 90
fd 200
lt 90
fd 200
fd 100
lt 180
fd 200
fd 100
fd 120
bk 120
bk 50
pennormal
pd
well
pu
pennormal
pu
bk 60
lt 90
fd 60
fd 50
rt 90
bucket
lt 90
fd 100
lt 90
fd 250
fd 50
bk 30
lt 180
bk 20
pennormal
pd
tree 60
pennormal
pu
bk 60
rt 90
fd 200
lt 90
rt 90
fd 10
lt 90
lt 90 fd 10
lt 90
lt 180
pennormal pd
tree 65
pu
pennormal
pu
fd 300
lt 90
fd 250
fd 50
rt 90
fd 100
rt 90 fd 200
bk 50
bk 150
lt 90
pu
bk 10
lt 90
fd 20
rt 90
field
pennormal pu
rt 45
fd 200
fd 40
fd 20
lt 90
rt 45
pennormal
setpensize [2 2]
pd man
pu
bk 200
lt 90
fd 200
bk 60
rt 90
fd 50
fd 20
pd man
pu
rt 90
fd 300
lt 45
fd 200
fd 100
lt 90
bk 50
rt 45
pd pennormal
tree 30
rt 45
pennormal pu
fd 100
lt 45
bk 40
pennormal pd
tree 30
lt 45
rt 90
pu
pennormal pu
bk 200
lt 45
pd
rt 90
pu fd 10
fd 10
lt 90
bk 10
bk 10
pd tree 30
pu
rt 90
fd 200
fd 100
lt 90
bk 100
pu
bk 200
bk 2
bk 1
pd
house
pu
lt 90
fd 200
rt 90
pd
repeat 10 [crop 10 pu rt 90 fd 15 lt 90 pd]
pu lt 90 fd 150 rt 90 bk 20
repeat 10 [crop 10 pu rt 90 fd 15 lt 90 pd]
pu lt 90 fd 150 rt 90 bk 20
fd 20
pd
crop 10
pu
rt 90
fd 250
fd 30
lt 90
fd 30
rt 90
fd 5
lt 90
fd 5
pd man
pennormal
pu
fd 50
rt 90
fd 5
fd 5
fd 2
fd 1
fd 1
lt 90
fd 30
bk 20
fd 10
setpc [32 224 64] setpensize [2 2] man
fd 40
rt 90
fd 20
bk 2
bk 1
lt 90
fd 20
fd 2
fd 10
setpc [32 224 64] setpensize [3 3] man
setpc [32 224 63] setpensize [3 3] man
pd
pu
home
bk 35
home
bk 350
rt 90
fd 480
lt 90
fd 60
lt 90
fd 5
fd 50
bk 45
fd 2
fd 1
rt 90
bk 1
bk 2
fd 10
setpc [32 224 63] setpensize [3 3] man
pu
fd 70
fd 10
rt 90
fd 10
fd 2
lt 90
rt 90
fd 7
lt 90
pd pennormal
setpensize [2 2] man
pu
lt 45
fd 200
fd 10
rt 90
lt 90
fd 10
rt 45
pd pennormal
tree 30
pu rt 45
fd 100
lt 45
bk 20
bk 10
pd pennormal
tree 30
pu
lt 90
fd 300
fd 50
lt 90
fd 75
rt 90
fd 20
rt 90
pd pennormal
tree 30
pennormal
pu
fd 400
setfc [0 255 255]
fill
bk 20
bk 20
fd 10
lt 90
fd 300
fd 50
fd 20
rt 90
setfc [255 255 0]
setpc [255 255 0]
setpensize [2 2]
circle 50
pd
circle 50
fill
repeat 12 [fd 75 bk 75 rt 360/12]
pu
pennormal
pu
fd 400

pu
home
fd 200
fd 20
lt 90
pd
cloud 25 3
pu
bk 200
bk 50
bk 20
pd cloud 20 2
pu
fd 300
fd 200
bk 50
pd
pd cloud 20 2
pu
bk 20
setfc [100 100 100]
fill
bk 200
fill
bk 300
fill
pennormal
pu
home
setpensize [2 2]
fd 400
bk 200
bk 30
lt 45
fd 40
fd 20
lt 45
fd 20
rt 180
fd 10
bk 10
pd fd 10
rt 60
fd 10
lt 120
fd 10
rt 60 fd 10
pu
fd 250
pd fd 10
rt 60
fd 10
lt 120
fd 10
rt 60 fd 10
pu
rt 60
fd 20
lt 60
pd fd 10
rt 60
fd 10
lt 120
fd 10
rt 60 fd 10
pennormal pu
end

to man
pd circle 10 pu bk 10 pd bk 10
lt 45 bk 20
fd 20
rt 135
lt 45
bk 20
fd 20
lt 45
bk 20
bk 5
lt 30
bk 30
fd 30
rt 60
bk 30
lt 30
end

to rect :h :w
repeat 2[fd :h rt 90 fd :w rt 90]
end

to sun
setfc [255 255 0] setpc [255 255 0] setpensize [2 2]
circle 50 fill
repeat 12 [fd 75 bk 75 rt 360/12]
end

to tree :n
pd
setpc [165 65 65]
setpensize [6 6]
fd :n
lt 60
repeat 5 [branch :n rt 30]
lt 90
pennormal
end

to well
setfc [255 0 0]
setpc [255 255 180]
rect 60 120
rt 45 pu fd 10 fill bk 10 lt 45 pd
rect 50 120 rect 40 120 rect 30 120 rect 20 120 rect 10 120

fd 60
lt 90
rt 180
repeat 3[fd 30 rt 90 fd 10 bk 10 lt 90] bk 90
lt 90
bk 10
rt 90
repeat 2[fd 40 rt 90 fd 10 bk 10 lt 90] bk 80
lt 90 bk 10
rt 90
repeat 3[fd 30 rt 90 fd 10 bk 10 lt 90] bk 90
lt 90 bk 10 rt 90
repeat 2[fd 40 rt 90 fd 10 bk 10 lt 90] bk 80
lt 90 bk 10 rt 90
repeat 3[fd 30 rt 90 fd 10 bk 10 lt 90] bk 90
lt 90 bk 10 rt 90
repeat 2[fd 40 rt 90 fd 10 bk 10 lt 90] bk 80

setpc [0 0 0]
lt 90 bk 10
rect 120 120
fd 120
rt 90 fd 60
lt 90
setpc [255 255 180] setpensize [2 2]
fd 5
bk 5
setpc [255 255 180] setpensize [6 6]
fd 5
bk 10
setpensize [2 2]
bk 55
pennormal
end

You might also like