- 浏览: 1446873 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
BezierCurve
webgl的贝塞尔曲线
webgl例子
https://www.khronos.org/webgl/wiki/Demo_Repository
参考
http://jsdo.it/Biske/A07Y
http://jsdo.it/kimmy/Z9z6
html
enjoy it
http://haoning.net/webs/webgl/BezierCurve/
最简单的实现方式
webgl的贝塞尔曲线
webgl例子
https://www.khronos.org/webgl/wiki/Demo_Repository
参考
http://jsdo.it/Biske/A07Y
http://jsdo.it/kimmy/Z9z6
(function(d, w){ var FPS = 30;//FPS ,Frames Per Second var F = 300;//焦点距离 var N = 1;//轨迹的个数 var VERTEX_MAX = 5;//轨迹长度 var TRAIL_QUALITY = 4000;//轨迹的品质,越小越直 var mu = 0.5;//前的主持人点的依赖程度 var bmRandom = function(mu, sigma){ var x, y, r, tmp=null, tmp2; return function(){ if(tmp !== null){ tmp2 = tmp; tmp = null; return y*tmp2+mu; } do{ x = Math.random()*2-1; y = Math.random()*2-1; r = x*x+y*y; }while(r>=1); tmp = sigma*Math.sqrt(-2*Math.log(r)/r); return x*tmp+mu; }; }; pointCopy = function(src, dst){ dst.x = src.x; dst.y = src.y; dst.z = src.z; return dst; }; Trail = function(pos, t, color_f){ this.pos={x:0,y:0,z:0}; this.start={x:0,y:0,z:0}; this.goal={x:0,y:0,z:0}; this.anchor_1={x:0,y:0,z:0}; this.anchor_2={x:0,y:0,z:0}; this.start_time = 0; this.take_time = 1; this.vertexes = []; this.anchors_1 = []; this.anchors_2 = []; this.color_f = color_f; pointCopy(pos, this.pos); pointCopy(pos, this.start); pointCopy(pos, this.goal); this.setNextGoal(t); }; Trail.prototype.setNextGoal = function(t, target){ pointCopy(this.goal, this.start); this.anchor_1.x = this.start.x+(this.start.x-this.anchor_2.x)*mu; this.anchor_1.y = this.start.y+(this.start.y-this.anchor_2.y)*mu; this.anchor_1.z = this.start.z+(this.start.z-this.anchor_2.z)*mu; if(target){ this.anchor_2.x = (this.anchor_1.x+target.x)/2+myrand(); this.anchor_2.y = (this.anchor_1.y+target.y)/2+myrand(); this.anchor_2.z = (this.anchor_1.z+target.z)/2+myrand(); this.goal.x = target.x; this.goal.y = target.y; this.goal.z = target.z; }else{ this.anchor_2.x = this.anchor_1.x+myrand(); this.anchor_2.y = this.anchor_1.y+myrand(); this.anchor_2.z = this.anchor_1.z+myrand(); this.goal.x = this.anchor_2.x+myrand(); this.goal.y = this.anchor_2.y+myrand(); this.goal.z = this.anchor_2.z+myrand(); } this.start_time = t; this.take_time = 200+Math.random()*200; this.vertexes.push(pointCopy(this.start, {x:0,y:0,z:0})); this.anchors_1.push(pointCopy(this.anchor_1, {x:0,y:0,z:0})); this.anchors_2.push(pointCopy(this.anchor_2, {x:0,y:0,z:0})); if(this.vertexes.length > VERTEX_MAX){ this.vertexes.splice(0,this.vertexes.length-VERTEX_MAX); this.anchors_1.splice(0,this.anchors_1.length-VERTEX_MAX); this.anchors_2.splice(0,this.anchors_2.length-VERTEX_MAX); } }; Trail.prototype.update = function(t, target){ bezier3( t-this.start_time, this.start, this.anchor_1, this.anchor_2, this.goal, this.take_time, this.pos ); if(t-this.start_time > this.take_time){ this.setNextGoal(this.start_time+this.take_time, target); this.update(t, target); } }; Trail.prototype.draw = function(ctx, camera, t){ var i, dz, dt, ddt, rt, a, v={x:0, y:0, z:0}; var ps = {x:0, y:0}; ctx.beginPath(); if(perspective(this.vertexes[0], camera, ps)){ ctx.moveTo(ps.x, ps.y); } var x0 = ps.x; rt = (t-this.start_time)/this.take_time; for(i=1; i<this.vertexes.length; i++){ ddt = 0.01; for(dt=0; dt<1; dt+=ddt){ bezier3(dt, this.vertexes[i-1], this.anchors_1[i-1], this.anchors_2[i-1], this.vertexes[i], 1, v); if(perspective(v, camera, ps)){ dz = v.z-camera.z; a = 1-(this.vertexes.length-i+1-dt+rt)/VERTEX_MAX; this.color_f(ctx, a, dz); ctx.lineTo(ps.x, ps.y); ctx.stroke(); ctx.beginPath(); ctx.moveTo(ps.x, ps.y); ddt = dz/TRAIL_QUALITY+0.01; } } } ddt = 0.01; for(dt=0; dt<rt; dt+=ddt){ bezier3(dt, this.start, this.anchor_1, this.anchor_2, this.goal, 1, v); if(perspective(v, camera, ps)){ dz = v.z-camera.z; a = 1-(1-dt+rt)/VERTEX_MAX; this.color_f(ctx, a, dz); ctx.lineTo(ps.x, ps.y); ctx.stroke(); ctx.beginPath(); ctx.moveTo(ps.x, ps.y); ddt = dz/TRAIL_QUALITY+0.01; } } if(perspective(this.pos, camera, ps)){ dz = this.pos.z-camera.z; a = 1-1/VERTEX_MAX; this.color_f(ctx, a, dz); ctx.lineTo(ps.x, ps.y); ctx.stroke(); } }; bezier3 = function(t, a, b, c, d, e, dst){ t /= e; dst.x = a.x*(1-t)*(1-t)*(1-t)+ b.x*3*t*(1-t)*(1-t)+ c.x*3*t*t*(1-t)+ d.x*t*t*t; dst.y = a.y*(1-t)*(1-t)*(1-t)+ b.y*3*t*(1-t)*(1-t)+ c.y*3*t*t*(1-t)+ d.y*t*t*t; dst.z = a.z*(1-t)*(1-t)*(1-t)+ b.z*3*t*(1-t)*(1-t)+ c.z*3*t*t*(1-t)+ d.z*t*t*t; }; perspective = function(point, camera, dst){ var dx = point.x-camera.x; var dy = point.y-camera.y; var dz = point.z-camera.z; if(dz > 0){ dst.x = F*dx/dz; dst.y = F*dy/dz; return true; } return false; }; updateScene = function(ctx){ var i, goal; time_now = new Date().getTime(); var time_d = time_now-time_pre; trails[0].update(time_now); for(i=1; i<trails.length; i++){ trails[i].update(time_now, trails[i-1].pos); } camera.x += (trails[0].pos.x-camera.x)*0.0005*time_d; camera.y += (trails[0].pos.y-camera.y)*0.0005*time_d; camera.z += (trails[0].pos.z-camera.z-100)*0.0005*time_d; time_pre = time_now; }; drawScene = function(ctx){ var i; ctx.clearRect(-canvas.width/2, -canvas.height/2, canvas.width, canvas.height); for(i=0; i<trails.length; i++){ trails[i].draw(ctx, camera, time_now); } }; var myrand = bmRandom(0,20); var canvas = d.getElementById("world"); var ctx = canvas.getContext("2d"); var trails = []; var i; var time_now = new Date().getTime(); var time_pre = time_now; var camera = {x:0, y:0, z:-200}; for(i=0; i<N; i++){ trails.push(new Trail({x:myrand(), y:myrand(), z:myrand()}, time_now, function(a,z){return "#FFFFFF";})); } for(i=0; i<N; i++){ switch(i%3){ case 0: trails[i].color_f=function(ctx, a, dz){ var b = dz<10?0:a*F/dz; b = (b>1?1:b)*(dz<30?(dz-10)/20:1); ctx.strokeStyle = "rgba(255,"+Math.floor(255*a)+",0,"+b+")"; ctx.lineWidth = F/dz; ctx.lineCap = b>0.8?"round":"butt"; }; break; case 1: trails[i].color_f=function(ctx, a, dz){ var b = dz<10?0:a*F/dz; b = (b>1?1:b)*(dz<30?(dz-10)/20:1); ctx.strokeStyle = "rgba(0, 255,"+Math.floor(255*a)+","+b+")"; ctx.lineWidth = F/dz; ctx.lineCap = b>0.8?"round":"butt"; }; break; default: trails[i].color_f=function(ctx, a, dz){ var b = dz<10?0:a*F/dz; b = (b>1?1:b)*(dz<30?(dz-10)/20:1); ctx.strokeStyle = "rgba("+Math.floor(255*a)+",0,255,"+b+")"; ctx.lineWidth = F/dz; ctx.lineCap = b>0.8?"round":"butt"; }; break; } } canvas.width = w.innerWidth; canvas.height = w.innerHeight; ctx.translate(canvas.width/2, canvas.height/2); setInterval(function(){ updateScene(); drawScene(ctx); }, 1000/FPS); })(document, window);
html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>forked: 3D Bezier Curve - js do it</title> <meta name="Description" content="" /> <meta name="Keywords" content="" /> <link rel="stylesheet" type="text/css" media="screen,print" href="style.css" /> </head> <body> <canvas id='world'></canvas> <script type="text/javascript" src="index.js"></script> </body> </html>
body{ padding: 0; margin: 0; } #world{ display: block; background-color: #000000; }
enjoy it
http://haoning.net/webs/webgl/BezierCurve/
最简单的实现方式
<script type="text/javascript"> window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.moveTo(188, 130); var controlX1 = 140; var controlY1 = 10; var controlX2 = 388; var controlY2 = 10; var endX = 388; var endY = 170; context.bezierCurveTo(controlX1, controlY1, controlX2, controlY2, endX, endY); context.lineWidth = 1; context.strokeStyle = "black"; // line color context.stroke(); }; </script> <canvas id='myCanvas'></canvas>
发表评论
-
indexedDB存图片减少请求
2020-05-21 19:23 516getImageFile()获取网络图片 showImage ... -
vizceral-example的例子
2020-03-19 18:53 320自定义图和加载结构 代码在 https://github.c ... -
jsonpath的helloworld
2020-03-17 14:58 376基本语法:https://www.cnblogs.com/jp ... -
流动图神器vizceral
2019-10-12 19:04 441把c的代码生成json:https://github.com/ ... -
emscripten asm.js的helloworld
2018-03-01 20:15 1070mac下安装: brew install SDL2 SDL2_ ... -
websocket上传文件
2016-12-15 13:30 4377nginx的上传 查看http://haoningabc.it ... -
webpack的helloworld
2016-11-02 10:42 881参考 http://www.jianshu.com/p/42e ... -
iphone6等移动端的css自适应
2016-10-17 01:18 1171参考 http://jingyan.baidu.com/art ... -
javascript自定义事件
2016-06-01 21:49 524一言不合上代码 <input value=" ... -
html5的fiesystem api 浏览器本地存储
2016-06-01 15:59 888html5的fiesystem api可以存取本地文件 一言不 ... -
websocket传传图片
2015-12-25 17:51 7211参考[url]http://www.adobe.com/dev ... -
angularjs使用include后双向绑定失败的解决
2015-12-20 19:41 1838原理参考 http://segmentfault.com/q/ ... -
html5 陀螺仪
2014-11-26 21:05 5823<html> <head> ... -
chrome app的helloworld
2014-11-11 13:56 673参考 http://blog.csdn.net/rydiy/a ... -
shader and Program编程基本概念 - 转
2014-11-04 11:50 1468原地址:http://blog.csdn.net/myarro ... -
javascript对象转json
2014-10-17 14:09 963<html> <head>& ... -
jquery 的svg中国地图
2012-12-16 14:37 28034三种吧 1.d3.js很强大 2.jquery的 jvecto ... -
纯css的树型结构
2012-10-03 18:29 1233<html><head> ... -
D3 的3d图
2012-09-16 17:05 1425LCF http://mathworld.wolfram. ... -
jquery table拖拽排序
2012-07-14 21:45 7093参考http://dragsort.codeplex.com/ ...
相关推荐
《WebGL编程指南》的主要篇幅讲解了WebGL 原生API 和三维图形学的基础知识,包括渲染管线、着色器、矩阵变换、着色器编程语言(GLSL ES)等等,也讲解了使用WebGL 渲染三维场景的一般技巧,如光照、阴影、雾化等等。...
Unity通用WebGL模板Universal WebGL Template 1.2.1 仅供学习,请勿商用。
webgl载入模型webgl载入模型webgl载入模型 webgl载入模型webgl载入模型webgl载入模型
本书?前可以?把?教你使用WebGL进行编程,?且在不断更 新。
untiy webgl 打开 PDF文件
Better-Minimal-WebGL-Template unity webgl打包模板 支持手机
支持Webgl自动播放视频,支持unity2019以上版本,强烈推荐
包含webgl编程指南pdf版本,还有教材中实例的源码(windows和mac版本),还有cuon-matrix.js,cuon-utils.js,webgl-debug.js,webgl-utils.js供大家下载使用!
WebGL编程指南示例源码( WebGL Programming Guide)
代码说明如何实现webgl帧缓存。里面包含了HTML,JS, GLSL的代码。
Each chapter develops a number of working, fully functional WebGL applications and explains key WebGL features through these examples. After finishing the book, you will be ready to write WebGL ...
效果超棒的Webgl模型-
5.6参数曲线 5.7优化策略 5.8插值方案 5.9本章小结 第6章颜色、深度测试以及Alpha混合 6.1在WebGL中使用颜色 6.2使用对象中的颜色 6.3使用光照颜色 6.4体系结构的更新操作 6.5通过iQueryUI实现互动性 6.6有向点光源...
webgl函数库(cuon-matrix、cuon-utils、webgl-debug、webgl-utils) webgl公共函数
解决webgl视频播放问题,视频格式 ogv
Create WebGL sample pages as you learn, and build a racing game application in the final chapter Get to know the Three.js open source library in detail Develop working knowledge of graphics rendering,...
UnityWebGL唤醒手机输入框,安卓和苹果已测试。https://blog.csdn.net/abcd5711664321/article/details/125384825?spm=1001.2014.3001.5502
网页动画素材 WebGL基于canvas画布绘制3D噪音线条酷炫动画特效。(抖音资料)网页动画素材 WebGL基于canvas画布绘制3D噪音线条酷炫动画特效。(抖音资料)网页动画素材 WebGL基于canvas画布绘制3D噪音线条酷炫动画...
UnityWebGL文件选择.unitypackage