Draw Circle Using Web Application In TypeScript

Introduction 

 
In this article, we draw a circle in a web application using TypeScript.
 
First, we download some files in the following attachment:
  1. Kinect.d.ts
  2. Kinectic.min.js
These file 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_Circle" 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.
 
 solution-explorer.jpg
 

Coding

 
app.ts
  1. /// <reference path="Kinect.d.ts" />  
  2. class Draw_Circle  
  3. {  
  4.  Circle()  
  5.  {  
  6.   var stage = new Kinetic.Stage({  
  7.    container: 'content',  
  8.    width: 250,  
  9.    height: 200  
  10.   });  
  11.   var layer = new Kinetic.Layer();  
  12.   var circle = new Kinetic.Circle({  
  13.    x: stage.getWidth() / 2,  
  14.    y: stage.getHeight() / 2,  
  15.    radius: 70,  
  16.    fill: 'blue',  
  17.    stroke: 'black',  
  18.    strokeWidth: 4,  
  19.   });  
  20.   layer.add(circle);  
  21.   stage.add(layer);  
  22.  }  
  23. }  
  24. window.onload = () =>  
  25.  {  
  26.   var obj = new Draw_Circle();  
  27.   obj.Circle();  
  28.  };  
Image_Animation_Demo.aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Draw_Circle_Demo.aspx.cs" Inherits="Draw_Circle.Draw_Circle_Demo" %>  
  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="app.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>Circle In TypeScript Using Web Application</h3>  
  14.                 <div id="content"></div>  
  15.             </div>  
  16.         </form>  
  17.     </body>  
  18. </html>  
app.js
  1. var Draw_Circle = (function() {  
  2.  function Draw_Circle() {}  
  3.  Draw_Circle.prototype.Circle = function() {  
  4.   var stage = new Kinetic.Stage({  
  5.    container: 'content',  
  6.    width: 250,  
  7.    height: 200  
  8.   });  
  9.   var layer = new Kinetic.Layer();  
  10.   var circle = new Kinetic.Circle({  
  11.    x: stage.getWidth() / 2,  
  12.    y: stage.getHeight() / 2,  
  13.    radius: 70,  
  14.    fill: 'blue',  
  15.    stroke: 'black',  
  16.    strokeWidth: 4  
  17.   });  
  18.   layer.add(circle);  
  19.   stage.add(layer);  
  20.  };  
  21.  return Draw_Circle;  
  22. })();  
  23. window.onload = function() {  
  24.  var obj = new Draw_Circle();  
  25.  obj.Circle();  
  26. };   
Output 
 
Image.jpg  


Similar Articles