Matteo Franchin's corner

snake.gdlΒΆ

An example of usage of the instruction “Line”

_images/snake-medium.jpg

Figure: after running the GDL program, we obtain this image (postscript format in this case)

 ' This example shows how powerful is the algorithm for line-drawing
 ' implemented in GDL: you will see how the instruction Line can be
 ' used to draw a snake

 include "stddefs.gdl"

' We draw the tongue as a separate object
tongue <- Window !type "fig"
>< Poly dark_red, (0.5, 0), (0.5, 4), 0, 1, (0.5, 5), 1, 0, (1, 5), _
 0, 1, (0, 5), 1, 0, (0, 4.5), 0, 1, (0, 5), 1, 0, (-1, 5), _
 0, 1, (-0.5, 5), 1, 0, (-0.5, 4), (-0.5, 0)

' Here we draw the eye
eye <- Window !type "fig"
>< Circle yellow, (0, 0), !ra 1, !rb 0.5
>< Circle black, (0, 0), !ra 0.1, !rb 0.5
>< Circle dark_green

' Now we use the tongue and the eye to draw the face
face <- Window !type "fig"
A = (5, -5)
B = (7, 0)
C = (4, 8)
D = (0, 9)
>< Poly dark_green, A, 0.5, B, C, D, (-C.x, C.y),  (-B.x, B.y), (-A.x, A.y)
>< Put tongue, (0, 6)
>< Put eye, (2.6, 0), -70, !scale 1.5
>< Put eye, (-2.6, 0), 70, !scale 1.5

' We need these hot points to decide how the instruction Line
' should use this figure to end or start the line it draws
A = Hot[(0, 9)]
A = Hot[(0, 5)]
A = Hot[(0, -4)]

' Now this is all what we need to draw the snake!!!
snake <- Window !type "fig"
>< Line dark_green, line_smooth, (10, 10), 1, 4, (40, 100), 4, 5, (80, 10), _
 (120, 90), (150, 25), (170, 55), face, (195, 70)

output <- Window !type "ps", !file "snake.ps"
>< Put (0, 0), snake, !scale 1