Modifying the Curve using HTML 5

Introduction

 
In this article, we are going to understand the concept of Modifying the curve using HTML 5. In this, we can change the curve while it is displaying on the browser.
 
Here we will use some JavaScript and some styles along with the HTML code. Just go through the steps to see how to create this application.
 
Let's see how the modify-curve application can be created. To do so go through the following steps.
 
Step 1 : Open a HTML editor or Visual Studio.
 
sd.gif
 
Open File menu ->select new ->Choose Website then.
 
0000.jpg
 
This is where we will create an HTML5 application.
  • Go to Solution Explorer
  • Right-click on the Application name
  • Select Add-->add new item
  • Now in the window that opens, select an HTML page or new Webform
  • Rename it by modifyingcurve.aspx
md1.gif
 
Step 2: In this section, we will create the style for the media and create the .css on the media screen. Put the given script in the Head section of the HTML or in between the <head>--</head>.
 
Here two CSS files are used for design purposes; one is for the section div, named d1.css and the other d2.css for the whole body of the web page.
 
d1.css scripting
  1. body {  
  2.   background#FFFF99;  
  3.   color#fff;  
  4.   font300 100.1% "Helvetica Neue" , Helvetica"Arial Unicode MS" , Arialsans-serif;  
  5. }  
  6. #holder {  
  7.   height442px;  
  8.   left: 42%;  
  9.   margin-240px 0 0 -320px;  
  10.   positionabsolute;  
  11.   top: 57%;  
  12.   width842px;  
  13.   font-sizex-large;  
  14.   background-color#008000;  
  15. }  
  16. #duplicate {  
  17.   bottom: 0;  
  18.   font300 .7em "Helvetica Neue"Helvetica,;  
  19.   positionabsolute;  
  20.   right: 1em;  
  21.   text-alignright;  
  22. }  
  23. #duplicate d {  
  24.   color#fff;  
  25. }  
  26. d2.css scripting.body {  
  27.   background#fff;  
  28.   color#000;  
  29.   font100.1% "Comic Sans MS", Lucida, Verdanasans-serif;  
  30. }  
  31. #holder {  
  32.   height480px;  
  33.   left: 50%;  
  34.   margin0 0 0 -320px;  
  35.   positionabsolute;  
  36.   top: 0;  
  37.   width640px;  
  38. }  
  39. #duplicate {  
  40.   bottom: 0;  
  41.   font-size: .7em;  
  42.   positionabsolute;  
  43.   right: 1em;  
  44.   text-alignright;  
  45. }  
Step 3: In this part, we need to work on some JavaScript over here. For understanding the full working of JavaScript download the attached .rar file and run the modifycurve application.
 
The whole JavaScript looks like as follow.
  1. window.onload = function() {  
  2.  var dragger = function() {  
  3.    this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx");  
  4.    this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");  
  5.    this.animate({  
  6.     "fill-opacity": .2  
  7.    }, 500);  
  8.   },  
  9.   move = function(dx, dy) {  
  10.    var att = this.type == "rect" ? {  
  11.     x: this.ox + dx,  
  12.     y: this.oy + dy  
  13.    } : {  
  14.     cx: this.ox + dx,  
  15.     cy: this.oy + dy  
  16.    };  
  17.    this.attr(att);  
  18.    for (var i = connections.length; i--;) {  
  19.     r.connection(connections[i]);  
  20.    }  
  21.   },  
  22.   up = function() {  
  23.    this.animate({  
  24.     "fill-opacity": 0  
  25.    }, 500);  
  26.   },  
  27.   r = Color("holder", 640, 480),  
  28.   connections = [],  
  29.   shapes = [r.ellipse(190, 100, 30, 20),  
  30.    r.rect(290, 80, 60, 40, 10),  
  31.    r.rect(290, 180, 60, 40, 2),  
  32.    r.ellipse(450, 100, 20, 20)  
  33.   ];  
  34.  for (var i = 0, ii = shapes.length; i < ii; i++) {  
  35.   var color = Color.getColor();  
  36.   shapes[i].attr({  
  37.    fill: color,  
  38.    stroke: color,  
  39.    "fill-opacity": 0,  
  40.    "stroke-width": 2,  
  41.    cursor: "move"  
  42.   });  
  43.   shapes[i].drag(move, dragger, up);  
  44.  }  
  45.  connections.push(r.connection(shapes[0], shapes[1], "#fff"));  
  46.  connections.push(r.connection(shapes[1], shapes[2], "#fff""#fff|5"));  
  47.  connections.push(r.connection(shapes[1], shapes[3], "#000""#fff"));  
  48. };  
Step 4: In this section, we are going to become familiar with the body part of HTML scripting. Replace this script from the body section of the roundaboutpointer.aspx page.
 
Here we pass a #holder in the div id that is defined in the d1.css file.
  1. <body>  
  2.     <p>  
  3.         Modifying The Curve  
  4.     </p>  
  5.     <hr>  
  6.         <div id="holder"></div>  
  7.     </body>  
Step 5: The Complete code for Playground application.
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="modifyingcurve.aspx.cs" Inherits="_Default" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html  
  4.     xmlns="http://www.w3.org/1999/xhtml">  
  5.     <head runat="server">  
  6.         <link rel="stylesheet" href="d1.css" type="text/css" media="screen">  
  7.             <link rel="stylesheet" href="d2.css" type="text/css" media="print">  
  8.                 <script src="dee.js" type="text/javascript" charset="utf-8"></script>  
  9.                 <script src="dee1.js" type="text/javascript" charset="utf-8"></script>  
  10.                 <style type="text/css" media="screen">  
  11.         #holder  
  12.         {  
  13.             -moz-border-radius: 10px;  
  14.             -webkit-border-radius: 10px;  
  15.             border: solid 1px #333;  
  16.         }  
  17.         p  
  18.         {  
  19.             text-align: center;  
  20.         }  
  21.     </style>  
  22.             </head>  
  23.             <body>  
  24.                 <p>  
  25.         Modifying The Curve  
  26.     </p>  
  27.                 <hr>  
  28.                     <div id="holder"></div>  
  29.                 </body>  
  30.             </html>  
Step 6 : Output Press F5
 
Note:
For the accurate output of HTML5 applications, you must have the Google Chrome browser on your PC. You can change the position by dragging the pointer to any rectangular boxes, ellipse, and circle as shown in the figure.
 
md2.gif