Hacker News new | comments | show | ask | jobs | submit login

You can try it out yourself in your browser. This scriptlet generates random and non-random dot distributions side by side (refreshing regenerates, at least in Firefox 17):

javascript:"<html><body><canvas id=\"tutorial\" width=\"200\" height=\"200\">foo</canvas><-><canvas id=\"tutorial2\" width=\"200\" height=\"200\">foo</canvas><script>var canvas = document.getElementById('tutorial');var ctx = canvas.getContext('2d');ctx.fillStyle = \"rgb(000,0,0)\";for (var i=0;i<400;i++) {ctx.fillRect (Math.random() * 200,Math.random() * 200, 2, 2); };</script><script>var canvas = document.getElementById('tutorial2');var ctx = canvas.getContext('2d');ctx.fillStyle = \"rgb(000,0,0)\";for (var i=0;i<20;i++) for(var j=0;j<20;j++) for(k=0;k<1;k++) {ctx.fillRect (i * 10 + Math.random() * 10, j * 10 + Math.random() * 10, 2, 2); };</script></body></html>"

(just paste the above into the address bar)




Here’s a web page displaying those dot distributions plus a more readable version of that code: http://bl.ocks.org/4358325.


Thanks, this looks much better. My code was like this because I used a pasted canvas tutorial example + my browser's URL bar as the IDE :)




Applications are open for YC Winter 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: