JS 绘制心形线

JS 绘制心形线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>JS心型线</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Tangerine">
<style>
div{
position:absolute;
}
.xx-box{
left:50%;
top:0;
margin-left:-250px;
width:500px;
height:500px;
}
.xx-box .text{
top:30%;
height:48px;
line-height:48px;
color:#f00;
text-shadow: 3px 3px 4px #f00;
font-size:36px;
font-weight:bold;
width:100%;
text-align:center;
font-family:Tangerine,Tahoma,Arial,"\65f6\5c1a\4e2d\9ed1\7b80\4f53","\5b8b\4f53";
}
.xx-box .item{
width:20px;
height:20px;
overflow:hidden;
}
</style>
</head>
<body>
<div class="xx-box" id="xx-box">
<div class="text">I Love You</div>
</div>
<script>
function createPoint(x,y,c){
var div = document.createElement("div");
div.className = "item";
div.style.left = x + "px";
div.style.top = y + "px";
div.style.backgroundColor = c;
document.getElementById("xx-box").appendChild(div);
}
function heartShape(r,dx,dy,c){//r:大小;dx:水平偏移;dy:垂直偏移;c:颜色
var m,n,x,y,i;
for(i = 0; i <= 200; i += 1){
m = i;
n = -r * (((Math.sin(i) * Math.sqrt(Math.abs(Math.cos(i)))) / (Math.sin(i) + 1.4)) - 2 * Math.sin(i) + 2);
x = n * Math.cos(m) + dx;
y = n * Math.sin(m) + dy;
createPoint(x,y,c);
}
}
heartShape(120,250,100,"#f00");
</script>
</body>
</html>
  
posted @   托尼不是塔克  阅读(1393)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示