title: Getting pixel values of images in p5js
body: <p>I have been working on some code that is supposed to draw a dot(ellipse) on each pixel that is black. I am new to the get function, and suspect that I might have made a mistake using it. Does anyone know why my code cannot successfully "dot" the map of India?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function setup() {
    createCanvas(400, 400);
  }
                    
  window.onload = function() {
    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    var img = document.getElementById("map");
    ctx.drawImage(img, 10, 10, 150000, 1800000);
  }
  
  function draw() {
    for (var x = 0; x &lt; 100; x++){
      for (var y = 0; y &lt; 100; y++){
        if(black(get(x,y))==255){
          ellipse(x , y, 10, 100); 
        }
      }
    }
  }
      </code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>&lt;style&gt;
  
    p {
      position:absolute;
      z-index:3;
    }
  
    img {
      position:absolute;
      z-index: -1;
    }
  &lt;/style&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  
    &lt;!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) --&gt;
    &lt;script language="javascript" type="text/javascript" src="libraries/p5.min.js"&gt;&lt;/script&gt;
    &lt;script language="javascript" type="text/javascript" src="p5js-temp-sadfsfdsad8981306098870070843.js"&gt;&lt;/script&gt;
    &lt;!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN --&gt;
  
    &lt;!-- This line removes any default padding and style.
         You might only need one of these values set. --&gt;
    &lt;style&gt; body { padding: 0; margin: 0; } &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;img id="map" width="220" height="277" src="https://geology.com/world/india-map.gif" alt="The map"&gt;
    &lt;!--&lt;img src="https://geology.com/world/india-map.gif"&gt;--&gt;
    &lt;p id="area"&gt;&lt;/p&gt; &lt;br&gt;
    &lt;p id="perimeter"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Edit: I changed the code to </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  window.onload = function() {
    var c = canvas;
    var ctx = c.getContext("2d");
    var img = document.getElementById("map");
    ctx.drawImage(img, 10, 10, 150000, 1800000);
  }
  
                    
  
  function draw() {
  
  
  for (var x = 0; x &lt; 100; x++){
    for (var y = 0; y &lt; 100; y++){
    if(black(get(x,y))==255){
     ellipse(x , y, 10, 100);
    
  }
  }
  }
    
  
      }
      </code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>&lt;style&gt; body { padding: 0; margin: 0; } &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;img id="map" width="220" height="277" src="https://geology.com/world/india-map.gif" alt="The map"&gt;
  &lt;!--&lt;img src="https://geology.com/world/india-map.gif"&gt;--&gt;
  &lt;p id="area"&gt;&lt;/p&gt; &lt;br&gt;
  &lt;p id="perimeter"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;style&gt;
  
  p{
  position:absolute;
  z-index:3;
  
  }
  img{
   position:absolute;
   z-index: -1;
    
  }
  &lt;/style&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  
  
    &lt;script language="javascript" type="text/javascript" src="libraries/p5.min.js"&gt;&lt;/script&gt;
    &lt;script language="javascript" type="text/javascript" src="p5js-temp-sadfsfdsad1466343293693433275.js"&gt;&lt;/script&gt;
  
  
    &lt;!-- This line removes any default padding and style.
         You might only need one of these values set. --&gt;
    </code></pre>
  </div>
  </div>
  </p>
  
  <p>However, I get a black rectangle on the map and no dots. Does anyone know why this is happening?</p>