Draw Star Using Web Application In TypeScript

In this article, we draw a star in a web application in TypeScript.

First we download some files in the following attachment:

  1. Kinect.d.ts

  2. Kinectic.min.js

These files are added to the project then use the following procedure.

Step 1

Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is opened. In this window, click "HTML Application for TypeScript" under Visual C#.

Give the name of your application as "Draw_Star" and then click "Ok".

Step 2

After this session the project has been created; a new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the ts file, js file and css file and aspx page.

wondow-explorer.jpg

Coding

app.ts

/// <reference path="Kinect.d.ts" />

class Draw_Star

{

    Star()

    {

        var stage = new Kinetic.Stage({

            container: 'content',

            width: 358,

            height: 200

        });

        var layer = new Kinetic.Layer();

 

        var star = new Kinetic.Star({

            x: stage.getWidth() / 2,

            y: stage.getHeight() / 2,

            numPoints: 6,

            innerRadius: 50,

            outerRadius: 90,

            fill: 'blue',

            stroke: 'black',

            strokeWidth: 4

        });

 

        layer.add(star);

        stage.add(layer);

    }

}

window.onload = () =>

{

    var obj = new Draw_Star();

    obj.Star();

};

 

Image_Animation_Demo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Draw_Star.aspx.cs" Inherits="Draw_Star.Draw_Star" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title></title>

    <script src="star.js"></script>

    <script src="Kinetic.min.js" type="text/javascript"></script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <h3>Star In TypeScript Using Web Application</h3>

        <div id="content"></div>

    </div>

    </form>

</body>

</html>

 

app.js

/// <reference path="Kinect.d.ts" />

var Draw_Star = (function () {

    function Draw_Star() { }

    Draw_Star.prototype.Star = function () {

        var stage = new Kinetic.Stage({

            container: 'content',

            width: 358,

            height: 200

        });

        var layer = new Kinetic.Layer();

        var star = new Kinetic.Star({

            x: stage.getWidth() / 2,

            y: stage.getHeight() / 2,

            numPoints: 6,

            innerRadius: 50,

            outerRadius: 90,

            fill: 'blue',

            stroke: 'black',

            strokeWidth: 4

        });

        layer.add(star);

        stage.add(layer);

    };

    return Draw_Star;

})();

window.onload = function () {

    var obj = new Draw_Star();

    obj.Star();

};

//@ sourceMappingURL=star.js.map

 

Output   


line.jpg


For more information, download the attached sample application.