- 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 Web form
- Rename it to sheartransform.aspx
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 between the <head>--</head> tags. Here the CSS is used for design purposes.
CSS Script
<style>
body
{
margin: 0px;
padding: 0px;
}
#myCanvas
{
border: 2px solid #FFFFCC;
margin-top: 50px;
margin-left: 50px;
background-color: #CCCCCC;
box-shadow: 5px 5px 8px #222;
}
.title
{
text-align: center;
font-family: Segoe UI Light, Arial, Helvetica;
font-size: 2.2em;
margin: 1em;
}
.info
{
text-align: center;
font-family: Segoe UI Light, Arial, Helvetica;
font-size: 1.2em;
margin: 0.25em;
}
</style>
Step 3 : In this part we need to work on some JavaScript. To fully understanding how the JavaScript works, download the attached .rar file and run the CanvasShearTransforms application.
The whole JavaScript looks as in the following.
<script>
window.onload = function ()
{
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var rectWidth = 150;
var rectHeight = 75;
var sx = 0.75;
var sy = 0;
context.translate(canvas.width / 2, canvas.height / 2);
// apply custom transform
context.transform(1, sy, sx, 1, 0, 0);
context.fillStyle = "red";
context.fillRect(-rectWidth / 2, -rectHeight / 2, rectWidth, rectHeight);
};
</script>
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 sheartransform.aspx page. Here we pass a Canvas in the canvas tag:
<body style="background-color: #FFCCCC">
<center>
<h1>
Canvas Shear Transform
</h1>
</center>
<hr />
<canvas id="myCanvas" width="540" height="200">
</canvas>
</body>