《春雪》

唐·东方虬

春雪满空来,触处似花开。

不知园里树,若个是真梅。

《红林擒近·寿词·满路花》

宋·陈允平

三万六千顷,玉壶天地寒。庾岭封的皪,淇园折琅。漠漠梨花烂漫,纷纷柳絮飞残。直疑潢潦惊翻,斜风溯狂澜。

对此频胜赏,一醉饱清欢。呼童翦韭,和冰先荐春盘。怕东风吹散,留尊待月,倚阑莫惜今夜看。

在陈允平笔下,雪是绝美的。

人生当如这漫天的飞雪,肆意地飘洒。这是我对人生的感悟。

今天我们用js来模拟雪,让雪花飞扬在代码的世界,因为喜欢雪,我收集了一些关于雪的代码。

js制作的透明超炫酷雪花效果 (mubanmao.top)

js制作的漂亮雪花图案

js制作的唯美温柔落雪效果

js制作的超唯美雪花飘落效果

雪舞飞花,醉人如痴!

代码欣赏:

var G1Code;
(function() {G1Code = function(x, y) {var self = this;self.x = x;self.y = y;};var members = {toString: function() {var self = this;// Added roundingreturn "G1 X" + self.x.toFixed(2) + " Y" + self.y.toFixed(2);},// Rotate the XY point of the GCoderotate: function(theta) {var self = this;var oldX = self.x;var oldY = self.y;self.x = oldX * Math.cos(theta) - oldY * Math.sin(theta);self.y = oldX * Math.sin(theta) + oldY * Math.cos(theta);},// Add relative movesrelative_move: function(xMove, yMove) {var self = this;var oldX = self.x;var oldY = self.y;self.x = oldX + xMove;self.y = oldY + yMove;},// Clone Methodclone: function() {var self = this;return new G1Code(self.x, self.y);}}// Copy over members to prototypefor (var key in members) {G1Code.prototype[key] = members[key];};
})();var PolyLine;
(function() {PolyLine = function() {this.listofcodes = [];};var members = {toString: function() {var self = this;var output = "";for(gcode in self.listofcodes) {output += self.listofcodes[gcode] + "\n"}return output;},draw: function(ctx) {var self = this;ctx.beginPath();var code = self.listofcodes[0];ctx.moveTo(code.x, code.y);for(var n=1; n < self.listofcodes.length; n++) {code = self.listofcodes[n];ctx.lineTo(code.x, code.y);}ctx.closePath();},// add a single G1Code to the listappend: function(gcode) {var self = this;self.listofcodes.push(gcode);},// add another PolyLine to the end of this PolyLineextend: function(polyline) {var self = this;for(gcode in polyline.listofcodes) {self.listofcodes.push(polyline.listofcodes[gcode].clone());}},// method to make a clone of the myPolyLineclone: function() {var self = this;var cloned = new PolyLine();for(gcode in self.listofcodes) {cloned.append(self.listofcodes[gcode].clone());}return cloned;},// rotate each individual G1Code withinrotate: function(angle) {var self = this;for(gcode in self.listofcodes) {self.listofcodes[gcode].rotate(angle);}},// mirror the list of G1Codes around the x axis// this may be a counter-intuitive name - rename to mirrorY?mirrorX: function() {var self = this;for(gcode in self.listofcodes) {self.listofcodes[gcode].y = -1*(self.listofcodes[gcode].y);}},// reverse the order of the list of G1Codesreverse: function() {var self = this;self.listofcodes.reverse();}};// Copy over members to prototypefor (var key in members) {PolyLine.prototype[key] = members[key];};
})();var Snowflake;
(function() {Snowflake = function(options) {this.options = {/** {Integer} Number of arms of the snowflake */numArms: 6,/** {Integer} Length of arms of the snowflake */armLength: 100,/** {Integer} Thickness of arms of the snowflake */armThickness: 3,/** {Integer} Number of spikes on the arms of the snowflake */numSpikes: 4,/** {Number}  */spacer: 0.5};for (var key in options) {this.options[key] = options[key];}this.__gapSize = (this.options.armLength/this.options.numSpikes)/2;};/*---------------------------------------------------------------------------PRIVATE FUNCTIONS---------------------------------------------------------------------------*//*** Generates a random integer that is between two integers.** @param from {Integer} The integer to start from.* @param to {Integer} The integer to end with.** @return {Integer} Random integer in between the two given integers.**/function randomInt(from, to) {return Math.floor(Math.random() * (to - from + 1) + from);};/*** @param degrees {Number} Angle in degrees** @return {Number} Angle in radians**/function radians(degrees) {return degrees*(Math.PI/180);};var members = {/*---------------------------------------------------------------------------INTERNAL FIELDS ::---------------------------------------------------------------------------*//** {Number} Set in constructor */__gapSize: 0,/*---------------------------------------------------------------------------PUBLIC API---------------------------------------------------------------------------*//*** Draws the snowflake** @param ctx {2D Context} The 2D graphics context from a canvas element.*/draw: function(ctx) {var self = this;var spikyArm = new PolyLine(),thisGCode = new G1Code(self.options.armThickness, self.options.armThickness/2);spikyArm.append(thisGCode);var angle = radians(30);for(var n=0; n < self.options.numSpikes; n++) {var spikeLength = Math.random()*(self.options.armLength/2),// spikeLength = arm_length/2.0,x1 = self.options.spacer + self.__gapSize*(n*2),y1 = self.options.armThickness/2,x2 = self.options.spacer + x1 + spikeLength*Math.cos(angle),y2 = spikeLength*Math.sin(angle),x3 = self.options.spacer + x1 + self.__gapSize,y3 = self.options.armThickness/2;spikyArm.append(new G1Code(x1, y1));spikyArm.append(new G1Code(x2, y2));spikyArm.append(new G1Code(x3, y3));};thisGCode = new G1Code(self.options.armLength, self.options.armThickness/2);spikyArm.append(thisGCode);// make a mirror image of the first half of the armotherHalf = spikyArm.clone();otherHalf.mirrorX();otherHalf.reverse();// make a pointy tipthisGCode = new G1Code(self.options.armLength+(self.options.armLength/10), 0);// join em togetherspikyArm.append(thisGCode);spikyArm.extend(otherHalf);// join together 6 rotated copies of the spiky armvar thisGCodeStar = new PolyLine();for(var a=0; a < self.options.numArms; a++) {spikyArm.rotate(radians(-(360/self.options.numArms)));thisGCodeStar.extend(spikyArm);}thisGCodeStar.draw(ctx);}}// Copy over members to prototypefor (var key in members) {Snowflake.prototype[key] = members[key];}})();

js模拟制作超逼真的雪花效果相关推荐

  1. html5实现3d翻页效果,利用css3 3d transform制作超逼真翻书效果

    本教程给大家带来一个非常有创意的翻书效果,使用的是css 3D transforms属性和css transitions属性.这里将给你展示两种不同的图书设计:精装书和平装书.这两种设计只需要简单的改 ...

  2. html 页面下雪效果,HTML5超逼真下雪场景效果

    简要教程 这是一款基于jquery的超逼真下雪场景特效.该特效使用jquery代码来动态插件html5 canvas元素,然后在canvas中制作下雪特效. 使用方法 在页面中引入ThreeCanva ...

  3. 用JS模拟向左移动的侧移式灯箱效果

    HTML结构如下: 其中ahot是表示有几屏,现在正移动到哪一屏: ohot表示整个灯箱,ihot也是整个灯箱,但先是隐藏起来的: 而dhot表示一屏灯箱,此处共四屏: hot_div是表示一屏灯箱的 ...

  4. PS如何制作超酷3D字效果

    效果图.jpg (24.94 KB) 2008-4-4 21:46 1.打开PS 执行文件-新建-新建550X400像素空白文档 1.jpg (36.69 KB) 2008-4-4 21:46 2.输 ...

  5. html中实现添加水印的功能,JS模拟实现图片添加水印功能

    JS模拟实现图片添加水印功能 ======================================================== 今天看到网友发帖求助如果在图片上自动添加水印的功能,于是 ...

  6. JS模拟实现图片添加水印功能

    JS模拟实现图片添加水印功能 ======================================================== 今天看到网友发帖求助如果在图片上自动添加水印的功能,于是 ...

  7. js制作的模拟超逼真下雨效果

    一层秋雨一层凉. 小楼一夜听春雨. 虞美人·听雨 少年听雨歌楼上.红烛昏罗帐.壮年听雨客舟中.江阔云低.断雁叫西风. 而今听雨僧庐下.鬓已星星也.悲欢离合总无情.一任阶前.点滴到天明. 我是那迷恋微雨 ...

  8. js实现雪花效果(超简单)

    打个广告,最底下的公众号,可以每天领外卖红包.打车优惠券还有96折充值电费等,需要的可以关注一下哦 使用js实现雪花飘落效果,话不多说直接上代码 <!DOCTYPE html> <h ...

  9. php绘制雪花图,怎么制作雪花飘落动态图片 雪花效果图片制作

    雪花飘落是冬天特有的一种美景,一般来说只有生活在靠近北方的小伙伴们才有机会看到雪,而生活在南方的小伙伴就有些许遗憾啦.雪花飘落的场景当然很美,我们今天要讲的重点并不是说雪花怎么美哦,而是要教大家怎么制 ...

最新文章

  1. 为特定用户创建监牢 chroot
  2. Glide 源码分析与面试提问
  3. mysql 双缓冲_Mysql一些好的优化建议(二)
  4. mysql 绕过select报错_MySQL注射绕过技巧(三)
  5. 【CH5105】Cookies
  6. php 邮箱重置密码错误,discuz邮箱重置密码参数失败的解决方法
  7. 2017前端技术大盘点 1
  8. 2016-11-15NOIP模拟赛
  9. Visual Graph图形控件的高级应用
  10. 【深度学习中的数学】高维矩阵乘法规则
  11. imp遇到重复数据_oracle的imp导入时覆盖目标数据库
  12. 移动端Touch (触摸)事件
  13. win10亮度_Win10系统运行游戏或大型软件的优化设置教程
  14. 从0开始学习 GitHub 系列之「08.如何发现优秀的开源项目」----转载自stormzhang 原创文章
  15. 使用js调用设备摄像头并实现拍照
  16. Learning ROS for Robotics Programming Second Edition学习笔记(六) indigo xtion pro live
  17. nanotime java 博客园_JVM源码分析之System.currentTimeMillis及nanoTime原理详解
  18. 剑指offer——丑数
  19. layui前端框架的基本使用方法
  20. STM32F03C8T6 MPU6050 标准库

热门文章

  1. SwitchResX 开启HiDPI时显示Not installed的解决办法
  2. linux修改文件元信息,Linux 文件元数据详细讲解
  3. MATLAB取3维数组中的一层?
  4. iOS 跳转到 App Store 下载评分页面
  5. 用我一辈子去忘记(昆明-大理-丽江-香格里
  6. 电路设计实例(电源转换电路设计---24V转3.3V或者5V)
  7. ElGamal加密算法简介
  8. @NotNull、@NotEmpty、@NotBlank区别
  9. 【CityEngine教程文档】 ---02 街道教程 之高级街道网
  10. 累乘计算问题(C语言程序设计)