sine-wave
Its a simple javascript plugin to build a beautiful sine wave on the given canvas. It allows user to add multiple elements on the same canvas. A demo of the working project is here.
Copy the Wave.min.js inside your working directory and insert the script tag inside your HTML document.
<script type="txt/javascript" src="Wave.min.js" />
The following code segment will produce a sine wave on the canvas.
<!-- Canvas Holder for the animation --><canvas id="anim" width="500" height="500"></canvas>
var canvas = document.getElementById("anim");var context = canvas.getContext("2d");var firstwave = new Wave({ canvas: canvas }); firstwave.draw();
Takes Config object to configure the wave. It is compulsory to provide the Config Object.
Syntax
var wave = new Wave(config);
Method to draw a single sine wave on the canvas. It uses window.requestAnimationFrame()
to animate the wave on the canvas. The canvas is cleared at each step,
hence this method cannot be used to draw more than one element on the
canvas.
See .redraw()
to draw multiple elements on the same canvas.
Syntax
wave.draw();
Method to draw a single keyframe of the sine wave on the canvas. It must be used with users own animation method to draw each keyframe after an interval.
Syntax
var myanim = function() { window.requestAnimationFrame(myanim); wave.clearCanvas(); wave.redraw(); }
Method to clear the entire canvas for redraw of keyframes.
Syntax
wave.clearCanvas();
Holds the DOM canvas object. It must be passed for the application to work. If no canvas object is pass, an exception is thrown.
The frequency of the sine wave. It defines the number of waves inside the given canvas. Default value is 0.005.
The phase with which the sine wave will be produced. Default value is 30.
The amplitude with which the sine wave will be produced. Default value is 50.
The color of the sine wave. Default value is red.
Shift defines the relative speed of the wave. It is responsible for wave animation. Default value is 10.
The width of the line sine wave. Default value is 4.
Boolean flag to show/hide the sine wave outline. It is compulsory to
show the outline when working with line sine wave. It can be removed
when filling the wave. Default value is true
.
Boolean flag to fill the bottom of the wave with the given color.
This will hide the other waves if their values are lower than the last
wave. Default value is false
.
Boolean flag to add gradient to the fill property of the sine wave.
The gradient used will be color to transparent from top to bottom.
Default value is false
.
Object describing the position of the start of the sine wave. Contains keys x
and y
for defining coordinates of the wave from the top left of the canvas. Default value is { x: 0, y: canvas.height/2 }
.
Boolean flag to fix the start position of wave. The y offset at start
position will be 0. A damping factor will be applied to the rest of the
wave depending upon the distance from the start position. Default value
is false
.
Boolean flag to fix the end position of wave. The y offset at end
position will be 0. A damping factor will be applied to the rest of the
wave depending upon the distance from the end position. Default value is false
.
Damping factor applied to each wave y-coordinate if fixedStart or/and fixedEnd is enabled. Default value is 0.5
.
var waveList = []; var colors = ["#F44336", "#E91E63", "#9C27B0", "#673AB7", "#3F51B5", "#2196F3", "#03A9F4", "#00BCD4"]; /** * Clear the canvas and then draw all the waves on the canvas. Utilize requestAnimationFrame for recursion. **/ var draw = function() { window.requestAnimationFrame(draw); // draw all features waveList[0].clear(); for(var w of waveList) w.redraw(); } // build 3 waves and push it to waveList for(var i = 0; i < 3; i++) { waveList.push( new Wave({ canvas: canvas, color: colors[Math.floor(Math.random() * colors.length-1)], phase: 30 * i, shift: 10 * (i+1), amplitude: 10 * (i+1), outline: true }) ); } // fire it up draw();
上一篇:SINESP_Consulta
下一篇:raml-spec
还没有评论,说两句吧!
热门资源
seetafaceJNI
项目介绍 基于中科院seetaface2进行封装的JAVA...
spark-corenlp
This package wraps Stanford CoreNLP annotators ...
Keras-ResNeXt
Keras ResNeXt Implementation of ResNeXt models...
capsnet-with-caps...
CapsNet with capsule-wise convolution Project ...
shih-styletransfer
shih-styletransfer Code from Style Transfer ...
智能在线
400-630-6780
聆听.建议反馈
E-mail: support@tusaishared.com