jeudi 7 avril 2016

Changing color randomly Javascript

Heys guys,

I am testing some stuff out with the native accelometer on my android phone, I want to draw rectangles, which works but I want them to be a different color everytime one is drawn.

Thank you in advance :)

    function onSuccess(acceleration) {

var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.width = window.innerWidth;
context.height = window.innerHeight;

    context.save(); 
    context.beginPath();
    context.rect(acceleration.x*10+150, acceleration.y*10+100, acceleration.z*10, acceleration.y*10);
    context.fillStyle = '#FF0000';
    context.fill();
    context.lineWidth = 3;
    context.strokeStyle = 'black';
    context.stroke();
    context.restore(); 

}

function onError() {
    alert('onError!');
}




Aucun commentaire:

Enregistrer un commentaire