• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

李珣动态爱心代码教程

武飞扬头像
池鱼&思故渊
帮助1

作为一个学计算机的小白,在网上看了人家写的代码,感觉是非常beatiful,在这给非计算机专业的兄弟们教一下怎么拿代码哄女朋友,不用安装任何软件,只要一台电脑欧克,俗话说行家看是傻子操作,外行一看,我nia nia 真他****厉害,废话不多,看下面傻瓜式教学

第一步,先在桌面建一个文本文档,随便写个名字,如图所示

学新通

第二步,打开此文档将下面代码复制粘进去

  1.  
    <!doctype html>
  2.  
    <html>
  3.  
    <head>
  4.  
    <meta charset="utf-8">
  5.  
    <title>HTML5 Canvas爱心表白动画特效DEMO演示</title>
  6.  
     
  7.  
    <style>
  8.  
    html, body {
  9.  
    height: 100%;
  10.  
    padding: 0;
  11.  
    margin: 0;
  12.  
    background: #000;
  13.  
    }
  14.  
    canvas {
  15.  
    width: 100%;
  16.  
    height: 100%;
  17.  
    }
  18.  
    </style>
  19.  
     
  20.  
    </head>
  21.  
    <body>
  22.  
     
  23.  
    <div style="text-align:center;clear:both;">
  24.  
    <script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
  25.  
    <script src="/follow.js" type="text/javascript"></script>
  26.  
    </div>
  27.  
     
  28.  
    <canvas id="pinkboard"></canvas>
  29.  
     
  30.  
    <script>
  31.  
    var settings = {
  32.  
    particles: {
  33.  
    length: 500,
  34.  
    duration: 2,
  35.  
    velocity: 100,
  36.  
    effect: -0.75,
  37.  
    size: 30,
  38.  
    },
  39.  
    };
  40.  
     
  41.  
    (function(){var b=0;var c=["ms","moz","webkit","o"];for(var a=0;a<c.length&&!window.requestAnimationFrame; a){window.requestAnimationFrame=window[c[a] "RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a] "CancelAnimationFrame"]||window[c[a] "CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d f)},f);b=d f;return g}}if(!window.cancelAnimationFrame){window.cancelAnimationFrame=function(d){clearTimeout(d)}}}());
  42.  
     
  43.  
    var Point = (function() {
  44.  
    function Point(x, y) {
  45.  
    this.x = (typeof x !== 'undefined') ? x : 0;
  46.  
    this.y = (typeof y !== 'undefined') ? y : 0;
  47.  
    }
  48.  
    Point.prototype.clone = function() {
  49.  
    return new Point(this.x, this.y);
  50.  
    };
  51.  
    Point.prototype.length = function(length) {
  52.  
    if (typeof length == 'undefined')
  53.  
    return Math.sqrt(this.x * this.x this.y * this.y);
  54.  
    this.normalize();
  55.  
    this.x *= length;
  56.  
    this.y *= length;
  57.  
    return this;
  58.  
    };
  59.  
    Point.prototype.normalize = function() {
  60.  
    var length = this.length();
  61.  
    this.x /= length;
  62.  
    this.y /= length;
  63.  
    return this;
  64.  
    };
  65.  
    return Point;
  66.  
    })();
  67.  
     
  68.  
    var Particle = (function() {
  69.  
    function Particle() {
  70.  
    this.position = new Point();
  71.  
    this.velocity = new Point();
  72.  
    this.acceleration = new Point();
  73.  
    this.age = 0;
  74.  
    }
  75.  
    Particle.prototype.initialize = function(x, y, dx, dy) {
  76.  
    this.position.x = x;
  77.  
    this.position.y = y;
  78.  
    this.velocity.x = dx;
  79.  
    this.velocity.y = dy;
  80.  
    this.acceleration.x = dx * settings.particles.effect;
  81.  
    this.acceleration.y = dy * settings.particles.effect;
  82.  
    this.age = 0;
  83.  
    };
  84.  
    Particle.prototype.update = function(deltaTime) {
  85.  
    this.position.x = this.velocity.x * deltaTime;
  86.  
    this.position.y = this.velocity.y * deltaTime;
  87.  
    this.velocity.x = this.acceleration.x * deltaTime;
  88.  
    this.velocity.y = this.acceleration.y * deltaTime;
  89.  
    this.age = deltaTime;
  90.  
    };
  91.  
    Particle.prototype.draw = function(context, image) {
  92.  
    function ease(t) {
  93.  
    return (--t) * t * t 1;
  94.  
    }
  95.  
    var size = image.width * ease(this.age / settings.particles.duration);
  96.  
    context.globalAlpha = 1 - this.age / settings.particles.duration;
  97.  
    context.drawImage(image, this.position.x - size / 2, this.position.y - size / 2, size, size);
  98.  
    };
  99.  
    return Particle;
  100.  
    })();
  101.  
     
  102.  
    var ParticlePool = (function() {
  103.  
    var particles,
  104.  
    firstActive = 0,
  105.  
    firstFree = 0,
  106.  
    duration = settings.particles.duration;
  107.  
     
  108.  
    function ParticlePool(length) {
  109.  
    particles = new Array(length);
  110.  
    for (var i = 0; i < particles.length; i )
  111.  
    particles[i] = new Particle();
  112.  
    }
  113.  
    ParticlePool.prototype.add = function(x, y, dx, dy) {
  114.  
    particles[firstFree].initialize(x, y, dx, dy);
  115.  
     
  116.  
    firstFree ;
  117.  
    if (firstFree == particles.length) firstFree = 0;
  118.  
    if (firstActive == firstFree ) firstActive ;
  119.  
    if (firstActive == particles.length) firstActive = 0;
  120.  
    };
  121.  
    ParticlePool.prototype.update = function(deltaTime) {
  122.  
    var i;
  123.  
     
  124.  
    if (firstActive < firstFree) {
  125.  
    for (i = firstActive; i < firstFree; i )
  126.  
    particles[i].update(deltaTime);
  127.  
    }
  128.  
    if (firstFree < firstActive) {
  129.  
    for (i = firstActive; i < particles.length; i )
  130.  
    particles[i].update(deltaTime);
  131.  
    for (i = 0; i < firstFree; i )
  132.  
    particles[i].update(deltaTime);
  133.  
    }
  134.  
     
  135.  
    while (particles[firstActive].age >= duration && firstActive != firstFree) {
  136.  
    firstActive ;
  137.  
    if (firstActive == particles.length) firstActive = 0;
  138.  
    }
  139.  
     
  140.  
     
  141.  
    };
  142.  
    ParticlePool.prototype.draw = function(context, image) {
  143.  
    if (firstActive < firstFree) {
  144.  
    for (i = firstActive; i < firstFree; i )
  145.  
    particles[i].draw(context, image);
  146.  
    }
  147.  
    if (firstFree < firstActive) {
  148.  
    for (i = firstActive; i < particles.length; i )
  149.  
    particles[i].draw(context, image);
  150.  
    for (i = 0; i < firstFree; i )
  151.  
    particles[i].draw(context, image);
  152.  
    }
  153.  
    };
  154.  
    return ParticlePool;
  155.  
    })();
  156.  
     
  157.  
    (function(canvas) {
  158.  
    var context = canvas.getContext('2d'),
  159.  
    particles = new ParticlePool(settings.particles.length),
  160.  
    particleRate = settings.particles.length / settings.particles.duration, // particles/sec
  161.  
    time;
  162.  
     
  163.  
    function pointOnHeart(t) {
  164.  
    return new Point(
  165.  
    160 * Math.pow(Math.sin(t), 3),
  166.  
    130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) 25
  167.  
    );
  168.  
    }
  169.  
     
  170.  
    var image = (function() {
  171.  
    var canvas = document.createElement('canvas'),
  172.  
    context = canvas.getContext('2d');
  173.  
    canvas.width = settings.particles.size;
  174.  
    canvas.height = settings.particles.size;
  175.  
    function to(t) {
  176.  
    var point = pointOnHeart(t);
  177.  
    point.x = settings.particles.size / 2 point.x * settings.particles.size / 350;
  178.  
    point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;
  179.  
    return point;
  180.  
    }
  181.  
    context.beginPath();
  182.  
    var t = -Math.PI;
  183.  
    var point = to(t);
  184.  
    context.moveTo(point.x, point.y);
  185.  
    while (t < Math.PI) {
  186.  
    t = 0.01;
  187.  
    point = to(t);
  188.  
    context.lineTo(point.x, point.y);
  189.  
    }
  190.  
    context.closePath();
  191.  
    <!-- 粉色#ea80b0-->
  192.  
    context.fillStyle = '#228B22';
  193.  
    context.fill();
  194.  
     
  195.  
    var image = new Image();
  196.  
    image.src = canvas.toDataURL();
  197.  
    return image;
  198.  
    })();
  199.  
     
  200.  
    function render() {
  201.  
    requestAnimationFrame(render);
  202.  
     
  203.  
    var newTime = new Date().getTime() / 1000,
  204.  
    deltaTime = newTime - (time || newTime);
  205.  
    time = newTime;
  206.  
     
  207.  
    context.clearRect(0, 0, canvas.width, canvas.height);
  208.  
     
  209.  
    var amount = particleRate * deltaTime;
  210.  
    for (var i = 0; i < amount; i ) {
  211.  
    var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
  212.  
    var dir = pos.clone().length(settings.particles.velocity);
  213.  
    particles.add(canvas.width / 2 pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);
  214.  
    }
  215.  
     
  216.  
    particles.update(deltaTime);
  217.  
    particles.draw(context, image);
  218.  
    }
  219.  
     
  220.  
    function onResize() {
  221.  
    canvas.width = canvas.clientWidth;
  222.  
    canvas.height = canvas.clientHeight;
  223.  
    }
  224.  
    window.onresize = onResize;
  225.  
     
  226.  
    setTimeout(function() {
  227.  
    onResize();
  228.  
    render();
  229.  
    }, 10);
  230.  
    })(document.getElementById('pinkboard'));
  231.  
     
  232.  
    </script>
  233.  
    <a href="https://nmdvd.top/vod-detail-id-40264.html" target="_blank">
  234.  
    <p>只要我没对象,你们得到的心就是绿的,</p>
  235.  
    <p>往上翻代码提示有粉色代码,点击这行字跳转高清影视观看 点燃我,温暖我</p>
  236.  
    </a>
  237.  
    </br>
  238.  
    </br>
  239.  
    </br>
  240.  
    </body>
  241.  
    </html>
学新通

 第三步,点击左上角文件,单击另存为,将文件名改为(你的文件名.html(一定要点点))如我的(李珣爱心代码.html),然后保存类型选择所有文件

学新通

 保存完成后会出现浏览器图标,如下:

学新通

最后双击该图标,就可以看到你想看动态爱心啦

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgekhjc
系列文章
更多 icon
同类精品
更多 icon
继续加载