- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章基于p5.js 2D图像接口的扩展(交互实现)由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文为大家分享了基于p5.js 2D图像接口的扩展,供大家参考,具体内容如下 。
1、心跳笔刷 。
组织结构:
1.纵坐标取一定范围内的随机值,横坐标按规律递增.
基本用法:
1、按住鼠标左键画出一条心跳线,松开鼠标左键,随机心跳线确定 2、按空格键清除画面 。
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
|
let isButtonRight =
false
;
let make =
null
;
let root =
null
;
let makeSize =
null
;
var
mx=[],my=[];
//记录鼠标位置
let Conce =
true
;
function
setup() {
root = createDiv();
createCanvas(600, 400).parent(root).id(
'js-canvas'
)
background(0);
makeSize = createVector(40, 40);
}
function
draw() {
if
(mouseIsPressed){
// 鼠标按下画
if
(mouseButton === LEFT){
// stroke(random(255), random(255), random(255)); // 线条颜色
//画心电图
if
(Conce){
mx[0] = mouseX;
my[0] = mouseY;
Conce =
false
;
}
else
{mx[1] = mouseX;
my[1] = mouseY;
background(0);
stroke(255);
strokeWeight(1);
// 线条粗细
line_Heart_0414(mx[0], my[0], mx[1]/2, my[1],30,(mx[1]-mx[0])/5);
//Conce = true;
}
isButtonRight =
false
;
}
}
if
(keyIsPressed){
// 按下空格键清空画布
if
(keyCode == 32)
background(0);
}
}
function
mouseReleased(){
Conce =
true
;
}
function
line_Heart_0414(x0,y0,x1,y1,Distance,res)
{
var
theta = 0;
var
xp = x0;
//初始点
var
yp = y0;
for
(
var
i=1;i<res;i++)
{
var
t = i/res;
var
yt = lerp(y0,y1,t);
//t决定yt是靠近y0还是y1
var
biasY
if
(i%2==0)
biasY = random(-Distance,0);
else
biasY = random(0,Distance);
var
x = x0+5;
var
y
y = yt+biasY;
line(xp,yp,x,y);
x0 =x;
xp = x;
yp = y;
}
}
|
效果图:
2、生成气泡笔刷 。
组织结构:
定义了气泡结构函数,含有属性(圆的横纵坐标,透明值,圆的半径,向上平移的单位) 不同气泡的大小、位置、透明值等取随机值,生成一定数量的气泡压进气泡数组里。 绘制数组里的气泡,并靠不停刷新气泡的x值和y值来形成运动的效果 用相同颜色的直线掩盖运动轨迹 。
基本用法:
鼠标左键绘制气泡 。
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
|
let isButtonRight =
false
;
let make =
null
;
let root =
null
;
let makeSize =
null
;
var
bubbles = [];
var
c1, c2;
function
setup() {
root = createDiv();
createCanvas(600, 400).parent(root).id(
'js-canvas'
)
makeSize = createVector(40, 40);
}
function
draw() {
if
(mouseIsPressed){
// 鼠标按下画
if
(mouseButton === LEFT){
CreateBubbles0414(2);
isButtonRight =
false
;
}
}
//画气泡
//创建一定数量的气泡
c1 = color(60, 195, 255, 1);
c2 = color(0, 100, 200, 10);
colorMode(RGB, 255, 255, 255, 1);
//从y=0到y=h开始画线,构成背景面
for
(
var
i = 0; i <= 400; i++) {
line(0, i, 600, i);
}
BubblesRise_0414();
}
//设置气泡结构函数
function
Bubble_0414(xloc, yloc, zloc, rise, rad) {
this
.xloc = xloc;
//横坐标
this
.yloc = yloc;
//纵坐标
this
.zloc = zloc;
//透明值
this
.rad = rad;
//半径
this
.rise = rise;
//向上平移的单位
}
function
CreateBubbles0414(count) {
for
(i = 0; i < count; i++) {
var
x = mouseX;
var
y = mouseY;
var
z = random(0.3, 0.7);
//map从一个范围内映射一个数字去另一个范围
var
r = map(z, 0.3, 0.7, 7, 25);
var
rise = map(z, 0.3, 0.7, 0.7, 1.7);
var
b =
new
Bubble_0414(x, y, z, rise, r);
bubbles.push(b);
}
}
function
BubblesRise_0414() {
//绘制气泡
var
c = lerpColor(c1, c2,0.5);
//插值混合两个颜色,最后的amt参数是倾向值
stroke(c);
for
(i = 0; i < bubbles.length; i++) {
var
x = bubbles[i].xloc;
var
y = bubbles[i].yloc;
var
z = bubbles[i].zloc;
var
r = bubbles[i].rad;
fill(255, 255, 255, z);
ellipse(x, y, r, r);
}
//设置气泡运动轨迹
for
(i = 0; i < bubbles.length; i++) {
var
x = bubbles[i].rise;
bubbles[i].yloc -= x;
//想要各自的摆动频率不一样,借助他们互不相同的透明值
//结合map,限定了气泡的摇摆范围
var
zmin = bubbles[i].zloc* -2.0;
var
zmax = bubbles[i].zloc * 2.0;
//产生cos函数路径
var
slowy = bubbles[i].yloc* 0.08;
//映射x坐标的移动位置是符合cos函数的
bubbles[i].xloc += map(cos(slowy), -1, 1, zmin, zmax)
}
}
|
效果:
3、DNA观摩 。
组织结构:
需要呈现运动的效果,除了不同x坐标的y值取sin的值外,还需要相同x坐标自己的y值符合sin模型的变化。为了让效果更明显,在顶点处又添加了圆.
基本用法:
鼠标上下左右移动观察双螺旋结构的基因图 。
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
|
var
start = 0,
inc = 0.01;
//直线间呈现的跨度
var
canvasWidth = 300,
canvasHeight = canvasWidth;
var
lineInterval = 15;
//线条之间的距离
function
setup() {
root = createDiv();
createCanvas(canvasWidth, canvasHeight).parent(root).id(
'js-canvas'
)
}
function
draw() {
background(0);
DNA_0414();
}
function
DNA_0414()
{
//第一条线的y的长度值
var
xoff = mouseX/100;
for
(
var
x = 2; x < canvasWidth; x++) {
//使每条直线的长度都满足sin(),xoff自己变化起始点逐渐增大
var
y1 = sin(xoff) * canvasHeight / 5 + mouseY;
var
y2 = -sin(xoff) * canvasHeight / 5 + mouseY;
if
(x % lineInterval == 0) {
//绘制直线
stroke(45,120,255);
line(x, y1, x, mouseY);
line(x, y2, x, mouseY);
//在直线顶点画圆
noStroke();
ellipse(x, y1, 5, 5);
ellipse(x, y2,5,5);
}
xoff += inc;
}
// start += inc; //每一条线的长度初始值也
}
|
效果 。
4、桌面男孩 。
基本用法:鼠标在画板上移动,引起男孩的表情变化 。
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
|
function
setup() {
createCanvas(500, 500);
rectMode(CENTER);
}
function
draw() {
noStroke();
background(16,30,70);
drawFace_0414();
}
function
drawFace_0414()
{
fill(255,221,202);
//头
circle(250,140,160);
circle(175,150,30)
//耳朵
circle(325,150,30)
moveeyes_0414();
//移动的眼睛
stroke(0);
noFill();
//眉毛
strokeWeight(1);
arc(215,130,30,10,PI,0);
//绘制弧形
arc(285,130,30,10,PI,0);
stroke(
'purple'
);
// 鼻子
strokeWeight(5);
//
point(250,175);
moveMouth_0414();
//嘴巴
fill(0);
//留海
arc(250, 120, 170, 140, PI, 2*PI, HALF_PI);
}
///绘制交互动态嘴巴
function
moveMouth_0414(){
var
deltax=abs(mouseX-250)/250*20;
fill(209,51,26);
noStroke();
square(250,200, deltax, 10);
}
///绘制交互动态眼睛,朝向鼠标位置
function
moveeyes_0414(){
var
deltax=(mouseX-250)/250*7.5;
var
deltay=(mouseY-150)/350*7.5;
fill(255);
circle(215,150,35);
circle(285,150,35);
fill(0);
circle(215+deltax,150+deltay,20);
circle(285+deltax,150+deltay,20);
}
|
效果:
5、总结 。
留下不足的地方: 1、没有用UI界面把几个合成在一起 2、心跳图笔刷不能留存上次的痕迹,但这样也是一种用法 3、气泡图不能刷新清空 。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/weixin_45774924/article/details/110337319 。
最后此篇关于基于p5.js 2D图像接口的扩展(交互实现)的文章就讲到这里了,如果你想了解更多关于基于p5.js 2D图像接口的扩展(交互实现)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在学习构建单页应用程序 (SPA) 所需的所有技术。总而言之,我想将我的应用程序实现为单独的层,其中前端仅使用 API Web 服务(json 通过 socket.io)与后端通信。前端基本上是
当我看到存储在我的数据库中的日期时。 这是 正常 。日期和时间就是这样。 但是当我运行 get 请求来获取数据时。 此格式与存储在数据库 中的格式不同。为什么会发生这种情况? 最佳答案 我认为您可以将
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试使用backbone.js 实现一些代码 和 hogan.js (http://twitter.github.com/hogan.js/) Hogan.js was developed ag
我正在使用 Backbone.js、Node.js 和 Express.js 制作一个 Web 应用程序,并且想要添加用户功能(登录、注销、配置文件、显示内容与该用户相关)。我打算使用 Passpor
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我尝试在 NodeJS 中加载数据,然后将其传递给 ExpressJS 以在浏览器中呈现 d3 图表。 我知道我可以通过这种方式加载数据 - https://github.com/mbostock/q
在 node.js 中,我似乎遇到了相同的 3 个文件名来描述应用程序的主要入口点: 使用 express-generator 包时,会创建一个 app.js 文件作为生成应用的主要入口点。 通过 n
最近,我有机会观看了 john papa 关于构建单页应用程序的精彩类(class)。我会喜欢的。它涉及服务器端和客户端应用程序的方方面面。 我更喜欢客户端。在他的实现过程中,papa先生在客户端有类
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是一个图形新手,需要帮助了解各种 javascript 2D 库的功能。 . . 我从 Pixi.js 中得到了什么,而我没有从 Konva 等基于 Canvas 的库中得到什么? 我从 Konva
我正在尝试将一些 LESS 代码(通过 ember-cli-less)构建到 CSS 文件中。 1) https://almsaeedstudio.com/ AdminLTE LESS 文件2) Bo
尝试查看 Express Passport 中所有登录用户的所有 session ,并希望能够查看当前登录的用户。最好和最快的方法是什么? 我在想也许我可以在登录时执行此操作并将用户模型数据库“在线”
我有一个 React 应用程序,但我需要在组件加载完成后运行一些客户端 js。一旦渲染函数完成并加载,运行与 DOM 交互的 js 的最佳方式是什么,例如 $('div').mixItUp() 。对
请告诉我如何使用bodyparser.raw()将文件上传到express.js服务器 客户端 // ... onFilePicked(file) { const url = 'upload/a
我正在尝试从 Grunt 迁移到 Gulp。这个项目在 Grunt 下运行得很好,所以我一定是在 Gulp 中做错了什么。 除脚本外,所有其他任务均有效。我现在厌倦了添加和注释部分。 我不断收到与意外
我正在尝试更改我的网站名称。找不到可以设置标题或应用程序名称的位置。 最佳答案 您可以在 config/ 目录中创建任何文件,例如 config/app.js 包含如下内容: module.expor
经过多年的服务器端 PHP/MySQL 开发,我正在尝试探索用于构建现代 Web 应用程序的新技术。 我正在尝试对所有 JavaScript 内容进行排序,如果我理解得很好,一个有效的解决方案可以是服
我是 Nodejs 的新手。我在 route 目录中有一个 app.js 和一个 index.js。我有一个 app.use(multer....)。我还定义了 app.post('filter-re
我正在使用 angular-seed用于构建我的应用程序的模板。最初,我将所有 JavaScript 代码放入一个文件 main.js。该文件包含我的模块声明、 Controller 、指令、过滤器和
我是一名优秀的程序员,十分优秀!