"Drawing a rectangle in Canvas with user input" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "Drawing a rectangle in Canvas with user input" answered properly. Developers are finding an appropriate answer about Drawing a rectangle in Canvas with user input related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like Drawing a rectangle in Canvas with user input. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on Drawing a rectangle in Canvas with user input.
Drawing a rectangle in Canvas with user input
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
$(function(){
// get a reference to the canvas and context
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
// vars for current width and height of a canvas rectangle
var width=50;
var height=35;
// references to the input-text elements
// used to let user change the rect width & height
var $width=document.getElementById('width');
var $height=document.getElementById('height')
// set the initial input-text values to the width/height vars
$width.value=width;
$height.value=height;
// call the draw command
draw();
// listen for keyup events on width & height input-text elements
// Get the current values from input-text & set the width/height vars
// call draw to redraw the rect with the current width/height values
$width.addEventListener("keyup", function(){
width=this.value;
draw();
}, false);
$height.addEventListener("keyup", function(){
height=this.value;
draw();
}, false);
// draw() clears the canvas and redraws the rect
// based on user input
function draw(){
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillRect(40,40,width,height);
}
}); // end $(function(){});
</script>
</head>
<body>
Width:<input type="text" id="width"><br>
height:<input type="text" id="height"><br>
<canvas id="canvas" width=300 height=300></canvas>
</body>
</html>
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on Drawing a rectangle in Canvas with user input can get a collection of related answers to their query. Programmers need to enter their query on Drawing a rectangle in Canvas with user input related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Drawing a rectangle in Canvas with user input for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of Drawing a rectangle in Canvas with user input while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "Drawing a rectangle in Canvas with user input". Visit this developer's friendly online web community, CodeProZone, and get your queries like Drawing a rectangle in Canvas with user input resolved professionally and stay updated to the latest Whatever updates.