• Python画爱心——谁能拒绝用代码敲出来会跳动的爱心呢~


    还不快把这份浪漫拿走!!节日就快到来了,给Ta一个惊喜吧~

     今天给大家分享一个浪漫小技巧,利用Python中的 HTML 制作一个立体会动的心动小爱心

    成千上百个爱心汇成一个大爱心,从里到外形成一个立体状,给人视觉上的冲击感!浪漫极了

    +V:hw13980 

    话不多说上才艺: 


     
       
       


         
         
         
         
       

    部分代码

      (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);
            };
          }
        })();

        /*
         *Point class
         */
        var Point = (function () {
          function Point(x, y) {
            this.x = typeof x !== "undefined" ? x : 0;
            this.y = typeof y !== "undefined" ? y : 0;
          }
          Point.prototype.clone = function () {
            return new Point(this.x, this.y);
          };
          Point.prototype.length = function (length) {
            if (typeof length == "undefined")
              return Math.sqrt(this.x * this.x + this.y * this.y);
            this.normalize();
            this.x *= length;
            this.y *= length;
            return this;
          };
          Point.prototype.normalize = function () {
            var length = this.length();
            this.x /= length;
            this.y /= length;
            return this;
          };
          return Point;
        })();

        /*
         * Particle class
         */
        var Particle = (function () {
          function Particle() {
            this.position = new Point();
            this.velocity = new Point();
            this.acceleration = new Point();
            this.age = 0;
          }
          Particle.prototype.initialize = function (x, y, dx, dy) {
            this.position.x = x;
            this.position.y = y;
            this.velocity.x = dx;
            this.velocity.y = dy;
            this.acceleration.x = dx * settings.particles.effect;
            this.acceleration.y = dy * settings.particles.effect;
            this.age = 0;
          };
          Particle.prototype.update = function (deltaTime) {
            this.position.x += this.velocity.x * deltaTime;
            this.position.y += this.velocity.y * deltaTime;
            this.velocity.x += this.acceleration.x * deltaTime;
            this.velocity.y += this.acceleration.y * deltaTime;
            this.age += deltaTime;
          };
          Particle.prototype.draw = function (context, image) {
            function ease(t) {
              return --t * t * t + 1;
            }
            var size = image.width * ease(this.age / settings.particles.duration);
            context.globalAlpha = 1 - this.age / settings.particles.duration;
            context.drawImage(
              image,
              this.position.x - size / 2,
              this.position.y - size / 2,
              size,
              size
            );
          };
          return Particle;
        })();

    运行结果:

  • 相关阅读:
    thinkPhp5返回某些指定字段
    MySQL:IFNULL无法返回null的情况
    BiLSTM(双向LSTM)实现股票预测(TensorFlow2版)|时间序列预测
    【LeetCode】67. 二进制求和
    纯Unity环境下,把一个object系列化成json并保存到本地,然后读取json再次反系列化成object
    阿里OceanBase GitHub送礼刷Star引争议,CTO致歉
    Spring中的事务管理
    window Zookeeper 启动;
    第一百六十二回 PopupMenuButton组件
    day53 动态规划part14● 1143.最长公共子序列 ● 1035.不相交的线 ● 53. 最大子序和 动态规划
  • 原文地址:https://blog.csdn.net/m0_59485658/article/details/127748894