siteIcon

TNTShamrock

Challenges Home

shamrock
Hints:

Looking at the JSGS gallery of shapes, there is no shape available to make the body of the shamrock! (The stem may be made by one of the library shapes -- which one?!)

You must create the engine to make the body of the 3 leaf shamrock!

Features:
Comments:

You must find a shape in the library that is similar to the shamrock and find the associated JavaScript that creates that shape.

Make a copy of the code and create a work area where you create a TNTShamrock by modifying the code you 'stole,' adapting it to mathematical equation(s) you will have to find on the Internet!

Most of the TNT Graphic shapes are not based on classes. See if you can modernize the code to use the class keyword!

Here is the code that was used to create the picture above:

blackStroke.lineWidth = .1;
shouldShowStem = true;
stemOrientation = 0; //0, random; 1, right; 2, left; 3 fixed
var myShamrock = new TNTShamrock(origin, 7, darkGreen, blackStroke, 15, shouldShowStem, stemOrientation);
myShamrock.drawTNTShamrock(context);
                                        
Primary Attributes:

7 Parameters:

  • center: TNTPoint
  • distance to a 'lobe': a decimal
  • fillColor: TNTColor (can be null for a framework image)
  • borderStroke: a TNTStroke: to set the border color as well as the thickness of the sides
  • rotationDeg: a 'double' that rotates the image about its center.
    rotn > 0 ==> counter-clockwise; rotn < 0 ==> clockwise
    At 0° the top leaf axis of symmetry aligns with the y-axis
  • shouldShowStem: a boolean
  • stemOrientation: an integer such that...
    1. random: can be left or right of centerline
    2. right: on the right of the centerline
    3. left: on the left of the centerline
    4. fixed: fixed on centerline, fixed length