一.最简单的文本代码
1.在桌面创建一个记事本将下列代码复制粘
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
@keyframes ani{
from{
transform:rotateY(0deg) rotateX(0deg);
}
to{
transform:rotateY(360deg) rotateX(360deg);
}
}
body{
perspective:1000px;
}
#heart{
position:relative;
height:200px;
width:150px;
margin:200px auto;
animation:ani 5s linear infinite;
transform-style:preserve-3d;
}
.line{
position:absolute;
height:200px;
width:150px;
border:2px solid red;
border-left:0;
border-bottom:0;
border-radius:50% 50% 0/50% 40% 0;
}
#word{
font-family:"隶书";
font-size:1.3em;
color:red;
position:absolute;
top: 80px;
left:22px;
font-weight:bold;
}
</style>
</head>
<body>
<div id="heart">
<div id="word">I Love You</div>
</div>
<script>
var heart=document.getElementById("heart");
var html="";
for(var i=0;i<36;i++){
html+="<div class='line' style='transform:rotateY("+i*10+"deg) rotateZ(45deg) translateX(25px)'></div>";
}
heart.innerHTML += html;
</script>
</body>
</html>
2.重命名该文件,将末尾的“.txt"改为".html"
3.直接通过浏览器打开该文件。
二.利用Python来编写一个爱心程序
(1)最简单的直接输出:
print(" a a")
print(" a a a")
print("a a")
print(" a a")
print(" a a")
print(" a")
直接print输出由a组成的爱心
(2)用love组成一个爱心
print(
'\n'.join([''.join([('love'[(x-y) % len('love')]
if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0
else ' ') for x in range(-30, 30)]) for y in range(30, -30, -1)])
)
这是它的输出结果: