InicioInfoHtml5: Dibuja utilizando Canvas y Javascript

Html5: Dibuja utilizando Canvas y Javascript

Info6/27/2011
Aca les dejo un codigo simple para dibujar un smile usando solo algunos pocos estilos, algo de javascirpt y un canvas.

Primero agregamos el agregamos en el tag "style"


H1 {
    font-family: Arial, Sans-serif;
    font-size: 24px;
    color: navy;
    font-weight: normal;
    position: absolute;
    left: 45px;
    top: 0;
}


Despues en el tag "script"

window.onload = function() {
    var drawingCanvas = document.getElementById('myDrawing');
 
    // Check the element is in the DOM and the browser supports canvas
    if(drawingCanvas && drawingCanvas.getContext) {
        // Initaliase a 2-dimensional drawing context
        var context = drawingCanvas.getContext('2d');
 
        // Create the yellow face
        context.strokeStyle = "#000000";
        context.fillStyle = "#FFFF00";
        context.beginPath();
        context.arc(100,100,50,0,Math.PI*2,true);
        context.closePath();
        context.stroke();
        context.fill();
 
        // Add 2 green eyes
        context.strokeStyle = "#000000";
        context.fillStyle = "#FFFFFF";
        context.beginPath();
        context.arc(80,80,8,0,Math.PI*2,true);
        context.closePath();
        context.stroke();
        context.fill();
 
        context.fillStyle = "#009966";
        context.beginPath();
        context.arc(80,80,5,0,Math.PI*2,true);
        context.closePath();
        context.fill();
 
        context.strokeStyle = "#000000";
        context.fillStyle = "#FFFFFF";
        context.beginPath();
        context.arc(120,80,8,0,Math.PI*2,true);
        context.closePath();
        context.stroke();
        context.fill();
 
        context.fillStyle = "#009966";
        context.beginPath();
        context.arc(120,80,5,0,Math.PI*2,true);
        context.closePath();
        context.fill();
 
        // Create the diamond-shaped nose
        context.fillStyle = "#000000";
        context.beginPath();
        context.moveTo(93,100);
        context.lineTo(100,93);
        context.lineTo(107,100);
        context.lineTo(100,107);
        context.closePath();
        context.fill();
 
        // Add the smile
        context.strokeStyle = "#000000";
        context.beginPath();
        context.moveTo(70,110);
        context.quadraticCurveTo(100,150,130,110);
        context.quadraticCurveTo(100,150,70,110);
        context.closePath();
        context.stroke();
    }
}


Y por ultimo el HTML

<canvas height="200" width="200" id="myDrawing">
            <p>Your browser doesn't support canvas.</p>
        </canvas>


Pruebenlo y fijense lo q sale con solo este codigo y sin usar ninguna imagen...

Saludos

Datos archivados del Taringa! original
0puntos
294visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
0visitas
0comentarios
Dar puntos:

Dejá tu comentario

0/2000

No hay comentarios nuevos todavía

Autor del Post

M
MaxElCalamar🇦🇷
Usuario
Puntos0
Posts10
Ver perfil →
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.