Comentário: Este artigo apresenta principalmente exemplos de código da tela HTML5 para implementar curvas de rosas e padrões em forma de coração. Amigos que precisam podem se referir a ele.
Imagem de reprodução:
Dica: copie o código em um arquivo HTML e salve -o e abra diretamente para ver o efeito.
Código de implementação:
<! Doctype html>
<html>
<head>
<meta charset = "gbk">
<title> HTML5 Demo </ititle>
<style type = "text/css">
#apDiv1 {
Posição: Absoluto;
Largura: 120px;
Altura: 300px;
Z-Index: 1;
Esquerda: 840px;
topo: 80px;
}
</style>
</head>
<Body>
<Canvas>
Seu navegador não suporta o elemento Canvas. </canvas>
<div>
<morm>
Equação de curva de rosa:
r = a+bsin (m/n*x)
Selecione parâmetros:
m: <input type = "número" min = "2" max = "29" value = "29"/>
n: <input type = "número" min = "1" max = "12" value = "11"/>
a: <input type = "número" min = "0" max = "5" value = "1"/>
b: <input type = "número" min = "1" max = "7" value = "5"/>
<input type = "button" value = "draw">
<HR>
<input type = "button" value = "desenho 2">
<HR>
<input type = "button" value = "cartão cardíaco">
</morm>
</div>
<script type = "text/javascript">
função draw () {
var ctx = document.getElementById ('Canvas'). getContext ('2D');
ctx.save ();
ctx.Translate (400.300);
ctx.clearrect (-400, -300.800.600);
ctx.strokestyle = "#cc0000";
var a = 0, b = 1, m = 6, n = 1;
m = document.forms [0] .m.value;
n = document.forms [0] .n.Value;
a = document.forms [0] .a.value;
b = document.forms [0] .b.value;
drawrose (ctx, a, b, m, n);
ctx.restore ();
}
função drawrose (ctx, a, b, m, n) {
ctx.BeginPath ();
var e = 0, c = 120;
var k = 2 * math.pi / 360;
fazer {
var r = a / b + math.sin (m * e / n * k);
r = r * c;
var x = r * math.cos (e * k);
var y = r * math.sin (e * k);
e += 0,1;
ctx.lineto (x, y);
} while (e <= 4320);
ctx.stroke ();
}
função draw2 () {
var ctx = document.getElementById ('Canvas'). getContext ('2D');
ctx.save ();
ctx.Translate (400.300);
ctx.clearrect (-400, -300.800.600);
ctx.strokestyle = "#cc0000";
ctx.BeginPath (); //ctx.moveto(0,0);
var e = 0, c = 150;
var k = 2 * math.pi / 360;
fazer {
x = 150*math.cos (5/2*e*k) + 50*Math.Cos (15/16*5/2*e*k);
y = 150*Math.sin (5/2*e*k) - 50*Math.sin (15/16*5/2*e*k);
e += 0,1;
ctx.lineto (x, y);
} while (e <= 3600);
ctx.stroke ();
ctx.restore ();
}
função draw3 () {
var ctx = document.getElementById ('Canvas'). getContext ('2D');
ctx.save ();
ctx.Translate (400.300);
ctx.clearrect (-400, -300.800.600);
ctx.strokestyle = "#ff0000";
ctx.BeginPath ();
var x = 1, y;
fazer {
y = -80*(math.sqrt (1 -x*x) + math.pow (x*x, 1/3));
x -= 0,001;
ctx.lineto (100*x, y);
} while (x> = -1);
fazer {
y = 80*(math.sqrt (1 -x*x) - math.pow (x*x, 1/3));
x += 0,001;
ctx.lineto (100*x, y);
} while (x <= 1);
ctx.closePath ();
var grad = ctx.CreamRadialGradient (-40, -60,10, -40, -40.200);
grad.addcolorstop (0, "#ffcc00");
grad.addcolorstop (1, "#ff0000");
ctx.fillstyle = grad;
ctx.fill ();
// ctx.stroke ();
ctx.restore ();
}
window.onload = function () {
empate();
}
</script>
</body>
</html>