Draw Star Using Web Application In TypeScript

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
  1. class Draw_Star {  
  2.  Star() {  
  3.   var stage = new Kinetic.Stage({  
  4.    container: 'content',  
  5.    width: 358,  
  6.    height: 200  
  7.   });  
  8.   var layer = new Kinetic.Layer();  
  9.   var star = new Kinetic.Star({  
  10.    x: stage.getWidth() / 2,  
  11.    y: stage.getHeight() / 2,  
  12.    numPoints: 6,  
  13.    innerRadius: 50,  
  14.    outerRadius: 90,  
  15.    fill: 'blue',  
  16.    stroke: 'black',  
  17.    strokeWidth: 4  
  18.   });  
  19.   layer.add(star);  
  20.   stage.add(layer);  
  21.  }  
  22. }  
  23. window.onload = () => {  
  24.  var obj = new Draw_Star();  
  25.  obj.Star();  
  26. };  
Image_Animation_Demo.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Draw_Star.aspx.cs" Inherits="Draw_Star.Draw_Star" %>  
  2. <!DOCTYPE html>  
  3. <html  
  4.     xmlns="http://www.w3.org/1999/xhtml">  
  5.     <head id="Head1" runat="server">  
  6.         <title></title>  
  7.         <script src="star.js"></script>  
  8.         <script src="Kinetic.min.js" type="text/javascript"></script>  
  9.     </head>  
  10.     <body>  
  11.         <form id="form1" runat="server">  
  12.             <div>  
  13.                 <h3>Star In TypeScript Using Web Application</h3>  
  14.                 <div id="content"></div>  
  15.             </div>  
  16.         </form>  
  17.     </body>  
  18. </html>  
app.js
  1. var Draw_Star = (function() {  
  2.  function Draw_Star() {}  
  3.  Draw_Star.prototype.Star = function() {  
  4.   var stage = new Kinetic.Stage({  
  5.    container: 'content',  
  6.    width: 358,  
  7.    height: 200  
  8.   });  
  9.   var layer = new Kinetic.Layer();  
  10.   var star = new Kinetic.Star({  
  11.    x: stage.getWidth() / 2,  
  12.    y: stage.getHeight() / 2,  
  13.    numPoints: 6,  
  14.    innerRadius: 50,  
  15.    outerRadius: 90,  
  16.    fill: 'blue',  
  17.    stroke: 'black',  
  18.    strokeWidth: 4  
  19.   });  
  20.   layer.add(star);  
  21.   stage.add(layer);  
  22.  };  
  23.  return Draw_Star;  
  24. })();  
  25. window.onload = function() {  
  26.  var obj = new Draw_Star();  
  27.  obj.Star();  
  28. };  
Output   
 
line.jpg
 
For more information, download the attached sample application.