Javascript no shapes appear -


i'm trying make rectangle nothing appear, background. i've tried ctx.fill, ctx.fillstyle etc. nothing works:

i'm refering part

fill(77, 66, 66); rect(10,200,100,100); 

here whole code page

 var ctx, w, h;     window.onload = function() {     var canvas = document.getelementbyid("canvas");   w = window.innerwidth;   h = window.innerheight;    canvas.width = w;   canvas.height = h;     ctx = canvas.getcontext("2d");     setinterval(draw, 1);   function draw() {   ctx.globalcompositeoperation = "source-over";   ctx.fillstyle = "#e6e6ff"; // part appear   ctx.fillrect(0, 0, w, h);    fill(77, 66, 66); // doesn't appear   rect(10,200,100,100);  }   } 

thanks

you need call fill , rect on canvas context. need change fillstyle otherwise you're drawing rectangle same color background , won't show.

var ctx, w, h;        window.onload = function() {        var canvas = document.getelementbyid("canvas");    w = window.innerwidth;    h = window.innerheight;      canvas.width = w;    canvas.height = h;        ctx = canvas.getcontext("2d");        settimeout(draw, 1);        function draw() {      ctx.globalcompositeoperation = "source-over";      ctx.fillstyle = "#e6e6ff";      ctx.fillrect(0, 0, w, h);        ctx.fillstyle = "red"; // need otherwise rect same color background      ctx.rect(10, 200, 100, 100); // needs called on canvas context      ctx.fill(); // needs called on canvas context, fill path not filled in.    }      }


Comments