正文
一些废话(直接看代码的可跳过)
贝塞尔曲线:什么是贝塞尔曲线?用过PS的就知道,那破钢笔工具就是,什么,没用过?自行百度用法。
需要的工具
直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
body {
position: fixed;
background: black;
}
#flower {
border: 1px solid red;
width: 500px;
height: 500px;
position: relative;
}
</style>
</head>
<body>
<div id="flower"></div>
</body>
<script>
(function (data) {
var _methods = {
init: function () {
this.data = data.data
this.e = data.e
this.count = data.number
this.color = data.color
this.number = 360 / this.count
for (var i = 0, j = .1; i < this.count; i++, j += .1) {
var canvas = document.createElement('canvas')
canvas.id = 'flower' + i
canvas.height = data.height
canvas.width = data.width
canvas.style.position = 'absolute'
canvas.style.transition = j + 's ease'
this.$(this.e).appendChild(canvas)
this.painting(this.$('flower' + i))
}
this.handle()
},
painting: function (e) {
var ctx = e.getContext("2d")
ctx.beginPath()
ctx.moveTo(this.data.start.x, this.data.start.y)
ctx.quadraticCurveTo(this.data.curve.x, this.data.curve.y, this.data.end.x, this.data.end.y)
ctx.moveTo(this.data.start.x, this.data.start.y)
ctx.quadraticCurveTo(this.data.start.x + this.data.curve.x, this.data.curve.y, this.data.end.x, this.data.end.y)
ctx.fillStyle = this.color
ctx.strokeStyle = this.color
ctx.globalAlpha = 0.1
ctx.fill()
ctx.stroke()
},
handle: function () {
var self = this
var i = 0
var timer = setInterval(function () {
if (i > self.count) {
clearInterval(timer)
return
}
self.$('flower' + i).style.transform = 'rotate(' + i * self.number + 'deg)'
i++
})
},
$: function (dom) {
return document.getElementById(dom)
}
}
_methods.init()
})({
e: "flower",
height: 500,
width: 500,
color: '#cc00ff',
data: {
start: {
x: 250,
y: 0
},
curve: {
x: 125,
y: 125
},
end: {
x: 250,
y: 250
}
},