Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The canvas is just 80x80 pixels. Your CSS is scaling it up to 640x480, meaning you just stretch the bitmap you're drawing to the canvas. (this explains your blurriness)</p> <p>The trick to achieving your scaling is here : </p> <pre><code>var scaleFactor = 10; for(i = 0; i &lt; 6400; i++) { d = random()*256|0; val = array[d]; viewbmd.fillStyle = "rgb(" + val + ", " + val + ", " + val + ")"; //fillrect draws your "pixels", viewbmd.fillRect(i%80*scaleFactor, (((i)/80)|0)*scaleFactor , scaleFactor, scaleFactor); } </code></pre> <p>In order to emulate drawing bix pixels, you multiply the x/y position of the rectangles you draw with the same number that determines their size (see scaleFactor).</p> <p>In the example, i'm drawing "pixels" that are actually 10x10 "points".</p> <p>This way, the initial picture is drawn correctly.</p> <p>We run into trouble though, the second we hit <code>flipSomePixels</code>, because it just takes actual pixels from the bitmap we drew earlier, and starts flipping those, so we will need a similar trick to draw the updated fake pixel there.</p> <p><strong>::update::</strong></p> <p>Thanks to Ken, i got an idea on how to achieve this in an "easier" way. We can draw the original 80x80 canvas off screen, and stretch that across a bigger canvas.</p> <p>We still need to do away with the css canvas resizing though, because resizing the canvas element will still cause the blurry scaling to happen. Instead, we make the canvas 640x640 and tell it to do crisp image rendering like this:</p> <p>-css:</p> <pre><code>canvas{ border:1px solid black; image-rendering: optimizeSpeed; image-rendering: -moz-crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: -o-crisp-edges; image-rendering: optimize-contrast; -ms-interpolation-mode: nearest-neighbor; } </code></pre> <p>-html:</p> <pre><code>&lt;canvas width="640" height="640"&gt;&lt;/canvas&gt; </code></pre> <p>For a working example, see <a href="http://jsfiddle.net/QTvpe/10/" rel="nofollow">http://jsfiddle.net/QTvpe/10/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload