android贝塞尔曲线多点,Canvas 贝塞尔曲线的多点波动

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

function Ball(x, y, radius) {

this.x = x;

this.y = y;

this.radius = radius;

this.vx = 20;

this.vy = 10;

}

Ball.prototype.draw = function(ctx) {

ctx.save();

ctx.translate(this.x, this.y);

ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';

ctx.beginPath();

ctx.arc(0, 0, this.radius, 0, Math.PI * 2, true);

ctx.fill();

ctx.restore();

}

function Curve(points) {

this.points = points;

this.ballRadius = 5;

this.speed = 0.12;

this.vy = 2 + Math.random() * 2;

}

Curve.prototype.draw = function() {

var length = this.points.length - 2,

ctrlPoint = {},

i;

ctx.save();

ctx.beginPath();

ctx.moveTo(this.points[0].x, this.points[0].y);

for (i = 1; i < length; i++) {

ctrlPoint.x = (this.points[i].x + this.points[i + 1].x) / 2;

ctrlPoint.y = (this.points[i].y + this.points[i + 1].y) / 2;

ctx.quadraticCurveTo(this.points[i].x, this.points[i].y, ctrlPoint.x, ctrlPoint.y);

}

ctx.quadraticCurveTo(this.points[i].x, this.points[i].y, this.points[i + 1].x, this.points[i + 1].y);

ctx.lineWidth = 2;

ctx.lineCap = 'round';

ctx.strokeStyle = '#fff';

ctx.stroke();

ctx.restore();

}

var canvas = document.querySelector('canvas'),

ctx = canvas.getContext('2d'),

W = canvas.width = window.innerWidth,

H = canvas.height = window.innerHeight,

limit = W / 2.2,

horizontalBall = new Ball(100, H / 2, 100),

curves = [];

for (var y = H / 2 - 150; y <= H / 2 + 150; y += 50) {

makeCurve(y)

}

function makeCurve(y) {

var curve, points = [];

for (var x = W / 2 - limit; x <= W / 2 + limit; x += 100) {

points.push({

x: x,

y: y,

oldY: y,

targetY: y - 300 + Math.random() * 600,

speed: 0.1,

vy: 5 + Math.random() * 5,

gravity: 0.85,

vyy: 3 + Math.random() * 4

});

}

curve = new Curve(points);

curves.push(curve)

}

function moveBalls(ball) {

if (ball == horizontalBall) {

if (ball.x + ball.radius > W) {

ball.x = W - ball.radius - 50;

ball.vx *= -1;

} else if (ball.x - ball.radius < 0) {

ball.x = 50 + ball.radius;

ball.vx *= -1;

}

ball.x += ball.vx;

}

}

(function drawFrame() {

requestAnimationFrame(drawFrame, canvas);

ctx.fillStyle = '#17293a';

ctx.fillRect(0, 0, W, H);

curves.forEach(function(curve) {

curve.points.forEach(function(point) {

var dx, dy, dist,

dx2, dy2, dist2,

n = curve.points.indexOf(point);

dx = (horizontalBall.x - point.x);

dy = (horizontalBall.y - point.y);

dist = Math.sqrt(dx * dx + dy * dy);

if (dist < 200) {

if (n % 2 === 0) {

point.y -= point.vyy;

} else if (n % 2 !== 0) {

point.y += point.vyy;

}

} else {

point.vy += (point.oldY - point.y) * point.speed;

point.vy *= point.gravity;

point.y += point.vy;

}

});

curve.draw(ctx);

});

moveBalls(horizontalBall);

}());

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/531575.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html5做一个展示页面,基于HTML5的WebGL实现json和echarts图表展现在同一个界面

突然有个想法&#xff0c;如果能把一些用到不同的知识点放到同一个界面上&#xff0c;并且放到一个盒子里&#xff0c;这样我如果要看什么东西就可以很直接显示出来&#xff0c;而且这个盒子一定要能打开。我用HT实现了我的想法&#xff0c;代码一百多行&#xff0c;这么少的代…

android 空白占位符,android textview空格占位符以及一些其他占位符汇总

普通的英文半角空格 no-break space (普通的英文半角空格但不换行) 中文全角空格 (一个中文宽度)   en空格 (半个中文宽度)   em空格 (一个中文宽度) 四分之一em空格 (四分之一中文宽度)相比平时的空格( )&#xff0c;nbsp拥有不间断(non-breaking)特性。即连续的nbs…

html图片平移,CSS3 按钮悬停时背景图片平移入场

JavaScript语言&#xff1a;JaveScriptBabelCoffeeScript确定$(".thumb-next").on(mouseleave, function() {$(".layout-p").text("Hover above, please.");});$(".thumb-next").on(mouseenter, function() {$(".layout-p")…

Netbeans 中创建数据连接池和数据源步骤(及解决无法ping通问题)

1.启动glassfish服务器&#xff0c; 在浏览器的地址栏中输入 http://localhost:4848 2.首先建立JDBC Connection Pools&#xff1b; 3.new 一个Connectio Pools 4.对General Settings属性填写&#xff1b; 5.填写Datasource Classname&#xff1a;com.mysql.jdbc.jdbc2.optiona…

商品详情页html,天天生鲜商品详情页HTML+css

body{font-family: Microsoft YaHei;color:#666;font-size:12px;}/*顶部条状态*/.header_con{height:29px;background-color: #f7f7f7;border-bottom:1px solid #ddd;}.header{width:1200px;height:29px;margin:0 auto;1}.welcome{font:12px/29px Microsoft YaHei UI;float: le…

Netbeans不能正常启动glassfish或者部署失败不能运行的问题

错误信息&#xff1a;D:\临时文件\netbeans\WebTest\build\web中部署GlassFish Server 4, deploy, Connection refused: connect, falseD:\临时文件\netbeans\WebTest\nbproject\build-impl.xml:1048: 尚未部署该模块。有关详细信息, 请查看服务器日志。构建失败 (总时间: 7 秒…

js实现图片加载特效(从左到右,百叶窗,从中间到两边)

/*  网上百度的&#xff0c;感觉”从中间到两边“的效果写的不是很好&#xff0c;改了一下&#xff0c;感觉可以了&#xff01;*/<html><head><title></title><meta http-equiv"Content-Type" content"text/html; charsetUTF-8&qu…

给html动态添加css样式,JavaScript动态添加css样式和script标签

[动态添加css样式]window.οnlοadfunction(){var headdocument.getElementsByTagName(head)[0];     //获取到head元素var linkdocument.createElement(link);             //创建link元素节点&#xff0c;也就是link标签link.rel"stylesheet";  …

java中Cookie中文字符乱码问题

如果Cookie中的Value 中有中文字符出现&#xff0c;在加入Cookie的时候&#xff0c;会出现下面的错误&#xff1a;  java.lang.IllegalArgumentException: Control character in cookie value or attribute.当我们设定Cookie的Value的值得时候&#xff1a;  cookie.setValue…

湖北省仙桃市2021年高考成绩查询,2021年4月湖北仙桃市自考成绩查询时间和有效期是多久?...

2021年4月湖北仙桃市自考成绩查询时间和有效期是多久?根据《2021年4月湖北自考成绩公布及复查事项通知》知悉&#xff0c;2021年4月湖北仙桃市自考成绩查询时间为5月12日起&#xff0c;官方成绩查询入口已开通。一、2021年4月湖北仙桃市自考成绩查询入口及流程2021年4月湖北仙…

html5 手机拍视频滤镜,用canvas实现图片滤镜效果附演示_html5教程技巧

这是一个很有意思的特效&#xff0c;模拟摄像机拍摄电视屏幕画面时出现点状颗粒的效果。颗粒的大小通过变换矩阵实现&#xff0c;可以任意调节&#xff0c;有兴趣研究的朋友可以尝试更多的效果&#xff0c;代码没有经过优化&#xff0c;只是一个粗糙的Demo&#xff0c;大家可以…

java中得到classpath和当前类的绝对路径的一些方法(路径中的%20进行替换空格)...

原网址&#xff1a;http://blog.csdn.net/shendl/article/details/1427475&#xff08;注意&#xff1a;利用下面方式得到路径&#xff0c;如果路径中有空格字符&#xff0c; 那么会有"%20"进行替换&#xff0c; 所以得到之后再将"%20"替换成空格&#xff…

计算机的好处英语,电脑的好处英语演讲稿

电脑的好处英语演讲稿The computer plays the vital role in ours life, the computer may help us to handle very many matters: The data computation, the study entertainment, the office automation, the control production, draws money automatically, long-distance…

jsp实现简单的分页

效果如下&#xff1a;<%-- Document : pageCreated on : 2014-11-18, 8:55:02Author : HJZ --%><%page contentType"text/html" pageEncoding"UTF-8"%> <!DOCTYPE html> <html><head><script language "javas…

台式计算机有什么配置,目前台式电脑的主流配置有哪些?

主流配置的话&#xff0c;目前CPU基本都上八代8100/8400/8700主板b360m板子比较火&#xff0c;不超频很合适内存条的话360只支持2666所以一般都是上8g2400的条子硬盘的话现在固态降价了&#xff0c;且主板支持nvme 256g性价比不错 看需求&#xff0b;机械显卡的话1060系列甜品级…

javaBean和jsp应用

原网页&#xff1a;http://www.douban.com/note/102320977/ JavaBean是一种可复用&#xff0c;跨平台的组件。共有两种JavaBean&#xff1a;一种无用户界面&#xff0c;这种一般用于处理数据运算&#xff0c;操作数据库等。另一种是有用户界面(User Interface)的JavaBean. 在Js…

计算机重应用,装了一大堆应用,iPhone6会变重吗?

你有没有想过&#xff0c;iPhone买来以后装入数十甚至上百个应用&#xff0c;手机是否在重量上发生了变化。广泛接受马克思主义教育的人类表示&#xff1a;别闹了&#xff0c;数据和信息属于意识&#xff0c;怎么能有重量(或者应该叫质量)。更何况这个所谓的“信息爆炸”时代每…

SQLExecption:Operation not allowed after ResultSet closed解决办法

原网址&#xff1a;http://blog.csdn.net/sku0923/article/details/1722370 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 一个stmt多个rs进行操作. 那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作. 不能互相交替使用,会引起rs已经关闭错误.…

2003正在锁定计算机,WIN2003 自动锁定怎么解决?

那么网速慢的作祟者是什么呢&#xff1f;依笔者推断原因主要有二。■网络协议配置问题&#xff0c;■WinXP计划任务的问题。但如果其它Windows电脑在网上邻居中根本看不到WinXP那台电脑&#xff0c;便可能是用户锁定和安全策略没有设置好。这时就需要从以下几个方面入手&#x…

Ajax在IE浏览器会出现中文乱码解决办法

在AJAX浏览器来进行发送数据时&#xff0c;一般它所默认的都是UTF-8的编码. Ajax在IE浏览器会出现中文乱码的情况&#xff01;解决办法如下<script type"text/javascript"> function showDiv(str){ document.getElementById("picDiv").style.displ…