shapes.polygon()- used to draw the first six shapes on the top row
shapes.roundedRect()- used to draw the last shape on the top row
shapes.stars()- used to draw all the stars on the second row
shapes.ellipse()-used to draw the firs two ellipses on the third row
shapes.cuboid()- used to draw the fourth shape on the third row
The third shape on the bottom row is a composite shape made up of two ellipses and a rectangle.
The fifth shape on the bottom row is another composite shape made up of a cuboid and a polygon. The polygon is an octagon.
The JavaScript functions all worked with Chrome, Firefox, IE11 and Safari.
They also worked on all the mobile devices they were tested on.
window.shapes.stars=function(context,xC,yC,r,R,nSp,lw,arcCol,fillStar,fillCol,rotAng)
{ var theta=360/nSp,theta=theta*Math.PI/180, //Theta to radiansfor(var i=0; i< nSp i++)
alpha=theta/2,
rotAng=rotAng*Math.PI/180; //rotAngle to radians
//Draw star
context.save();
context.beginPath();
context.translate(xC,yC); //Rotate star
context.rotate(rotAng);
context.lineWidth=lw; //Create star
context.lineCap=("round");
context.strokeStyle=arcCol;
context.fillStyle=fillCol;
context.moveTo(0,R);
{context.rotate(alpha);} if(fillStar)
context.lineTo(0,r);
context.rotate(alpha);
context.lineTo(0,R);
context.stroke();
{context.fill(); //Fill star}
context.stroke(); //Draw star strokes}//End stars
context.restore();
Star dimensions are in pixels or degrees
Star properties are defined as-
var xC=200, x coordinate of the star centre
yC=160, y coordinate of the star centre
r=50, radius of the inner circle
R=150, radius of the outer circle
nSp=8, number of star points
lw=2, width of the star stroke
arcCol="blue", colour of the star stroke
fillStar=true,
fillCol="red",
rotAng=30, Rotates the star about its centre
The function call for the 8 point star is
star01=window.shapes.stars(context,xC,yC,r,R,nSp,lw,arc Col,fillStar,fillCol,rotAng);
Stars can be drawn with any number of star points, but this is affected by the canvas resolution.