当前位置:首页 » 《随便一记》 » 正文

Python or html爱心代码(听说最近很火)

1 人参与  2022年12月06日 18:57  分类 : 《随便一记》  评论

点击全文阅读


第4种 下面第四个

 最近抖音莫名很火的一个爱心❤️

实现的方法不尽相同,重要的是心意而不是代码本身

前三种用Python来实现,最后一种较为复杂,是用HTML来实现,是笔者搜集而来

 1.

from turtle import *from time import sleepdef go_to(x, y):   up()   goto(x, y)   down()def big_Circle(size):  #函数用于绘制心的大圆   speed(9)   for i in range(150):       forward(size)       right(0.3)def small_Circle(size):  #函数用于绘制心的小圆   speed(1)   for i in range(210):       forward(size)       right(0.786)def line(size):   speed(1)   forward(51*size)def heart( x, y, size):   go_to(x, y)   left(150)   begin_fill()   line(size)   big_Circle(size)   small_Circle(size)   left(120)   small_Circle(size)   big_Circle(size)   line(size)   end_fill()def arrow():   pensize(10)   setheading(0)   go_to(-400, 0)   left(15)   forward(150)   go_to(339, 178)   forward(150)def arrowHead():   pensize(1)   speed(1)   color('red', 'red')   begin_fill()   left(120)   forward(20)   right(150)   forward(35)   right(120)   forward(35)   right(150)   forward(20)   end_fill()def main():   pensize(2)   color('red', 'pink')   #getscreen().tracer(30, 0) #取消注释后,快速显示图案   heart(200, 0, 1)          #画出第一颗心,前面两个参数控制心的位置,函数最后一个参数可控制心的大小   setheading(0)             #使画笔的方向朝向x轴正方向   heart(-80, -100, 1.5)     #画出第二颗心   arrow()                   #画出穿过两颗心的直线   arrowHead()               #画出箭的箭头   go_to(400, -300)   write("author:py.cn", move=True, align="left", font=("宋体", 30, "normal"))   done()main()

2. 

import turtle as tdef init():    t.speed(2)    t.pensize(2)    t.screensize(480, 360)    t.color('red', 'red')def draw_heart_right():    t.up()    t.goto(50, 50)    t.pendown()    t.right(45)    t.goto(100, 0)    t.seth(45)    t.fd(120)    t.circle(50, 225)def draw_heart_left():    t.up()    t.goto(0, 0)    t.down()    t.seth(45)    t.fd(120)    t.circle(50, 225)    t.seth(90)    t.circle(50, 225)    t.fd(120)def draw_arrow():    t.up()    t.seth(0)    # 羽毛    t.goto(-210, 40)    t.pendown()    t.goto(-215, 44)    t.goto(-190, 49)    t.goto(-175, 46)    t.up()    t.goto(-210, 40)    t.pendown()    t.goto(-213, 34)    t.goto(-185, 39)    t.goto(-175, 46)    t.up()    # 箭杆    t.pendown()    t.goto(0, 80)    t.penup()    t.goto(160, 110)    t.pendown()    t.goto(320, 140)    # 箭羽    t.left(160)    t.begin_fill()    t.fd(10)    t.left(120)    t.fd(10)    t.left(120)    t.fd(10)    t.end_fill()if __name__ == '__main__':    init()    draw_heart_right()    draw_heart_left()    draw_arrow()    t.hideturtle()    t.done()

3. 

import turtleimport mathturtle.pen()t=turtlet.up()t.goto(0,150)t.down()t.color('red')t.begin_fill()t.fillcolor('red')t.speed(1)t.left(45)t.forward(150)t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(250+math.sqrt(2)*100)t.right (90)t.speed(2)t.forward(250+100*math.sqrt(2))t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(100)t.right(45)t.forward(150)t.end_fill()t.goto(-10,0)t.pencolor('white')#Lt.pensize(10)t.goto(-50,0)t.goto(-50,80)t.up ()#It.goto(-100,0)t.down()t.goto(-160,0)t.goto(-130,0)t.goto(-130,80)t.goto(-160,80)t.goto(-100,80)t.up()#Ot.goto(10,25)t.down()t.right(45)t.circle(25,extent=180)t.goto(60,55)t.circle(25,extent=180)t.goto(10,25)t.up()t.goto(75,80)t.down()t.goto(100,0)t.goto(125,80)t.up()t.goto(180,80)t.down()t.goto(140,80)t.goto(140,0)t.goto(180,0)t.up()t.goto(180,40)t.down()t.goto(140,40)#Ut.up()t.goto(-40,-30)t.down()t.goto(-40,-80)t.circle(40,extent=180)t.goto(40,-30)t.hideturtle()

4. 

<!doctype html><html><head><meta charset="utf-8"><title>HTML5 Canvas爱心表白动画特效DEMO演示</title><style>html, body {  height: 100%;  padding: 0;  margin: 0;  background: #000;}canvas {  width: 100%;  height: 100%;}</style></head><body><div style="text-align:center;clear:both;"><script src="/gg_bd_ad_720x90.js" type="text/javascript"></script><script src="/follow.js" type="text/javascript"></script></div><canvas id="pinkboard"></canvas><script>var settings = {  particles: {    length:   500,    duration:   2,    velocity: 100,    effect: -0.75,    size:      30,  },};(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)}}}());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;})();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;})();var ParticlePool = (function() {  var particles,      firstActive = 0,      firstFree   = 0,      duration    = settings.particles.duration;    function ParticlePool(length) {    particles = new Array(length);    for (var i = 0; i < particles.length; i++)      particles[i] = new Particle();  }  ParticlePool.prototype.add = function(x, y, dx, dy) {    particles[firstFree].initialize(x, y, dx, dy);        firstFree++;    if (firstFree   == particles.length) firstFree   = 0;    if (firstActive == firstFree       ) firstActive++;    if (firstActive == particles.length) firstActive = 0;  };  ParticlePool.prototype.update = function(deltaTime) {    var i;        if (firstActive < firstFree) {      for (i = firstActive; i < firstFree; i++)        particles[i].update(deltaTime);    }    if (firstFree < firstActive) {      for (i = firstActive; i < particles.length; i++)        particles[i].update(deltaTime);      for (i = 0; i < firstFree; i++)        particles[i].update(deltaTime);    }        while (particles[firstActive].age >= duration && firstActive != firstFree) {      firstActive++;      if (firstActive == particles.length) firstActive = 0;    }          };  ParticlePool.prototype.draw = function(context, image) {    if (firstActive < firstFree) {      for (i = firstActive; i < firstFree; i++)        particles[i].draw(context, image);    }    if (firstFree < firstActive) {      for (i = firstActive; i < particles.length; i++)        particles[i].draw(context, image);      for (i = 0; i < firstFree; i++)        particles[i].draw(context, image);    }  };  return ParticlePool;})();(function(canvas) {  var context = canvas.getContext('2d'),      particles = new ParticlePool(settings.particles.length),      particleRate = settings.particles.length / settings.particles.duration, // particles/sec      time;    function pointOnHeart(t) {    return new Point(      160 * Math.pow(Math.sin(t), 3),      130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25    );  }    var image = (function() {    var canvas  = document.createElement('canvas'),        context = canvas.getContext('2d');    canvas.width  = settings.particles.size;    canvas.height = settings.particles.size;    function to(t) {      var point = pointOnHeart(t);      point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;      point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;      return point;    }    context.beginPath();    var t = -Math.PI;    var point = to(t);    context.moveTo(point.x, point.y);    while (t < Math.PI) {      t += 0.01;       point = to(t);      context.lineTo(point.x, point.y);    }    context.closePath();    context.fillStyle = '#ea80b0';    context.fill();      var image = new Image();    image.src = canvas.toDataURL();    return image;  })();    function render() {    requestAnimationFrame(render);        var newTime   = new Date().getTime() / 1000,        deltaTime = newTime - (time || newTime);    time = newTime;        context.clearRect(0, 0, canvas.width, canvas.height);        var amount = particleRate * deltaTime;    for (var i = 0; i < amount; i++) {      var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());      var dir = pos.clone().length(settings.particles.velocity);      particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);    }        particles.update(deltaTime);    particles.draw(context, image);  }    function onResize() {    canvas.width  = canvas.clientWidth;    canvas.height = canvas.clientHeight;  }  window.onresize = onResize;    setTimeout(function() {    onResize();    render();  }, 10);})(document.getElementById('pinkboard'));</script></body></html><!doctype html><html><head><meta charset="utf-8"><title>HTML5 Canvas爱心表白动画特效DEMO演示</title><style>html, body {  height: 100%;  padding: 0;  margin: 0;  background: #000;}canvas {  width: 100%;  height: 100%;}</style></head><body><div style="text-align:center;clear:both;"><script src="/gg_bd_ad_720x90.js" type="text/javascript"></script><script src="/follow.js" type="text/javascript"></script></div><canvas id="pinkboard"></canvas><script>var settings = {  particles: {    length:   500,    duration:   2,    velocity: 100,    effect: -0.75,    size:      30,  },};(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)}}}());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;})();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;})();var ParticlePool = (function() {  var particles,      firstActive = 0,      firstFree   = 0,      duration    = settings.particles.duration;    function ParticlePool(length) {    particles = new Array(length);    for (var i = 0; i < particles.length; i++)      particles[i] = new Particle();  }  ParticlePool.prototype.add = function(x, y, dx, dy) {    particles[firstFree].initialize(x, y, dx, dy);        firstFree++;    if (firstFree   == particles.length) firstFree   = 0;    if (firstActive == firstFree       ) firstActive++;    if (firstActive == particles.length) firstActive = 0;  };  ParticlePool.prototype.update = function(deltaTime) {    var i;        if (firstActive < firstFree) {      for (i = firstActive; i < firstFree; i++)        particles[i].update(deltaTime);    }    if (firstFree < firstActive) {      for (i = firstActive; i < particles.length; i++)        particles[i].update(deltaTime);      for (i = 0; i < firstFree; i++)        particles[i].update(deltaTime);    }        while (particles[firstActive].age >= duration && firstActive != firstFree) {      firstActive++;      if (firstActive == particles.length) firstActive = 0;    }          };  ParticlePool.prototype.draw = function(context, image) {    if (firstActive < firstFree) {      for (i = firstActive; i < firstFree; i++)        particles[i].draw(context, image);    }    if (firstFree < firstActive) {      for (i = firstActive; i < particles.length; i++)        particles[i].draw(context, image);      for (i = 0; i < firstFree; i++)        particles[i].draw(context, image);    }  };  return ParticlePool;})();(function(canvas) {  var context = canvas.getContext('2d'),      particles = new ParticlePool(settings.particles.length),      particleRate = settings.particles.length / settings.particles.duration, // particles/sec      time;    function pointOnHeart(t) {    return new Point(      160 * Math.pow(Math.sin(t), 3),      130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25    );  }    var image = (function() {    var canvas  = document.createElement('canvas'),        context = canvas.getContext('2d');    canvas.width  = settings.particles.size;    canvas.height = settings.particles.size;    function to(t) {      var point = pointOnHeart(t);      point.x = settings.particles.size / 2 + point.x * settings.particles.size / 350;      point.y = settings.particles.size / 2 - point.y * settings.particles.size / 350;      return point;    }    context.beginPath();    var t = -Math.PI;    var point = to(t);    context.moveTo(point.x, point.y);    while (t < Math.PI) {      t += 0.01;       point = to(t);      context.lineTo(point.x, point.y);    }    context.closePath();    context.fillStyle = '#ea80b0';    context.fill();      var image = new Image();    image.src = canvas.toDataURL();    return image;  })();    function render() {    requestAnimationFrame(render);        var newTime   = new Date().getTime() / 1000,        deltaTime = newTime - (time || newTime);    time = newTime;        context.clearRect(0, 0, canvas.width, canvas.height);        var amount = particleRate * deltaTime;    for (var i = 0; i < amount; i++) {      var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());      var dir = pos.clone().length(settings.particles.velocity);      particles.add(canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y);    }        particles.update(deltaTime);    particles.draw(context, image);  }    function onResize() {    canvas.width  = canvas.clientWidth;    canvas.height = canvas.clientHeight;  }  window.onresize = onResize;    setTimeout(function() {    onResize();    render();  }, 10);})(document.getElementById('pinkboard'));</script></body></html>

 最后一种文件要以文件名.html的形式命名

 点击即可跳转至默认浏览器

祝有缘人终成眷属~

笔者能力有限,文章不免疏漏,还请博友们及时指正



哎非说我文章质量不行没法发出来,我下面复制点东西(大家直接忽略)

下面也是Mkdocs的Blog相关的问题,感兴趣可以去看我主页关于Mkdocs的介绍

Hey there! You're looking at our new blog, built with the brand new built-in blog plugin. With this plugin, you can easily build a blog alongside your documentation or standalone.

Proper support for blogging, as requested by many users over the past few years, was something that was desperately missing from Material for MkDocs' feature set. While everybody agreed that blogging support was a blind spot, it was not obvious whether MkDocs could be extended in a way to allow for blogging as we know it from Jekyll and friends. The built-in blog plugin proves that it is, after all, possible to build a blogging engine on top of MkDocs, in order to create a technical blog alongside your documentation, or as the main thing.


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/49474.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (此去经年无故人)南初陆南城:结局+番外精品选集起点章节+阅读即将发布预订
  • 沈凝夏叶晚怡附加完整在线阅读(归雁不栖故人枝)最近更新列表
  • 剧情人物是时初,白浩雄的玄幻言情小说《召诸神,踏万界,天命帝女逆乾坤》,由网络作家&ldquo;海鸥&rdquo;所著,情节扣人心弦,本站TXT全本,欢迎阅读!本书共计381345字,185章节,:结局+番外免费品鉴:结局+番外评价五颗星
  • 凤青禾,江明远,***枢小说(别人修仙我捡漏,卷王们破防了)最近更新(凤青禾,江明远,***枢)整本无套路阅读
  • 薛梨小说无删减+后续(曾经亲情似草芥)畅享阅读
  • 沈南栀小说(穿越时空,我要修补时空裂缝)章节目录+起点章节(沈南栀)全篇清爽版在线
  • 未婚妻被巨蟒缠身,我该吃就吃该喝就喝前言+后续_阿豪林月周然后续+番外_小说后续在线阅读_无删减免费完结_
  • 陆骁,陆本初小说(陆骁,陆本初)(癫!睁眼穿成老太太挥鞭***逆子)前传+阅读全新作品预订
  • 姐姐含冤而死后冥王另娶,我杀穿整个地府在线阅读_阎罗殿殷红别提一口气完结_小说后续在线阅读_无删减免费完结_
  • (书荒必看)毒后重生:疯王的神医小娇妻沈清歌,萧绝:+后续热血十足
  • 重生后我和太监联手灭了敌国喻辰,林雪续集(重生后我和太监联手灭了敌国)终极反转(喻辰,林雪)全篇一口气阅读
  • 我不做灵媒后,自称灵媒摆渡人的养妹害怕了内容精选_苏晓霍老阿姐无广告_小说后续在线阅读_无删减免费完结_

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1