Asteroida (2)
Listing
var cv = document.getElementById('canvas'); var ctx = cv.getContext('2d'); var w = cv.width; var h = cv.height; var index = function(row, col, cols) { return row * cols + col; }; var asteroida2 = function(r, liczbaPunktow) { var x2; var y2; var img1 = ctx.getImageData(0, 0, w, h); var idata = img1.data; for ( var i = 0; i < liczbaPunktow; i++) { var t = i * Math.PI / 360.0; x2 = r * Math.pow(Math.cos(t), 3) + w / 2; y2 = r * Math.pow(Math.sin(t), 3) + h / 2; var j = 4 * index(Math.floor(x2), Math.floor(y2), w); idata[j] = 0; idata[j + 1] = 0; idata[j + 2] = 255; idata[j + 3] = 255; } ctx.putImageData(img1, 0, 0); }; asteroida2(150, 1000);