DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

News

Version1.42 is out since December 2nd 2016


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:draw_smiley

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;
}
sample_code/draw_smiley.txt · Last modified: 2015/09/16 07:18 by stevegarman