Draw a Smiley

This demo was written by Sankarshan Dudhate.

smiley.js
//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );    
    //Get size for a square imsge
    var siz=square(1);
    //Create an empty image to act as our drawing canvas of full width and height.
    img = app.CreateImage(null,siz.w,siz.h);
    //img=app.CreateImage(null,1,1);
    lay.AddChild(img); //Add it to layout.
 
    img.SetColor("#ffffffff"); //Set colour of our canvas to white.
    img.SetPaintColor("#ff000000"); //Set colour objects darwn on canvas to 'Black'.
                                    
    img.SetPaintStyle("Line"); //Set style of objects drawn on canvas to 'Line.'
    img.SetLineWidth(3); //Set LineWidth of obiects drawn to 3 pixels. 
    img.DrawCircle(0.5,0.2,0.18); //Draw a circle with center at (0.5,0.2) and radius 0.18 of device's width. 
 
    img.SetPaintStyle("Fill"); //Set style of objects drawn to 'Fill'.
 
    img.SetPaintColor("#ff444444"); //Set colour of objects drawn to 'Gray'.
    img.DrawCircle(0.42,0.16,0.04); //Draw circle with center at (0.42,0.16) and radius 0.04
    img.DrawCircle(0.57,0.16,0.04); //Center at (0.57,0.16) and radius 0.04.
 
    img.SetPaintColor("#ff0000"); //Set colour of objects drawn to 'Red'.
 
    //Draw an arc.
    //Pattern : (x1,y1,x2,y2,StartAngle,EndAngle).
    img.DrawArc(0.43,0.22,0.57,0.28,0,180);
 
    //Add layout to app. App will be empty if no layout is added.
    app.AddLayout( lay );
}
 
function square(size)
{
    var ratio = app.GetDisplayWidth() /
        app.GetDisplayHeight();
    var ret={};
    if (ratio >= 1) // landscape
    {
        ret.w = size / ratio;
        ret.h = size;
    }
    else
    {
        ret.w = size;
        ret.h = size * ratio;
    }
    return ret;
}