
previous

page 21
next
So all we have to do is use join to connect all the corners of the polygon.
But, wait! How do we know where they are?
So we need to get into the fd function and store the x and y values.
globals.js
...
var g_xx=[];
var g_yy=[];
var g_xx=[];
var g_yy=[];
my.js
function fd(d) {
...
g_ctx.stroke();
store();
...
}
function store() {
g_xx.push(Math.round(g_x));
g_yy.push(Math.round(g_y));
}
function cs() {
g_ctx.clearRect(0,0,g_side,g_side);
g_pen='down'; g_xx=[]; g_yy=[];
}
function rose(n=11) {
cpolygon(n);
for (var i=0;i<n-1;i++) {
for (var j=i+1;j<n;j++) {
join(g_xx[i],g_yy[i],g_xx[j],g_yy[j]);
}
}
}
...
g_ctx.stroke();
store();
...
}
function store() {
g_xx.push(Math.round(g_x));
g_yy.push(Math.round(g_y));
}
function cs() {
g_ctx.clearRect(0,0,g_side,g_side);
g_pen='down'; g_xx=[]; g_yy=[];
}
function rose(n=11) {
cpolygon(n);
for (var i=0;i<n-1;i++) {
for (var j=i+1;j<n;j++) {
join(g_xx[i],g_yy[i],g_xx[j],g_yy[j]);
}
}
}
previous
next