用python画烟花-python 实现漂亮的烟花,樱花,玫瑰花
//两个canvas
var tree = document.getElementById("tree");
tree.width = window.innerWidth;
tree.height = window.innerHeight ;
var tCxt = tree.getContext("2d");
var flower = document.getElementById("flower");
flower.width = window.innerWidth;
flower.height = window.innerHeight ;
var cxt = flower.getContext("2d");
var flowerList = [];//樱花列表
var rootTop = 450 ;//树起点
var flowerColor = "rgba(255,192,203,.3)" ;//花色
var flowerColorDeep = "rgba(241,158,194,.5)" ;//花色深
var treeColor2 = "rgba(255,192,203,.5)" ;//树枝颜色
var treeColor = "#FFF" ;//树干颜色
var fallList = [];//飘落樱花列表
var g = 0.01 ;//重力加速度
var gWind = 0.005;//风力加速度
var limitSpeedY = 1;//速度上限
var limitSpeedX = 1 ;//速度上限
cxt.shadowColor= "#FFF" ;
cxt.shadowBlur = 10 ;
function drawTree(x,y,deg,step,type){
var deg1 = step%2 == 0 ? 0.1 : -0.1 ;
var x1 = x + Math.cos(deg+deg1) * (step+4) * 0.8 ;//以步长来判断枝干长度 x轴偏移大一些
var y1 = y + Math.sin(deg+deg1) * (step-1) * 0.8 ;//以步长来判断枝干长度 Y轴压缩一些
tCxt.beginPath();
tCxt.lineWidth = step/3;
tCxt.moveTo(x,y);
tCxt.lineTo(x1,y1);
tCxt.strokeStyle = (step > 5 ) ? treeColor : treeColor2 ;//细纸条都换成花的颜色
tCxt.stroke();
if(step > 20){//树干相交的位置有间隙,以一个圆填充
tCxt.fillStyle = treeColor ;
tCxt.arc(x,y,step/6,0,Math.PI*2);
tCxt.fill();
}
if(step < 3 || (step < 23 && Math.random() > 0.1)){
//末梢位置 画花瓣
var color = [flowerColorDeep,flowerColor,flowerColor][Math.round(Math.random()+0.2)] ;
var r = 2+Math.random()*2
tCxt.fillStyle = color ;
tCxt.arc(x1+Math.random()*3,y1+Math.random()*3,r,0,Math.PI)
tCxt.fill();
flowerList.push({x:x,y:y,sx:(Math.random()-0.5),sy:0,color:color,r:r,deg:deg});//保存下画樱花的位置
}
step -- ;
if(step > 0){
drawTree(x1,y1,deg,step,type);
if(step%3 == 1 && step > 0 && step < 30)
drawTree(x1,y1,deg+0.2 + 0.3 * Math.random(),Math.round(step/1.13));//右分叉
if(step%3 == 0 && step > 0 && step < 30)
drawTree(x1,y1,deg-0.2 - 0.3 * Math.random(),Math.round(step/1.13));//左分叉
}
}
drawTree(tree.width/2,rootTop,-Math.PI/2,30,1);//执行
var len = flowerList.length ;
function step(){
if(Math.random() > 0.3) fallList.push(flowerList[Math.floor(Math.random()*len)]);//随机取出一个,花瓣复制到飘落花瓣的列表中
cxt.clearRect(0,0,tree.width,tree.height);
for(var i = 0 ;i < fallList.length ; i ++){
if(fallList[i].sy < limitSpeedY) fallList[i].sy += g ;
fallList[i].sx += gWind ;
fallList[i].x += fallList[i].sx ;
fallList[i].y += fallList[i].sy ;
if(fallList[i].y > rootTop+30){//飘到树根+30的花瓣移除
fallList.splice(i,1);
i -- ;
continue ;
}
cxt.beginPath();
cxt.fillStyle = fallList[i].color ;
fallList[i].deg += fallList[i].sx*0.05 ;//跟速度相关的旋转花瓣
cxt.arc(fallList[i].x,fallList[i].y,fallList[i].r,fallList[i].deg,fallList[i].deg+Math.PI*1.3);
cxt.fill();
}
requestAnimationFrame(step);
}
requestAnimationFrame(step);
用python画烟花-python 实现漂亮的烟花,樱花,玫瑰花相关推荐
- 圣诞节快到了,教大家用Python画一个简单的圣诞树和烟花,送给那个她
用Python画出圣诞树和烟花,瞧瞧我这简易版的吧 序言 圣诞树 效果展示 代码展示 圣诞树上加烟花 效果展示 代码展示 写在最后 序言 这不是圣诞节快到了,准备让让女朋友开心开心,也算是亲手做的,稍 ...
- python画七色花代码_漂亮的七色花简笔画怎么画
导读:小编根据大家的需要整理了一份关于<漂亮的七色花简笔画怎么画>的内容,具体内容: 七色花就如同它的名字一样,是有七种颜色的花朵,非常的美丽.那么漂亮的七色花的简笔画要怎么画呢?小编今天 ...
- python画曲线-Python绘制各种简单优美曲线
原标题:Python绘制各种简单优美曲线 matplotlib是著名的Python绘图库,它提供了一整套绘图API,十分适合交互式绘图.,解决数据分析和可视化问题,其实也是Python的拿手好戏.另外 ...
- python画曲线图-python画曲线
广告关闭 腾讯云双11爆品提前享,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高满返5000元! 桃心形曲线的方程如下 matlab绘制效果如下:? matlab程序如下. clc ...
- 用python画圣诞树-python圣诞树
广告关闭 腾讯云双11爆品提前享,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高满返5000元! import termcolorimport randomimport timei ...
- python画曲线图-python画蝴蝶曲线图的实例
蝴蝶曲线是由Temple H・Fay发现的可用极坐标函数表示的蝴蝶曲线. 由于此曲线优美, 因此就想把它作为博客favicon.ico,这里我使用pytho matplotlib.pyplot包来绘制 ...
- python画-用Python画一颗特别的心送给她
[前言] 520刚过去了,大家有没有跟自己喜欢的对象在一起呢? 520 当天你还在送 玫瑰花?巧克力?情侣套装?... 小编就想说:你能不能换点新意呢,这些操作已经普通的不能再普通了吧!就像别人来例假 ...
- python画代码-Python教程_Python画Mandelbrot集 代码
Python教程_Python画Mandelbrot集 代码 作者:Comet 来源: 课课家 www.kokojia.com点击数:278发布时间:2015-06-19 11:17:19 曼德勃罗集 ...
- python画轨迹曲线-python 画3维轨迹图并进行比较的实例
一. 数据的格式 首先我们需要x,y,z三个数据进行画图.从本实验用到的数据集KITTI 00.txt中举例: 1.000000e+00 9.043680e-12 2.326809e-11 5.551 ...
- 用python画花瓣-Python:绘制樱花树
代码详解 (一)绘制画幕 首先绘制画幕,命令说明如下: screensize(width, height, bg=color):设置画幕大小及颜色 setup(p1, p2):设置画幕大小,当 p1. ...
最新文章
- mysql5.7.22并行回放_MySQL 5.7并行复制时代
- 如何处理win10系统内置Linux系统闪退问题
- python趣味编程10例-Python趣味编程与精彩实例
- 在做研究的时候很重要的事情
- 前端学习(2344):高阶组件和函数子组件
- 算法之排序算法-shell排序(移位法)
- python 循环语句 for while range
- 基于Python+Django+Mysql的蔬菜水果在线购物商城
- bzoj 2850 巧克力王国 —— K-D树
- java 建立缓存_java动态缓存——创建一个简单的缓存
- 【转】Unity5 新AssetBundle打包方式 BuildPipeline.BuildAssetBundles
- 使用formData对象提交表单并上传图片
- OAuth2.0系列四:OAuth2.0简化模式
- 【Cesium】智慧城市建筑白模泛光特效
- vscode的vue代码提示与补全没反应(vetur问题)
- short 在JAVA_short在java中是什么类型的
- 谷粒商城项目工具准备
- 带x的分数解方程计算机,五年级分数解方程
- 如何用微信朋友圈引起客户注意?
- JavaScript中函数当作参数传递或当作返回值