- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
可能我很笨,但我需要帮助做一件简单的事情。
我想在单击按钮时将正弦波的速度从正常的 2 更改为 10。仅此而已,但我不知道该怎么做。
SineWave.js 的 Github 链接:Sinewave.js
代码:
var waves = new SineWaves({
el: document.getElementById('waves'),
speed: 2,
ease: 'SineInOut',
wavesWidth: '75%',
waves: [
{
timeModifier: 4,
lineWidth: 1,
amplitude: -25,
wavelength: 25
},
{
timeModifier: 2,
lineWidth: 1,
amplitude: -10,
wavelength: 30
},
{
timeModifier: 1,
lineWidth: 1,
amplitude: -30,
wavelength: 30
},
{
timeModifier: 3,
lineWidth: 1,
amplitude: 40,
wavelength: 40
},
{
timeModifier: 0.5,
lineWidth: 1,
amplitude: -60,
wavelength: 60
},
{
timeModifier: 1.3,
lineWidth: 1,
amplitude: -40,
wavelength: 40
}
],
resizeEvent: function() {
var gradient = this.ctx.createLinearGradient(0, 0, this.width, 0);
gradient.addColorStop(0,"rgba(25, 255, 255, 0)");
gradient.addColorStop(0.5,"rgba(255, 25, 255, 0.75)");
gradient.addColorStop(1,"rgba(255, 255, 25, 0");
var index = -1;
var length = this.waves.length;
while(++index < length){
this.waves[index].strokeStyle = gradient;
}
index = void 0;
length = void 0;
gradient = void 0;
}
});
Codepen 示例:
https://codepen.io/anon/pen/GxEKJZ?editors=1010
请帮助我,因为这个我现在快要死了......(甚至可能是一个很小的变化)
最佳答案
这是一个使用 jQuery 的实现:
var waves = new SineWaves({
el: document.getElementById('waves'),
speed: 2,
ease: 'SineInOut',
wavesWidth: '75%',
waves: [
{
timeModifier: 4,
lineWidth: 1,
amplitude: -25,
wavelength: 25
},
{
timeModifier: 2,
lineWidth: 1,
amplitude: -10,
wavelength: 30
},
{
timeModifier: 1,
lineWidth: 1,
amplitude: -30,
wavelength: 30
},
{
timeModifier: 3,
lineWidth: 1,
amplitude: 40,
wavelength: 40
},
{
timeModifier: 0.5,
lineWidth: 1,
amplitude: -60,
wavelength: 60
},
{
timeModifier: 1.3,
lineWidth: 1,
amplitude: -40,
wavelength: 40
}
],
resizeEvent: function() {
var gradient = this.ctx.createLinearGradient(0, 0, this.width, 0);
gradient.addColorStop(0,"rgba(25, 255, 255, 0)");
gradient.addColorStop(0.5,"rgba(255, 25, 255, 0.75)");
gradient.addColorStop(1,"rgba(255, 255, 25, 0");
var index = -1;
var length = this.waves.length;
while(++index < length){
this.waves[index].strokeStyle = gradient;
}
index = void 0;
length = void 0;
gradient = void 0;
}
});
$("#change_speed").click(function(){
waves.options.speed = 10;
});
<script src="https://isuttell.github.io/sine-waves/javascripts/sine-waves.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="waves" width="300" height="180"></canvas>
<button id='change_speed'>Change Speed</button>
更新:
如果您不尝试通过 resizeEvent
函数保留渐变,这里有一个更改颜色的示例:
var waves = new SineWaves({
el: document.getElementById('waves'),
speed: 2,
ease: 'SineInOut',
wavesWidth: '75%',
waves: [{
timeModifier: 4,
lineWidth: 1,
amplitude: -25,
wavelength: 25,
strokeStyle: 'rgba(0, 0, 255, 0.1)'
},
{
timeModifier: 2,
lineWidth: 1,
amplitude: -10,
wavelength: 30,
strokeStyle: 'rgba(0, 0, 255, 0.1)'
},
{
timeModifier: 1,
lineWidth: 1,
amplitude: -30,
wavelength: 30,
strokeStyle: 'rgba(0, 0, 255, 0.1)'
},
{
timeModifier: 3,
lineWidth: 1,
amplitude: 40,
wavelength: 40,
strokeStyle: 'rgba(0, 0, 255, 0.1)'
},
{
timeModifier: 0.5,
lineWidth: 1,
amplitude: -60,
wavelength: 60,
strokeStyle: 'rgba(0, 0, 255, 0.1)'
},
{
timeModifier: 1.3,
lineWidth: 1,
amplitude: -40,
wavelength: 40,
strokeStyle: 'rgba(0, 0, 255, 0.1)'
}
]
});
$("#change_color").click(function() {
waves.waves[0].strokeStyle = 'rgba(0, 0, 255, 0.9)';
waves.waves[1].strokeStyle = 'rgba(255, 0, 255, 0.9)';
waves.waves[2].strokeStyle = 'rgba(255, 0, 0, 0.9)';
waves.waves[3].strokeStyle = 'rgba(0, 255, 0, 0.9)';
waves.waves[4].strokeStyle = 'rgba(0, 255, 225, 0.9)';
waves.waves[5].strokeStyle = 'rgba(255, 255, 0, 0.9)';
});
<script src="https://isuttell.github.io/sine-waves/javascripts/sine-waves.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="waves" width="300" height="180"></canvas>
<button id='change_color'>Change Color</button>
关于Javascript:动态改变正弦波速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49432426/
这是我的问题 1)我有动态y数组数据,使用该数组如何连续绘制波浪。 如果Y数组数据完整,则使用相同的y数组数据继续。 2)声音自动播放在该数组值是143.if我停止不停止。 这是我的代码:
网络上有太多使用 WiFi 或蓝牙传输数据的对讲机应用程序(至少我见过的所有应用程序),但没有一个使用内置天线通过 radio 波传输数据真正的对讲机设备。 是否有任何安全原因?还是限制作为发送器/接
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve this
我正在尝试着手研究 boost wave,但到目前为止,我的运气并不好。 我尝试了网站上的示例代码。如下: #include #include #include #include #inclu
我正在尝试使用 svg 编写一个 javascript 加载器。想法是,它是一个从下到上两侧均匀填充的圆圈,加载器的顶线是一个从左到右不断移动的正弦波。 我能够根据百分比为加载程序创建弧线,如下所示:
这个问题在这里已经有了答案: Is there a one-line function that generates a triangle wave? (8 个答案) 关闭 9 年前。 我试图用 A
当我在论坛中搜索时,我了解到要定位 GPS,我必须通过互联网连接或短信发送坐标。但据我所知,我们可以通过 radio 波进行通信,发送语音、图片、数据。我可以用它来获取数据吗? GPS 设备?因为业余
我是一名优秀的程序员,十分优秀!