sábado, 31 de outubro de 2015
Cardioide em javaScript
<script> //============================================================================ // Autor: Luiz Augusto S. Prado - 2015 // Fonte: http://tivideotutoriais.blogspot.com.br/2015/10/cardioide-em-javascript.html // Site: http://www.codigorapido.com.br // Programa: Cardioide //============================================================================ function pos_circulo(ang, raio ) { x1 = Math.round(Math.cos(ang*Math.PI/180) * raio) ; y1 = Math.round(Math.sin(ang*Math.PI/180) * raio) ; return [x1,y1]; } function drawLine(ctx) { var x; var y; var antigoX=0; var antigoY=0; var tmx = 800; var tmy = 600; var k=0.01; //================================================================= ctx.beginPath() ; ctx.lineWidth=1 ; ctx.strokeStyle = "#F00"; var rotation=45; var raio = 60; var incremento = 80 raio_raio_variavel = raio * Math.sin(rotation*Math.PI/180) + raio * Math.cos(rotation*Math.PI/180) + incremento ; var array1 = pos_circulo( 0, raio_raio_variavel ); ctx.moveTo( array1[0]+tmx/2, array1[1]+tmy/2 ); for(var ang=0; ang<360; ang+=k) { raio_raio_variavel = raio * Math.sin((ang+rotation)*Math.PI/180) + raio * Math.cos((ang+rotation)*Math.PI/180) + incremento ; array1 = pos_circulo( ang, raio_raio_variavel ); ctx.lineTo( array1[0]+tmx/2, array1[1]+tmy/2 ); } ctx.stroke() ; //================================================================= //eixo x //================================================================= ctx.beginPath() ; ctx.lineWidth=1 ; ctx.strokeStyle = "#0F0"; ctx.moveTo( tmx/2 -220, tmy/2 ); ctx.lineTo( tmx/2 +220, tmy/2 ); ctx.stroke() ; //================================================================= //eixo y //================================================================= ctx.beginPath() ; ctx.lineWidth=1 ; ctx.strokeStyle = "#00F"; ctx.moveTo( tmx/2 , tmy/2 -220); ctx.lineTo( tmx/2 , tmy/2 +220); ctx.stroke() ; } </script> <body> <canvas id="canvas" width="800" height="600"></canvas> </body> <script> var ctx=document.getElementById("canvas").getContext("2d"); drawLine(ctx); </script>
Nenhum comentário:
Postar um comentário
Postagem mais recente
Postagem mais antiga
Página inicial
Nenhum comentário:
Postar um comentário