javascript - animate canvas up and down based on cylinder height and variable value which i enter in the code -
Animating top and bottom canvas (line) based on variables value.
Here I've added the variable name's name will be below the default my line cylinder. When I enter value as 20, then it grows up and is sub-work if I put value 15, then it has to come down like 0 - 100. So what I tried, I created a variable inside a new function call
function animatecurve () {var status = 0; Warning ("status" + status); Var bottomcylin = $ ('# canvas'). Event (). Top + $ ('# canvas'). External heights (true); Warning ("cylinder bottom" + bottom line); If (condition1> 0) {warning ("inside position" + condition1); $ ('# MyCanvas') Chetan ({Head: "- 10px",}, 300); } And {$ ('# myCanvas'). Animate ({top: "0 px",}, 300); }} Here I got the outer side of the cylinder. It should not be more than the cylinder if I am located at the 30th position then my curve has to be taken over the cylinder.
Please guide me.
Regards M
Take a look, maybe this is what you find
HTML
& lt; Canvas ID = "canvas" width = "300" height = "500" & gt; & Lt; / Canvas & gt; & Lt; Input type = "text" id = "level" placeholder = "type value here" / / gt; Canvas = document.getElementById ('canvas'), ctx = canvas.getContext ('2D'), input = document on javascript
GetElementById ('level'); //help ctx.drawEllipse = function (x, y, radius, color, color board) {this.fillStyle = '# 000'; This.strokeStyle = '# 000'; This.save (); this. Scale (2, 1); This.beginPath (); This.arc (x, y, radius, 0, 2 * monastery; pi, wrong); This.restore (); This.closePath (); If (color) {this.fillStyle = color; This.fill (); If (colorBorder) it. Stroke style = color; } This.stroke (); } Ctx.drawLine = function (startX, startY, endX, endY, color) {if (color) this.strokeStyle = color; Ctx.moveTo (startX, startY); Ctx.lineTo (ANDX, ANDY); Ctx.stroke (); }; / ** * @ param * @ Ultimate X - top left x coordinates * @param Wi - Top left Y coordinate * @param radius - Elipsis radius * @param height - the height of the cylinder * @ Parmal liquid paint - interior liquid paint * @ Parm Trlsnisaidkor - liquid surface color * @param liquidLevel - liquid level ** / ctx.drawCylinder = function (x, y, radius, height, liquidColor, liquidSunnySideColor, liquidLevel) {// do not fall liquidLevel = Math.min (height, LiquidLevel); // Draw Liquid Interior Body ctx.fillStyle = liquidColor; Ctx.fillRect (X, Y + (height - Liquid level), X + radius * 4, Liquid level); //console.log (x, y); // ctx.drawEllipse below (X, Y + height, radius, liquid liquid? Liquid color: wrong); // liquid level CtxkdrawEllipse (x, y + (height - liquidLevel), radius, liquidLevel liquidSunnySideColor: false, true); Ctx.drawEllipse (X, Y + height, radius); // Top cp ctx.drawEllipse (x, y, radius); // Left border CTXDrideline (X, Y, X, Y + height, '# 000'); // Right range ctx.drawLine (x + radius * 4, y, x + radius * 4, y + height, '# 000'); } Var renderLoop = window.webkitRequestAnimationFrame, // workers _fps = 60, _speed = 1, _currentLevel = 0, _maxLevel = 0, _renderTime = 0, _render, time, // cylinder X = 100, Y = 100, Radius = 50, Height = 200; _render = function () {time = window.performance.now (); If (time - _renderTime> 1000 / _fps) {ctx.clearRect (0, 0, 300, 500); // Only positive value _currentLevel = Math.max (0, _currentLevel); If (_currentLevel & gt; _maxLevel) _currentLevel - = _speed; If (_currentLevel & lt; _maxLevel) _currentLevel + = _speed; ctx.drawCylinder (x, y, radius, height, '# 90C94D', '# BBED80', _currentLevel); _renderTime = Time; } Render Loop (_render); } _to present(); input.addEventListener ( 'stigma', function () {// only positive values _maxLevel = Math.max (0, height * Math.min (1, this.value / 100));});
Comments
Post a Comment