function getShapeParams() {
var shapeParams = {};
shapeParams = {
radius: document.getElementsByClassName('radius')[0].value.toString(),
x1Crd: document.getElementsByClassName('circle-x1-crd')[0].value.toString(),
x2Crd: document.getElementsByClassName('circle-y2-crd')[0].value.toString()
};
console.log(shapeParams.radius);
}
function circle() {
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
getShapeParams(shapeParams);
this.radius = shapeParams.radius;
this.x1Crd = shapeParams.x1Crd;
this.x2Crd = shapeParams.x2Crd;
context.clearRect(0, 0, canvas.width, canvas.height);
context.beginPath();
context.arc(x1Crd, x2Crd, radius, 0, Math.PI*2, false);
context.fillStyle = 'red';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'red';
context.stroke();
}
circle();
<body>
<div class="container">
<div class="col-lg-12 text-center">
<h3>Get your own shapes</h3>
</div>
<div class="row">
<div class="col-lg-8">
<label>Here ya draw:</label>
<canvas height='360' width='720' id='canvas'></canvas>
</div>
<div class="col-lg-4">
<label>Ur settings:</label>
<form class="form">
<div class="form-group">
<select class="form-control shape-type">
<option value="">Choose shape type</option>
<option value="circle">Circle</option>
<option value="rectangle">Rectangle</option>
<option value="triangle">Triangle</option>
</select>
<div class="help-block">Select type and input shape parameters</div>
</div>
<div class="circle-form">
<div class="form-group">
<label>Radius:</label>
<input type="number" class="form-control radius" value="10" />
</div>
<div class="form-group">
<label>X-crd:</label>
<input type="number" class="form-control circle-x1-crd" value="50" />
</div>
<div class="form-group">
<label>Y-crd:</label>
<input type="number" class="form-control circle-y2-crd" value="20" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
function getShapeParams() {
var shapeParams = {};
shapeParams = {
radius: document.getElementsByClassName('radius')[0].value.toString(),
x1Crd: document.getElementsByClassName('circle-x1-crd')[0].value.toString(),
x2Crd: document.getElementsByClassName('circle-y2-crd')[0].value.toString()
};
console.log(shapeParams.radius);
return shapeParams;
}
getShapeParams(shapeParams);
заменить на var shapeParams = getShapeParams();
и все должно работать.var shapeParams = {};
function getShapeParams() {
shapeParams = {
radius: document.getElementsByClassName('radius')[0].value.toString(),
x1Crd: document.getElementsByClassName('circle-x1-crd')[0].value.toString(),
x2Crd: document.getElementsByClassName('circle-y2-crd')[0].value.toString()
};
console.log(shapeParams.radius);
}
function circle() {
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
getShapeParams();
this.radius = shapeParams.radius;
this.x1Crd = shapeParams.x1Crd;
this.x2Crd = shapeParams.x2Crd;
context.clearRect(0, 0, canvas.width, canvas.height);
context.beginPath();
context.arc(x1Crd, x2Crd, radius, 0, Math.PI*2, false);
context.fillStyle = 'red';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'red';
context.stroke();
}
circle();