// Canvas: 500x500 // Global variable: 'global' var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); /// Clear Screen context.fillStyle = "rgb(255,255,255)"; context.rect(0,0,500,500); context.fill(); /// Sample functions function setPixel(context, x,y, r,g,b){ var imgData = context.createImageData(1,1); imgData.data[0]=r; imgData.data[1]=g; imgData.data[2]=b; imgData.data[3]=255; context.putImageData(imgData,x,y); } function line(context, x,y, toX,toY, r,g,b){ context.strokeStyle = "rgb("+r+","+g+","+b+")"; context.beginPath(); context.moveTo(x,y); context.lineTo(toX,toY); context.stroke(); } /// More code...
Execute
Executing...
Error
Generate link (DEPRECATED)
Templates