Sailboat
The sailboat animation shows how to draw offscreen, and how to use animation frames for smooth movement.
A detailed step-to-step tutorial is available in the Logo manual.
This program was created by Paolo Ruiz.
TO MAKE.SHIP
; Draws the original ship size
setw 3 SETPC "INDIGO
SETH 90 FD 200*.7 RT 100
REPEAT 3 [FD 200*.1 RT 6]
LT 80 FD 200*.2 BK 200*.2 RT 80
SETH 270 FD 200*.55
LT 30 FD 200*.2 BK 200*.2 RT 30
RT 70
REPEAT 5 [FD 200*.06 RT 4]
SETH 90 FD 200*.3 LT 90 FD 200*1.4 RT 150
REPEAT 7 [FD 200*.2 RT 4]
SETH 265
FD 200*.43
SETH 10
REPEAT 6 [FD 200*.21 LT 4]
SETH 200
REPEAT 5 [FD 200*.24 LT 4]
SETH 95
FD 200*.23
; move the turtle to the lower left corner of the drawing
PU SETXY [-28 -80] SETH 0
; then snap the drawing into a bitmap and save the name
MAKE "SHIP (SNAP 200 370 "DRAWING)
; set the ship to WINDOW because we do not want the sailboat to wrap
PPROP :SHIP "WRAPMODE "WINDOW
; remove the drawing and send the turtle home
CS
END
TO MAKE.CLOUD1
HOME PD
SETPC "DARKGRAY
SETH 25 REPEAT 19 [FD 1 RT 3]
SETH 25 REPEAT 29 [FD 1 RT 4]
SETH 90 REPEAT 17 [FD 1 RT 5]
SETH 110 REPEAT 9 [FD 1 RT 4]
SETH 270 FD 58
PU SETH 0 BK 5
MAKE "CLOUD1 (SNAP 60 30 "DRAWING)
CS
END
TO MAKE.CLOUD2
HOME PD
SETPC "DARKGRAY
SETH 25 REPEAT 19 [FD 1 RT 2]
SETH 25 REPEAT 36 [FD 1 RT 3]
SETH 90 REPEAT 17 [FD 1 RT 4]
SETH 85 REPEAT 14 [FD 2 RT 5]
SETH 270 FD 80
PU SETH 0 BK 5
MAKE "CLOUD2 (SNAP 80 40 "DRAWING)
CS
END
TO CLOUD1
TELL :CLOUD1
ST LOCKSHAPE
SETXY [120 190]
SETH 90
SETVELOCITY 20
TELL 0
END
TO CLOUD2
TELL :CLOUD2
ST LOCKSHAPE
SETXY [-200 200]
SETH 90
SETVELOCITY 20
TELL 0
END
TO SHIP
TELL :SHIP
ST LOCKSHAPE
SETXY [50 -525]
TELL 0
END
TO WAVES :X
SETPC "LIGHTSEAGREEN
SETH 120
REPEAT :X [REPEAT 7 [FD 2 LT 10] RT 70]
END
TO HORIZON
; the curved horizon
PU SETY 45 RT 90 PD
SETW 3
SETPC "MEDIUMAQUAMARINE
REPEAT 5 [FD 80 RT 0.5] ;curved horizon
REPEAT 10 [LT 0.5 BK 80]
REPEAT 5 [FD 80 RT 0.5]
; the sun
setpc "gold
SETH 0 REPEAT 19 [FD 10 RT 10]
END
TO SCENERY
CLOUD1
CLOUD2
SHIP
HORIZON
PU SETXY [-120 -60] PD
WAVES 3
PU SETXY [-250 -150] PD
WAVES 5
PU SETXY [200 -120] PD
WAVES 4
END
MAKE "START.POS 203
MAKE "SHIP.POS :START.POS
; Called on every animation frame
TO MOVE.SHIP
IF :SHIP.POS <= 1 THEN (WHEN [ANIMATION FRAME]) STOP
TELL :SHIP
; Move ship slower the farther it gets
FD 1 + :SHIP.POS / 55
MAKE "SHIP.POS :SHIP.POS - 1
SETTS :SHIP.POS / :START.POS
END
TO ANIMATE
DRAW HT
FREEZEPIC
MAKE.SHIP
MAKE.CLOUD1
MAKE.CLOUD2
UNFREEZEPIC
SCENERY
; start the animation frame monitor
WHEN [ANIMATION FRAME] [MOVE.SHIP]
; wait for a TOPLEVEL
WAIT -1
END
ANIMATE
Procedure | ANIMATE |
Description | An animation of a sailboat sailing into the sunset. |
Level | Advanced |
Tags | Animation |