N-pointed stars
makestar = Function( {x, y, npoints, inside, outside},
{p = J( 2 * npoints, 3, . ), angle, i, move = 1, draw = 2},
For( i = 1, i < N Rows( p ), 0,
angle = 2 * Pi() * i / N Rows( p );
p[i, 1] = x + Sin( angle ) * inside; // sin and cos are reversed here to
p[i, 2] = y + Cos( angle ) * inside; // make the point be at the top.
p[i, 3] = If( i == 1, move, draw ); // swap sin/cos for point at left.
i += 1;
angle = 2 * Pi() * i / N Rows( p );
p[i, 1] = x + Sin( angle ) * outside; // ditto
p[i, 2] = y + Cos( angle ) * outside;
p[i, 3] = If( i == N Rows( p ), -draw, draw );
i += 1;
);
p; // return
);
New Window( "Example",
gb = Graph Box(
xaxis( Show Major Grid( 1 ) ),
yaxis( Show Major Grid( 1 ) ),
framesize( 500, 500 ),
Pen Color( "red" );
Pen Size( 3 );
Fill Color( "blue" );
npoints = 3; // each star gets more points below
For( xx = 20, xx <= 80, xx += 20,
For( yy = 20, yy <= 80, yy += 20,
// the inside/outside ratio needs to change with more points...
p = makestar( xx, yy, npoints, 2 + npoints / 4, 8 );
Path( p, 1 ); // blue solid fill
Path( p, 0 ); // red outline
npoints += 1;
)
);
)
);
// move the grid lines above the stars
grid = gb[framebox( 1 )] << find seg( SegPlaceholder( 1 ) );
// grid is the original, below the stars
gb[framebox( 1 )] << appendseg( grid ); // makes a copy above
// probably not needed...they are on top of each other...
grid << delete; // delete the original from below
Craige