- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章js实现三角形粒子运动由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了js实现三角形粒子运动的具体代码,供大家参考,具体内容如下 。
效果(这里只是截了一个静态图,实际上里面的粒子是运动状态的):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
title
>粒子</
title
>
<
style
>
* {
margin: 0;
padding: 0;
}
body {
overflow: hidden;
}
</
style
>
<
script
>
//随机数获取 3 10 *7+3
function random(min, max) {
return Math.random() * (max - min) + min;
}
//亮色系
// colors = ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', '#f15c80', '#e4d354', '#8085e8', '#8d4653', '#91e8e1'];
//暗色系
colors = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3']
//获取窗口宽高
var width = window.innerWidth;
var height = window.innerHeight;
function Bubble() {
this.r = random(5, 100);
this.x1 = random(this.r, this.r * 2);
this.y1 = random(this.r, this.r * 2);
this.x2 = random(this.r, this.r * 2);
this.y2 = random(this.r, this.r * 2);
this.x3 = random(this.r, this.r * 2);
this.y3 = random(this.r, this.r * 2);
//随机获取colors数组里的颜色
this.color = colors[Math.floor(random(0, colors.length))];
//偏移步长
this.xr = random(-5, 5);
this.yr = random(-5, 5);
}
Bubble.prototype = {
//绘制
draw: function (context) {
//开始路径
context.beginPath();
context.moveTo(this.x1, this.y1);
context.lineTo(this.x2, this.y2);
context.lineTo(this.x3, this.y3);
context.lineTo(this.x1, this.y1);
context.fillStyle = this.color;
context.fill();
},
//移动
move: function (context) {
this.x1 += this.xr;
this.y1 += this.yr;
this.x2 += this.xr;
this.y2 += this.yr;
this.x3 += this.xr;
this.y3 += this.yr;
//边缘检测
(this.x1 > width || this.x1 <
0
) ? this.xr = -this.xr : null;
(this.y1 > height || this.y1 <
0
) ? this.yr = -this.yr : null;
(this.x2 > width || this.x2 <
0
) ? this.xr = -this.xr : null;
(this.y2 > height || this.y2 <
0
) ? this.yr = -this.yr : null;
(this.x3 > width || this.x3 <
0
) ? this.xr = -this.xr : null;
(this.y3 > height || this.y3 <
0
) ? this.yr = -this.yr : null;
this.draw(context);
}
}
window.onload
=
function
() {
//获取画布dom
var
canvas
=
document
.querySelector('canvas');
//设置canvas的宽高
canvas.width
= width;
canvas.height
= height;
//获取画布上下文对象
var
context
=
canvas
.getContext('2d');
//数组存储bubble
var arr = [];
//生成粒子
var
total
=
100
;
//生成例子
for (var
i
=
0
; i < total; i++) {
var
bubble
=
new
Bubble();
bubble.draw(context);
arr.push(bubble);
}
var
id
=
setInterval
(function () {
//清除
context.clearRect(0, 0, width, height);
//开始移动
for (var
i
=
0
; i < arr.length; i++) {
arr[i].move(context);
}
}, 1000 / 60)
//点击次数
var
count
=
0
;
canvas.onclick
=
function
() {
if (count++ % 2 == 0) {
//停止
clearInterval(id);
} else {
//运行
id
=
setInterval
(function () {
//清除
context.clearRect(0, 0, width, height);
//开始移动
for (var
i
=
0
; i < arr.length; i++) {
arr[i].move(context);
}
}, 1000 / 60)
}
}
}
</script>
</
head
>
<
body
>
<
canvas
title
=
"点击停止,再次点击活动"
></
canvas
>
</
body
>
</
html
>
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/barbed/article/details/108691063 。
最后此篇关于js实现三角形粒子运动的文章就讲到这里了,如果你想了解更多关于js实现三角形粒子运动的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
这是否可以检测到手机何时像图片上那样移动?这个在android中叫什么名字? 是否有处理此类事情的事件?一年前,我看到一个带指南针的应用程序,它可以实时运行。 谢谢! 最佳答案 我希望这段代码能有所帮
我正在为这个而撕扯我的头发。出于某种奇怪的原因,我找不到/想不出如何在 SFML 和/或 SDL 中移动 Sprite 。我看过的这两个库的教程对此一无所知;所以我认为它更像是 C++ 的东西而不是库
所以我最近一直在研究 DirectX11,但我对它还是很陌生。我现在正在尝试通过翻译来移动一些东西,这就是我所拥有的。我一直在阅读 Frank D Luna 关于 DirectX11 的书,他提供了一
我一直在尝试为绘图元素制作动画,但没有成功。我可以对导入的图像进行动画处理,但是当我尝试对 pygame 生成的绘图进行动画处理时,它们仍然是静态的。 编辑:“动画”是指“移动”。就像使圆在 x 和
好吧,我已经尝试 Java 几个星期了,遵循类和在线教程。我做了一个简单的游戏,其中方 block 落向屏幕底部,而玩家控制一个小球,仅在 x 轴上移动并尝试避开它们。 我遇到的问题是方 block
我的 python 代码遇到一些问题,我正在制作蛇的一个版本,我的问题涉及蛇本身的运动。我已经得到了工作正常的方向,我只需要做到这一点,以便蛇继续沿着通过按键告诉它的方向移动,我还需要使它成为一个 b
那是我的代码。 -(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { [[NSNotificationC
我正在构建这个用于慢跑的 Android 应用程序,它应该测量用户从某个时间点开始的距离。 我对使用 GPS 选项(经度、纬度)不感兴趣,所以如果没有 GPS 选项并且只使用 android 传感器,
什么是自律?网上有这样一个回答:“最健康的自律是早睡,最实用的自律是运动,最丰盈内心的自律是读书。”早睡养神,运动养身,读书养脑。坚持把这三件事做好,你就已经超越了很多人。 1 每天早点睡 你有没有过
考虑下面这行 Lisp 代码: (some-function 7 8 | 9) ;; some comment. note the extra indentation 该点位于“8”和
在 Vim 中,如何移动到 xml 文件中的父/表亲标签?我正在寻找类似的东西: vatat " create a selection for second parent tag with all c
用 Dart 做这样的 Canvas 运动的最佳方法是什么? http://jsfiddle.net/loktar/dMYvG/ 我正在尝试使 Canvas 运动平稳,并想看看Dart可以做什么。 还
我试图让一个物体在固定的时间段内沿着圆形路径移动。 这个应用程序是一个“平滑运动”时钟。 因此,我不想每次 .getSeconds() 更新时将位置移动到固定坐标,而是想使用 ( .getSecond
我正在尝试创建一个简单的动画,其中一系列气泡围绕中心点旋转。我有一个动画版本,其中气泡在开始旋转之前从中心点扩散,效果很好,但是一旦我单击其中一个图像(引发动画),屏幕就会卡住一会儿,然后气泡出现在他
不久前我开始学习java作为一种爱好,因为我想制作一个小游戏。我学习了 Java 基础知识,并决定尝试解决游戏开发问题。我的 JFrame 和一切都很好,从技术上讲我没有错误,但我的小矩形家伙不会在屏
我在制作台球游戏时遇到问题,当我模拟击球时,我需要球使用react,程序是这样工作的,您单击击球的方向和力量,然后单击开始, go按钮位于创建标签的GUI类中,该按钮调用我的主类中的一个方法来接收参数
我以前在 2d 项目中使用过类似的东西来移动并且它总是有效。我现在正在使用它,它为我提供了一些输出的正确角度和错误的角度。我认为我的触发器中有一些错误,我弄错了。不过,我已经检查了大约一百万次。 Pr
我的 OpenGL 应用程序有问题,您可以在 this gif 中清楚地看到.基本上我想朝光标指向的方向移动,但这并没有发生,而是“前进”方向保持不变。 例如,如果我转身 180° 并按“w”向前走,
因此,我再次开始使用 C++ 编程并尝试使用 OpenGL。目前我有一个基本的应用程序,我只想用键移动相机。我读了很多关于这个的文章,但我仍然对运动有问题,我猜是因为即使只有一点点,但它们与我的程序不
我在 Android OpenGL 中有一个 Sprite 。这个 Sprite (一只小甲虫)总是向前移动,我使用: sprite.setPosition(posX, posY); 现在我有一个旋转
我是一名优秀的程序员,十分优秀!