Polygons

In pf you can draw different types of polygons. In this simple script you can find an example of most of them.

You draw polygons by storing vectors in a matrix, and if needed, a color in another matrix. You pack the 2 matrices together and pass them to a polygon word. The words available are: points, lines, linestrip, lineloop, triangles, trianglefan, trianglestrip, quads, quadstrip, and polygon.

load-opengl                     # load the OpenGl PF plugin
320 240 display                 # initialize a 320 by 240 window
2d                              # set the environment for 2D
drawing                         # start the drawing system 

0.1 scale                       # scale the world geometry from 1 to 10

: ndup          for dup next ;  # a word to simplify duplicating

points

((0.2 0.1)  (0.22 0.1) (0.24 0.1) (0.26 0.1) (0.28 0.1) (0.3 0.1)) >matrix
(1. 1. 1.) 5 ndup 6 pack >matrix
2 pack "cv" points

lines

((0. 2.)  (1. 2.) (2. 3.) (3. 3.) (4. 4.) (5. 4.)) >matrix
(1. 0. 0.) 5 ndup 6 pack >matrix
2 pack "cv" lines

linestrip

((-2. 1.) (-2.4 -1.) (-2.8 1.) (-3. -1.) (-3.4 1.)) >matrix
(1. 1. 0.) 4 ndup 5 pack >matrix
2 pack "cv" linestrip

lineloop

((0. 0.) (1. 0.3) (1.5 0.8) (0.5 0.4)) >matrix
(1. 0. 1.) 5 ndup 6 pack >matrix
2 pack "cv" lineloop

triangles

((-2. 3.) (-5. 3.) (-3.5 2.)) >matrix
(0.5 0.5 0.5) 2 ndup 3 pack >matrix
2 pack "cv" triangles

quads

((-3. -3.) (-4. -3.) (-4. -4.) (-3. -4.)) >matrix
(0.1 0. 0.5) 3 ndup 4 pack >matrix
2 pack "cv" quads

polygon

((3. -2.) (4. -2.) (4. -4.) (3. -4.) (2. -3.)) >matrix
(1. 0.4 0.7) 4 ndup 5 pack >matrix
2 pack "cv" polygon

Attachments