<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with get() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=get%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:14:03 +0000</pubDate>
         <description>Tagged with get() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedget%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How can I clone an image object?</title>
      <link>https://forum.processing.org/two/discussion/18109/how-can-i-clone-an-image-object</link>
      <pubDate>Thu, 08 Sep 2016 06:02:29 +0000</pubDate>
      <dc:creator>thinsoldier</dc:creator>
      <guid isPermaLink="false">18109@/two/discussions</guid>
      <description><![CDATA[<p>I want to load an image and draw it once with a mask and again without the mask.</p>

<p>I though I could load it then duplicate it as img2 and only apply the mask to the first img object.</p>

<p>Is that possible or is there a different way to do it?</p>

<pre><code>function preload() {
  img = loadImage("assets/moonwalk.jpg");
  imgMask = loadImage("assets/mask.png");
  img2 = ? ? ? ? ? ?; // how do i clone the first img?
}

function setup() {
  createCanvas(720, 400);
  img.mask(imgMask);
  imageMode(CENTER);
}

function draw() {
  background(250, 255, 3);
  image(img2, width/2, height/2);
  image(img, mouseX, mouseY);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to save image after edits</title>
      <link>https://forum.processing.org/two/discussion/25909/how-to-save-image-after-edits</link>
      <pubDate>Thu, 11 Jan 2018 04:28:50 +0000</pubDate>
      <dc:creator>Fangry</dc:creator>
      <guid isPermaLink="false">25909@/two/discussions</guid>
      <description><![CDATA[<p>Hello, forum
So I am doing this image processing application, but I haven't found a way to 'undo' changes or to save changes. 
I get how changing the brightness or the RBG values changes the image.</p>

<pre><code>loadPixels();
      for (int y = 0; y &lt;pic.height; y++) {
        for (int x = 0; x &lt;pic.width; x ++) {
          int index = x + height*y;
          float r = red(pic.pixels[index]);
          float g = green(pic.pixels[index]);
          float b = blue(pic.pixels[index]);
          pixels[index] = color(r, g, b);
        }
      }
      updatePixels();
</code></pre>

<p>saveFrame() saves the entire screen, including my user interface. And that's not what I want. I only want the image portion to be saved.</p>

<p>I think PImage.save is the way to go. But I don't know how to save changes to an image object and then it can save.</p>

<p>How do you save store changes so you can go back if you make a mistake?</p>

<p>My code can be found on my Github <a href="https://github.com/Finaros/Pixcell" target="_blank" rel="nofollow">https://github.com/Finaros/Pixcell</a>
Thank you very much!</p>
]]></description>
   </item>
   <item>
      <title>How could do what a capture from webcam show croped (no resize)</title>
      <link>https://forum.processing.org/two/discussion/25055/how-could-do-what-a-capture-from-webcam-show-croped-no-resize</link>
      <pubDate>Thu, 16 Nov 2017 23:27:45 +0000</pubDate>
      <dc:creator>guspelina</dc:creator>
      <guid isPermaLink="false">25055@/two/discussions</guid>
      <description><![CDATA[<p>How could do what a capture from webcam show croped in a square image like example 192x256 (or 400x400)? Not resize, crop.</p>

<pre><code>import processing.video.*;
    Capture cam;    
    PImage uno;
    PImage dos;
    PImage img;
    PImage circulo;
    final int anchoCam = 1024;
    final int altoCam = 768;
    final int anchoLienzo = 1024;
    final int altoLienzo = 768;
    final int anchoImagen = anchoLienzo/2;
    final int altoImagen =altoLienzo/2;
    final int anchoDelta = (anchoCam-anchoImagen)/2;
    final int altoDelta = (altoCam-altoImagen)/2;
    void setup() {

          size (anchoLienzo, altoLienzo);
          cam = new Capture(this, anchoCam, altoCam, 30);

          cam.crop(anchoDelta, altoDelta, anchoImagen, altoImagen);

          cam.read();
          uno = cam.get();


          circulo = loadImage("circulo.jpg");
          res = 0.0;
        }

PImage updateImg(Capture cam, PImage lado) {
  cam.read();
  lado = cam.get();

     if ( img = loadImage(int(random(26, 50)) + ".jpg"));     //y aquí el 26 y el 50
 {
  lado.blend(img, 0, 0, anchoImagen, altoImagen, 0, 0, anchoImagen, altoImagen, SCREEN);
  lado.blend(circulo, 0, 0, anchoImagen, altoImagen, 0, 0, anchoImagen, altoImagen, MULTIPLY); //Se puede cambiar el modo de fusión de las fotos cambiando MULTIPLY por otro, como BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE o BURN.
  lado.filter(GRAY);
  return lado;}
}

void draw() {

  background (0);
  if (keyPressed) {

   if (key == 'a' || key == 'A') {

     uno = updateImg(cam, uno);
}

    else if (keyCode == DOWN) {

    }
  }
  image(uno, 300, 0, anchoImagen, altoImagen);
 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why is it doing that ??? Saving live capture instead of the content of a capture object</title>
      <link>https://forum.processing.org/two/discussion/22237/why-is-it-doing-that-saving-live-capture-instead-of-the-content-of-a-capture-object</link>
      <pubDate>Thu, 27 Apr 2017 08:31:51 +0000</pubDate>
      <dc:creator>Mat007</dc:creator>
      <guid isPermaLink="false">22237@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I am trying to record incoming data from a serial port as well as capturing video. Because of the speed (data is coming every millisecond) I had to trigger the video capture inside the serialEvent (built-in camera works at 30 fps max). I decided to capture a snapshot every 50ms. It takes too long to save the snapshot so I had to buffer it in an arrayList. I did the same with the serial data.
Acquisition is triggered and stopped using keyPressed. Once it is finished, I come back to my arrayLists and save the pictures one by one (including the serial data in the name, it is just a short string).
Here is the trouble: instead of reading the content of the Capture arrayList it reads whatever is coming from the camera.</p>

<p>I tried without success:
-myPort.stop()
-myVideo.stop()
-noLoop()
-using a PImage arrayList instead of Capture object arrayList
-use different ways to trigger/stop acquisition.</p>

<p>It doesn't make any sense to me... why when I write mySnapshotAL.get(i) do I get the current camera view and not the content of the arrayList which is populated properly (I checked the size) ???</p>

<p>Many thanks!!!</p>

<pre><code>import processing.video.*;
import processing.serial.*;

Capture myVideo;                     // declaring a Capture object
Serial myPort;                       // declaring a  serial port
ArrayList&lt;String&gt; myDataAL;          // declaring an ArrayList of String (serial data)
ArrayList&lt;Capture&gt; mySnapshotAL;     // declaring an ArrayList of Capture objects
String myFileName;
String myDataString;
String myDate;
int startTime;
String myTime;
int i=0;
boolean saving=false;

void setup() {  
  frameRate(1000);
  size(1000, 700);
  background(0);
  mySnapshotAL= new ArrayList&lt;Capture&gt;();            // initialising the ArrayList of Capture objets
  myDataAL= new ArrayList&lt;String&gt;();                 // initialising the ArrayList of String
  myVideo = new Capture(this, 320, 240,30);          // initialising the Capture object
  myVideo.start();
  myPort = new Serial(this, Serial.list()[1], 9600); // initialising the port dev/cu.usbmodem1411
  myPort.bufferUntil(10); // char(10) = line feed
}

void serialEvent(Serial myPort) {   // myPort receives data every ms
  i++; 
    if (i==50){
      myVideo.read(); // only acquire every 50 ms
      i=0;
    } 
  myDataString = trim(myPort.readString());
  myTime=nf(millis()-startTime,6,1).substring(0,5);
  myDataString=myTime + "," + myDataString;
  if (saving){
  mySnapshotAL.add(myVideo);
  myDataAL.add(myDataString);
  }
}

void draw() {  
image(myVideo, 600, 40);
}

void keyPressed(){
        if (!saving) {
          saving=true;
          startTime=millis();
          }
        else {
          saving=false;
          myDate= nf(hour(),2,1).substring(0,2) + "h" + nf(minute(),2,1).substring(0,2);
          for (int i =0; i&lt;mySnapshotAL.size(); i++){
              myFileName="VideoFiles/Capture" + i + "@" +myDate+ "-" +myDataAL.get(i)+".png";
              mySnapshotAL.get(i).save(myFileName); 
              if (i==300) break;  // safety, until code is failproof
          }
        }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>image a P3D PGraphics buffer in/over a 2D "main window"</title>
      <link>https://forum.processing.org/two/discussion/22238/image-a-p3d-pgraphics-buffer-in-over-a-2d-main-window</link>
      <pubDate>Thu, 27 Apr 2017 09:53:07 +0000</pubDate>
      <dc:creator>mala</dc:creator>
      <guid isPermaLink="false">22238@/two/discussions</guid>
      <description><![CDATA[<p>This is driving me slightly mad... I have so far tried using a second applet to achieve the same but the results aren't great, as the second window has a border, can be dragged about etc. Whilst I would prefer the 3D "view" to just look like part of the rest of my 2D GUI.</p>

<p>I'm now trying to use a P3D offscreen buffer and then using image(), draw that to the 2D sketch... but I'm stuck with an error asking for size(). But I have no idea where/how I should be supplying this size() value, if I put it in settings() it applies to the main 2D sketch which I don't want.
Can anyone help please?!</p>

<p>simple version code :</p>

<pre><code>    PGraphics p3d;

    DBox myBox;
    void settings() {
      //size(400,400,P3D);
    }

    void setup() {
      size(800, 800);

      p3d = createGraphics(400, 400, P3D);
      p3d.beginDraw();
      p3d.noStroke();
      myBox = new DBox();
      p3d.background(128);
      myBox.render(this.g);
      p3d.endDraw();
    }

    void draw() {
      background(100);
      fill(255, 0, 0);
      ellipse(400, 400, 650, 650);
      image(p3d, 200, 200);
    }

    class DBox {

      DBox() {
      }

      void render(PGraphics pg) {
        pg.fill(0, 0, 255);
        pg.box(40);
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>What bracket is missing on the 6th line!?! (else if (keyCode == DOWN)</title>
      <link>https://forum.processing.org/two/discussion/21643/what-bracket-is-missing-on-the-6th-line-else-if-keycode-down</link>
      <pubDate>Mon, 27 Mar 2017 21:07:56 +0000</pubDate>
      <dc:creator>Nathan101</dc:creator>
      <guid isPermaLink="false">21643@/two/discussions</guid>
      <description><![CDATA[<pre><code>    if ( key == CODED) {

        if (keyCode == UP &amp;&amp; linkY-20 &gt; 0 &amp;&amp; (map.get((int)linkX, (int)linkY-20)== -339816 || map.get((int)linkX, (int)linkY-20)== -340072 || map.get((int)linkX, (int)linkY-20)== -206680 || map.get((int)linkX, (int)linkY-20)== -9145228 || map.get((int)linkX, (int)linkY-20)== -3650548 || map.get((int)linkX, (int)linkY-20)== -16777216 || map.get((int)linkX, (int)linkY-20)== -197380))
          linkY-=5;
          linkImg = linkUp;
        else if (keyCode == DOWN &amp;&amp; linkY+20 &lt; height &amp;&amp; (map.get((int)linkX, (int)linkY+20)== -339816 || map.get((int)linkX, (int)linkY+20)== -340072 || map.get((int)linkX, (int)linkY+20)== -206680 || map.get((int)linkX, (int)linkY+20)== -9145228 || map.get((int)linkX, (int)linkY+20)== -3650548 || map.get((int)linkX, (int)linkY+20)== -16777216 || map.get((int)linkX, (int)linkY+20)== -197380))
          linkY+=5;
          linkImg = linkDown;
        else if (keyCode == LEFT &amp;&amp; linkX-20 &gt; 0 &amp;&amp; (map.get((int)linkX-20, (int)linkY)== -339816 || map.get((int)linkX-20, (int)linkY)== -340072 || map.get((int)linkX-20, (int)linkY)== -206680 || map.get((int)linkX-20, (int)linkY)== -9145228 || map.get((int)linkX-20, (int)linkY)== -3650548 || map.get((int)linkX-20, (int)linkY)== -16777216 || map.get((int)linkX-20, (int)linkY)== -197380))
          linkX-=5;
          linkImg = linkLeft;
        else if (keyCode == RIGHT &amp;&amp; linkX+20 &lt; width &amp;&amp; (map.get((int)linkX+20, (int)linkY)== -339816 || map.get((int)linkX+20, (int)linkY)== -340072 || map.get((int)linkX+20, (int)linkY)== -206680 || map.get((int)linkX+20, (int)linkY)== -9145228 || map.get((int)linkX+20, (int)linkY)== -3650548 || map.get((int)linkX+20, (int)linkY)== -16777216 || map.get((int)linkX+20, (int)linkY)== -197380))
          linkX+=5;
          linkImg = linkRight;
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Use floats with get()</title>
      <link>https://forum.processing.org/two/discussion/21025/use-floats-with-get</link>
      <pubDate>Mon, 27 Feb 2017 01:23:41 +0000</pubDate>
      <dc:creator>Uranhjorten</dc:creator>
      <guid isPermaLink="false">21025@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>I am trying to make a light field renderer based on this Nvidia research <a href="https://research.nvidia.com/sites/default/files/publications/Slim%20near-eye%20display%20using%20pinhole%20aperture%20arrays.pdf" target="_blank" rel="nofollow">https://research.nvidia.com/sites/default/files/publications/Slim near-eye display using pinhole aperture arrays.pdf</a></p>

<p>Long story short - "int o = 1;" needs to be 0.75 but get() doesn't support floats.. any ideas?</p>

<p>This is my code so far:</p>

<pre><code>int N = height/3;
int o = 1;
void setup() {
  size(400, 300);
}
void draw() {
  PImage myImage = loadImage("fox.jpg");
  image(myImage, 0, 0);
  for (int i = 0; i &lt; myImage.width; i = i+1) {
    for (int j = 0; j &lt; myImage.height; j = j+1) {
      PImage c = get(i*N*o, j*N*o, N, N);
      tint(0, 200, 255); //just for checking it works
      image(c, i*N*o, j*N*o);
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why is this sketch so slow? Get() makes it slow</title>
      <link>https://forum.processing.org/two/discussion/20583/why-is-this-sketch-so-slow-get-makes-it-slow</link>
      <pubDate>Tue, 31 Jan 2017 20:59:49 +0000</pubDate>
      <dc:creator>manu123</dc:creator>
      <guid isPermaLink="false">20583@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>Can anyone tell me why this sketch runs so slow?
The line with the "Get()" is the problem...</p>

<p>I tried different renderer (P2D, P3D...) but without success..</p>

<pre><code>float  Angle = 0;

void setup() 
{
  size(600, 600,P3D ); 
  noSmooth();
}

void draw() {
  background(0);

  Angle += 0.8;

  // Draw something in the upper left corner (
  colorMode(HSB, 100);  
  pushMatrix();
  translate(7, 7);
  rotate(radians(Angle*34));
  Star5(0, 0, 9.5, 9.5, color(0, 100, 100), color(20, 100, 100), color(40, 100, 100), color(60, 100, 100), color(80, 100, 100), 100);
  popMatrix();


  colorMode(RGB, 255);
  noFill();

  // draw a rect (Pixel scan area)
  strokeWeight(1);
  stroke(255, 255);
  rect(-1, -1, 15, 15);



  int OffsetX = 50;
  int OffsetY = 50;
  int CellSize = 30;
  int GridWidth = 33;
  int CellRadius = 2;

  noStroke();

  // Scan Pixels in the upper left corner and draw matrix
  for (int yy = 0; yy &lt; 13; yy++)
  {
    for (int xx = 0; xx &lt; 13; xx++)
    {      
      color c = get(xx, yy); // THIS LINE MAKES THE WHOLE SKETCH VERY SLOW 
      //color c = color(xx*20,yy*20,0); // TO SEE THE DIFFERENCE... USE THIS LINE INSTEAD
      fill(c);
      rect(OffsetX + (xx * GridWidth), OffsetY + (yy * GridWidth),CellSize,CellSize,CellRadius);
    }
  } 
}


void Star5(float x1, float y1, float r1, float r2, color c1, color c2, color c3, color c4, color c5, int alpha) 
{
  // Draws a star
  noStroke();
  beginShape();
  fill(c1, alpha);
  vertex(x1+cos(radians(36*1))*r2, y1+sin(radians(36*1))*r2);
  vertex(x1+cos(radians(36*2))*r1, y1+sin(radians(36*2))*r1);
  fill(c2, alpha);
  vertex(x1+cos(radians(36*3))*r2, y1+sin(radians(36*3))*r2);
  vertex(x1+cos(radians(36*4))*r1, y1+sin(radians(36*4))*r1);
  fill(c3, alpha);
  vertex(x1+cos(radians(36*5))*r2, y1+sin(radians(36*5))*r2);
  vertex(x1+cos(radians(36*6))*r1, y1+sin(radians(36*6))*r1);
  fill(c4, alpha);
  vertex(x1+cos(radians(36*7))*r2, y1+sin(radians(36*7))*r2);
  vertex(x1+cos(radians(36*8))*r1, y1+sin(radians(36*8))*r1);
  fill(c5, alpha);
  vertex(x1+cos(radians(36*9))*r2, y1+sin(radians(36*9))*r2);
  vertex(x1+cos(radians(36*10))*r1, y1+sin(radians(36*10))*r1);
  endShape();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Performance of p5.js vs. Processing 3</title>
      <link>https://forum.processing.org/two/discussion/19720/performance-of-p5-js-vs-processing-3</link>
      <pubDate>Tue, 13 Dec 2016 14:32:25 +0000</pubDate>
      <dc:creator>omerpekin</dc:creator>
      <guid isPermaLink="false">19720@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>I am trying to switch to p5.js as much as I can, however I am fairly new at it.</p>

<p>The main problem I have is, when I do stuff with get() and double for loop, p5.js is incredibly slow.</p>

<p>When I run the following code with Processing (java mode) this runs pretty easy. When I do the same thing with p5.js, it is really really really slow.</p>

<pre><code>        var img;


        function setup() {
          createCanvas(480, 640);
          img = loadImage("assets/Image2.jpg");
        }

        function draw() {
          image(img, 0, 0);


          var stepSize = 10;

          for (var y = 0; y &lt; width; y+=stepSize) {
            for (var x = 0; x &lt; height; x+=stepSize) {
              var c = get(y, x);
              fill(c);
              noStroke();
              rect(y, x, 5, 5);
            }
          }
        }
</code></pre>

<p>So what is the problem here? What am I doing wrong with p5.js?? If I use the get() command outside of the for loops, it is fairly ok... If I change the stepSize from 10 to 1 then again, p5.js just freezes... Is this normal? Do I have to change something?</p>
]]></description>
   </item>
   <item>
      <title>How can I make copies of the canvas? Original + copy next to it, with same contents.</title>
      <link>https://forum.processing.org/two/discussion/19551/how-can-i-make-copies-of-the-canvas-original-copy-next-to-it-with-same-contents</link>
      <pubDate>Tue, 06 Dec 2016 08:11:18 +0000</pubDate>
      <dc:creator>kristianp89</dc:creator>
      <guid isPermaLink="false">19551@/two/discussions</guid>
      <description><![CDATA[<p>I have the following code in setup():</p>

<pre><code>originalCanvas = createCanvas(windowWidth/2, windowHeight);
originalCanvas.position(0, 0);
originalCanvas.background(0);

copiedCanvas = originalCanvas;
copiedCanvas.position(windowWidth/2, 0);
</code></pre>

<p>However, only the right half of the screen is black. The left part is white, which I find weird. If my approach didn't work, shouldn't at least the left part be black and the right part white?</p>

<p>When I put an ellipse with mouseX and mouseY in draw(), it only shows in the black/right canvas. The left canvas seems inactive.</p>

<p>I know about createGraphics, but then I would have to always draw things twice, right? For example "original.ellipse(...) and copy.ellipse(...)" - or am I missing something?</p>
]]></description>
   </item>
   <item>
      <title>Initializing arrays within a method</title>
      <link>https://forum.processing.org/two/discussion/19397/initializing-arrays-within-a-method</link>
      <pubDate>Tue, 29 Nov 2016 16:44:11 +0000</pubDate>
      <dc:creator>Mysterio1000</dc:creator>
      <guid isPermaLink="false">19397@/two/discussions</guid>
      <description><![CDATA[<p>I have this code:</p>

<pre><code>PImage[] lol;
PImage thing;

void setup() {
  size(500,300);

  thing = loadImage("c_0.png");
  loadImages(lol, 12);
}

void loadImages(PImage[] p1, int size) {
  p1 = new PImage[size];

  for(int i = 0; i &lt; size; i++) {
    p1[i] = thing;
  }
}

void draw() {
  image(lol[3], 30, 40);
}
</code></pre>

<p>However, this gives me a NullPointerException. Why? Can't I initialize the PImages inside a method?</p>

<p>Thank you for any help :)</p>
]]></description>
   </item>
   <item>
      <title>Get current canvas?</title>
      <link>https://forum.processing.org/two/discussion/19029/get-current-canvas</link>
      <pubDate>Mon, 14 Nov 2016 10:33:21 +0000</pubDate>
      <dc:creator>Aldun</dc:creator>
      <guid isPermaLink="false">19029@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>I'm trying to get the output of my canvas to perform blob detection on. How could I do this? I currently get the output of my cam, but I want to replace this with the output that is shown on the canvas (as I have performed some pixel editting on it)</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>non destructive resize of larger image</title>
      <link>https://forum.processing.org/two/discussion/18347/non-destructive-resize-of-larger-image</link>
      <pubDate>Thu, 29 Sep 2016 21:11:45 +0000</pubDate>
      <dc:creator>jeffmarc</dc:creator>
      <guid isPermaLink="false">18347@/two/discussions</guid>
      <description><![CDATA[<p>I used resize to scale a 1000x1000 image to 500x500
But then the original 1000x1000 image is gone.
I have to reload it each time, do my thresholding and then scale it down for display each time.</p>

<p>Is there a way to keep the original image after thresholding each time and display the scaled version without 
having to reload the original each time?</p>

<p>A non destructive resizing to a new smaller image without using brute force loops to create the new scaled image with a new name?
if i do a img.resize the original img is gone.</p>
]]></description>
   </item>
   <item>
      <title>Found BUG with get() and red() / blue() / green()</title>
      <link>https://forum.processing.org/two/discussion/18138/found-bug-with-get-and-red-blue-green</link>
      <pubDate>Sun, 11 Sep 2016 12:17:07 +0000</pubDate>
      <dc:creator>Sahibadul</dc:creator>
      <guid isPermaLink="false">18138@/two/discussions</guid>
      <description><![CDATA[<p>Hello</p>

<p>I recently discovered a bug with get() and the functions red green and blue. When I was looking in to why my program wasn't working, I found out that on the api the function get returns a int (or PImage but doesn't matter here). While the functions red green and blue return a float. This is I think my program isn't working.</p>

<p>Could somebody please look into this.</p>

<p>I posted the code below:</p>

<p>PImage pic;</p>

<p>color c1, c2, c3;</p>

<p>int r1, r2, r3;
int g1, g2, g3;
int b1, b2, b3;</p>

<p>float alternation=2;</p>

<p>void setup() {
  size(500, 500);
  pic=loadImage("meme.jpg");
  pic.resize(500, 500);
  image(pic, 0, 0);
  pic.loadPixels();
}</p>

<p>void draw() {
  for (int i=0; i&lt;width-1; i++) {
    for (int j=0; j&lt;height-1; j++) {</p>

<pre><code>  c1=pic.get(i, j);
  r1=red(c1);
  g1=green(c1);
  b1=blue(c1);

  c2=pic.get(i+1, j);
  r2=red(c2);
  g2=green(c2);
  b2=blue(c2);

  c3=pic.get(i, j+1);
  r3=red(c3);
  g3=green(c3);
  b3=blue(c3);

  if ((sqrt(sq(r1-r2)+sq(g1-g2)+sq(b1-b2)))&gt;=alternation 
    || (sqrt(sq(r1-r2)+sq(g1-g2)+sq(b1-b2)))&gt;=alternation) {
    set(i, j, 255);
    println("#000000");
  } else {
    set(i, j, 0);
    println("#FFFFFF");
  }
}
</code></pre>

<p>}
}</p>
]]></description>
   </item>
   <item>
      <title>resize</title>
      <link>https://forum.processing.org/two/discussion/18036/resize</link>
      <pubDate>Thu, 01 Sep 2016 18:03:11 +0000</pubDate>
      <dc:creator>jeffmarc</dc:creator>
      <guid isPermaLink="false">18036@/two/discussions</guid>
      <description><![CDATA[<p>If I use resize on a loaded image, does it change the resize the actual image in memory?</p>

<pre><code>memimg = loadImage("c:dirtscan.png"); 
memimg.resize(480,480);              // scale to fit screen 480x480
sclimg=memimg;
image(sclimg,imgstartcol,imgstartrow);
</code></pre>

<p>So now memimage.height and memimage.width =480?</p>

<p>If I want to get back to the full scale raw image in memory to execute image processing on 
I have to reload the image each time after i resize it?</p>

<p>Is that correct?</p>
]]></description>
   </item>
   <item>
      <title>Turning canvas pixels into an image variable</title>
      <link>https://forum.processing.org/two/discussion/17937/turning-canvas-pixels-into-an-image-variable</link>
      <pubDate>Mon, 22 Aug 2016 09:19:47 +0000</pubDate>
      <dc:creator>wah</dc:creator>
      <guid isPermaLink="false">17937@/two/discussions</guid>
      <description><![CDATA[<p>Hey all - newbie question here. I have tried to figure this out for a while so hopefully someone can see the error of my ways!</p>

<p>I want to take the current canvas output and turn it into an image object so I can pass that into another image processing function that requires an image (rather than raw pixels).</p>

<p>I see can save a canvas as an image file, but thats not what I need.</p>

<p>Many thanks</p>
]]></description>
   </item>
   <item>
      <title>Basic Question: Detecting Black Pixels in a Picture.</title>
      <link>https://forum.processing.org/two/discussion/17920/basic-question-detecting-black-pixels-in-a-picture</link>
      <pubDate>Sun, 21 Aug 2016 07:33:44 +0000</pubDate>
      <dc:creator>PixelMx</dc:creator>
      <guid isPermaLink="false">17920@/two/discussions</guid>
      <description><![CDATA[<p>Hello.
I'm new to processing and I decided to start with a simple script: something that allows me to identify black pixels in a picture. I have the code included below and as a checker I included the print command, just to see if the coordinates were moving forward (for loops).</p>

<p>Nothing is printing in my console and nothing is showing in my sketch, what am I doing wrong?
Thanks in advance</p>

<pre><code>void setup(){
  PImage myImage = loadImage("test.jpg");
  loadPixels();
  size(myImage.width,myImage.height);

}

void draw(){
  for (int i = 0; i &lt; width; i++) {
    for (int j = 0; j &lt; height; i++){
      color c = get(i,j);
      if (c == color(0)){
        point(i,j);
        print(i+","+j);
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>get() and copy() don't work in WEBGL mode?</title>
      <link>https://forum.processing.org/two/discussion/17531/get-and-copy-don-t-work-in-webgl-mode</link>
      <pubDate>Thu, 14 Jul 2016 19:13:37 +0000</pubDate>
      <dc:creator>Xeronimo74</dc:creator>
      <guid isPermaLink="false">17531@/two/discussions</guid>
      <description><![CDATA[<p>in Processing I would use something like</p>

<p>PImage img = get();</p>

<p>to get a snapshot of the current look of the screen but 'var img = get()' does not seem to work with p5js &amp; WEBGL?</p>

<p>Nor does:
var img;
img = createGraphics(100,100);
img = get();</p>

<p>so if this can be done: how?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Saving sketch with a transparent background</title>
      <link>https://forum.processing.org/two/discussion/12036/saving-sketch-with-a-transparent-background</link>
      <pubDate>Tue, 11 Aug 2015 18:49:04 +0000</pubDate>
      <dc:creator>dyk2111</dc:creator>
      <guid isPermaLink="false">12036@/two/discussions</guid>
      <description><![CDATA[<p>Hey,</p>

<p>I'm looking for some help with a simple way of saving the frame of a sketch as a png with no background, other than the drawn lines from the script. The sketch essentially reproduces a given image through a series of generated traceur lines, I've included the sketch for reference and it's something I found so I don't fully understand how it works. I'm new to processing so I apologize if this is really basic or if I'm missing something but after looking around, it seems surprisingly more complicated than I initially thought to render with no background. I'm using the latest version of processing 3 by the way.</p>

<pre><code>PGraphics alphaG;

PImage g;
traceur[] traceurs;

void setup(){
size(2500,800);


   alphaG = createGraphics(width,height, JAVA2D);

  g = loadImage("climate.png");

  traceurs = new traceur[0];
  background(255);
  stroke(126,24,175,20);
  for(int a=0;a&lt;120;a++){
    traceurs = (traceur[]) append (traceurs, new traceur());
  }

}

void draw(){
  for(int a=0;a&lt;traceurs.length;a++){
   traceurs[a].dessine(); 
  } 

 image(alphaG, 0,0);
}

class traceur{
    float x,y,an,v;
    float[] rang={-0.05,0.05};
  traceur(){
    x= random(width);y=random(height);
    an=random(TWO_PI);v=random(1.2,1.5);
   rang[0]=random(-0.1,-0.05);
   rang[1]=random(0.05, 0.1);
  }
  void dessine(){
   an+=random(rang[0],rang[1]);
   float newx=x+cos(an)*v;
   float newy=y+sin(an)*v;
   if(newx&lt;0||newx&gt;width||newy&lt;0||newy&gt;height){
     newx=constrain(newx,0,width);
     newy=constrain(newy,0,height);
     an+=random(-PI,PI);
   rang[0]=random(-0.1,-0.05);
   rang[1]=random(0.05, 0.1);
   }
   if(random(100)&lt;1){ 
   rang[0]=random(-0.1,-0.05);
   rang[1]=random(0.05, 0.1);
   }
   float angleChoisi=an;

   float couleur=brightness(g.get(int(newx),int(newy)));
   for(float a=an-PI*0.3;a&lt;an+PI*0.3;a+=PI*0.15){
      int ixe=int(newx+cos(a)*v);
      int igr=int(newy+sin(a)*v);
      float col=brightness(g.get(ixe,igr));
      if(col&lt;couleur){
        couleur=col;
        angleChoisi=a;
      }
   } 
   an=angleChoisi;
   if(random(100)&lt;1){an=an+random(-1,1);}
   line(x,y,newx,newy);
   x=newx;y=newy;

}
  }


 void keyReleased(){
  saveFrame("img#####.png");
}
</code></pre>

<p>I found another code which I tried incorporating that is pretty helpful in rendering with no background, with some pretty clear instructions for beginners, it utilizes pgraphics to render, but since I don't fully understand how the initial code works, I've been having a hard time incorporating the various drawing steps. I've included the original file here for reference.</p>

<pre><code>PGraphics alphaG;

void setup() {
size(1250,800); 
// create an extra pgraphics object for rendering on a transparent background 
 alphaG = createGraphics(width,height, JAVA2D);

// background will be transparent in the png-file 
background(255);
}

void draw() {

  // draw into the pgraphics object
  alphaG.beginDraw();
    alphaG.fill(255,100);
    alphaG.rect(random(width), random(height), 30,30); 
  alphaG.endDraw();

  // draw the second renderer into the window, so we can see something 
  image(alphaG, 0,0);
}

void keyPressed() {
   alphaG.save("alphatest.png"); 
   println("alphatest.png saved.");
}
</code></pre>

<p>Anyways, I hope what I'm asking makes some sense, and I would really appreciate anyone's help on this, thanks.</p>

<p>Best,<br />
David</p>
]]></description>
   </item>
   <item>
      <title>Getting a single frame from the webcam instead of continuous stream + saving those frames in a list</title>
      <link>https://forum.processing.org/two/discussion/15965/getting-a-single-frame-from-the-webcam-instead-of-continuous-stream-saving-those-frames-in-a-list</link>
      <pubDate>Mon, 11 Apr 2016 15:17:46 +0000</pubDate>
      <dc:creator>Ders</dc:creator>
      <guid isPermaLink="false">15965@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to create a simple web application that a user can take a picture with using their webcam. At the moment I have everything figured out so that the webcam is constantly streaming the video to the canvas but I want it to save a "frame" to the app instead. Is this possible? If so, how do I do this? Also, I want to save these images in an array for now. I've tried using array.push() on the timing I want to take a picture (using mouseReleased) but that gives me an array of video streams from the webcam.</p>
]]></description>
   </item>
   <item>
      <title>what's the easiest/best way to turn a part of the screen into a PImage?</title>
      <link>https://forum.processing.org/two/discussion/15945/what-s-the-easiest-best-way-to-turn-a-part-of-the-screen-into-a-pimage</link>
      <pubDate>Sun, 10 Apr 2016 07:07:36 +0000</pubDate>
      <dc:creator>Xeronimo74</dc:creator>
      <guid isPermaLink="false">15945@/two/discussions</guid>
      <description><![CDATA[<p>reading all the pixel values one by one and putting them into the pixel array of the PImage?</p>

<p>it'd be nice if one could simply say something like clone(x,y,w,h,newImage);</p>
]]></description>
   </item>
   <item>
      <title>Trying to split video frames into RGB component images</title>
      <link>https://forum.processing.org/two/discussion/14598/trying-to-split-video-frames-into-rgb-component-images</link>
      <pubDate>Sun, 24 Jan 2016 06:28:29 +0000</pubDate>
      <dc:creator>LDB477</dc:creator>
      <guid isPermaLink="false">14598@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to take a video frame and break out the RGB component information into three separate images.  The problem I seem to be having is that when I load more than one set of pixel information, some strange things start to happen.  You can see in the code below that when I simply reference the information in the original capture it will actually seem to change that information.  I'm not quite getting the loadPixels and updatePixels functions it seems.  Here's a simplified version of my sketch using one of the video examples:</p>

<pre><code>import processing.video.*;

Capture cam;

PImage camR;
PImage camG;
PImage camB;

void setup() {
  size(640, 480);
  colorMode(RGB,255);
  frameRate(1);
  String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 640, 480);
  } if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i &lt; cameras.length; i++) {
      println(cameras[i]);
    }

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam = new Capture(this, cameras[0]);
    // Or, the settings can be defined based on the text in the list
    //cam = new Capture(this, 640, 480, "Built-in iSight", 30);

    // Start capturing the images from the camera
    cam.start();
  }
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  camR = cam;
  camG = cam;
  camB = cam;
  cam.loadPixels();
  camR.loadPixels();
  camG.loadPixels();
  camB.loadPixels();

  for (int i = 0; i &lt; cam.width*cam.height; i++){

    camR.pixels[i] = color(red(cam.pixels[i]));
    camG.pixels[i] = color(green(cam.pixels[i]));
    camB.pixels[i] = color(blue(cam.pixels[i]));
  }
  cam.updatePixels();
  camR.updatePixels();
  camG.updatePixels();
  camB.updatePixels();
  image(cam,0,0,200,150);
  image(camR,200,0,200,150);
  image(camG,200,150,200,150);
  image(camB,200,300,200,150);

}
</code></pre>

<p>I'm expecting to see the full RGB image when I run image(cam...), but I end up just getting the greyscale RED channel.  The "camG" and "camB" are also displaying the red channel.</p>
]]></description>
   </item>
   <item>
      <title>How To Make One Image out of Pixels from Another Image?</title>
      <link>https://forum.processing.org/two/discussion/13879/how-to-make-one-image-out-of-pixels-from-another-image</link>
      <pubDate>Thu, 10 Dec 2015 14:44:31 +0000</pubDate>
      <dc:creator>GoonyKnightMan</dc:creator>
      <guid isPermaLink="false">13879@/two/discussions</guid>
      <description><![CDATA[<p>I have a small game which consists of the player moving around the screen collecting items. I'm working on graphics for each of the 70 items (plus 5 for the terrain and player), and feel that loading 75 images in setup() would look very cluttered.</p>

<p>My goal is to put all of the images on the same png (they're 32x32, so it shouldn't be too large), and have a method that sets the item variable in each point of the map (each is an object that has data pertaining to it's location, whether or not the player or items are on that node, etc.) to a 32x32 square of pixels on the larger image containing all items. Is there a way to do this?</p>
]]></description>
   </item>
   <item>
      <title>render on window graphics in another</title>
      <link>https://forum.processing.org/two/discussion/13233/render-on-window-graphics-in-another</link>
      <pubDate>Sun, 25 Oct 2015 02:23:07 +0000</pubDate>
      <dc:creator>gperez</dc:creator>
      <guid isPermaLink="false">13233@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I'm working in a two windows project. First one renders the sketch, second one is intended to control the sketch (with buttons, etc). Btw, I'm working with Eclipse.</p>

<p>As main window will be projected in a wall, and I want to take ride of the mouse cursor, I wonder if there's a way to reproduce the first window content in a little area of the second window, and control mouse events from there. Event's handling would be quite simple, but I'm not sure on how to render content from one window to another.</p>
]]></description>
   </item>
   <item>
      <title>A question about looping through the pixels of an image</title>
      <link>https://forum.processing.org/two/discussion/13167/a-question-about-looping-through-the-pixels-of-an-image</link>
      <pubDate>Thu, 22 Oct 2015 06:27:45 +0000</pubDate>
      <dc:creator>outisfun</dc:creator>
      <guid isPermaLink="false">13167@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys,</p>

<p>I've been trying to solve this for days now, and it's not working. So I'm trying to translate a sketch from Processing to p5.js, and in the sketch, I need to loop through the pixels of an image. Here's the code:</p>

<p>&lt;</p>

<p>script&gt;
var img;</p>

<p>function preload() {
  img = loadImage("img/wa.jpg");
}
function setup() {
  createCanvas(1900, 700);
  imageMode();
  background(255);
  image(img,0,0);
  img.loadPixels();
}</p>

<p>function draw() {</p>

<p>stroke(255,0,0);
  /*
  for (var j=0; j&lt;img.height; j++){
    for (var i=0; i&lt;img.width; i++){
      var pixcol = img.get(i,j);
    }
  }*/
}
</p>

<p>The part that's commented out, the loop, is not working. The image size is 1600x800, so it is inside the canvas entirely. When I try to run the loop, the browser crashes. If I just ask img.get(x,y) for a particular pixel, let's say img.get(500,500), it works just fine. I can't possibly guess what's wrong, I'm new to p5, please help?</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>cam.get()</title>
      <link>https://forum.processing.org/two/discussion/12015/cam-get</link>
      <pubDate>Sun, 09 Aug 2015 05:01:39 +0000</pubDate>
      <dc:creator>joySeeing</dc:creator>
      <guid isPermaLink="false">12015@/two/discussions</guid>
      <description><![CDATA[<p>In Processing, I can get pixel data from an image or cam by calling the get method on the image or cam. However, this doesn't seem possible in the same way with P5js.  In the reference, <a href="http://p5js.org/reference/#/p5/get" target="_blank" rel="nofollow">http://p5js.org/reference/#/p5/get</a>, it seems that get doesn't work this way. It appears you can only get data from what the current canvas is showing as opposed to something that is not (such as an img or cam).</p>

<p>One solution may be to display the webcam feed (img or whatever) offscreen and use those offscreen pixel values to retrieve what you want. It seems kind of silly though. Am I missing something</p>
]]></description>
   </item>
   <item>
      <title>image.get() broken ?</title>
      <link>https://forum.processing.org/two/discussion/12351/image-get-broken</link>
      <pubDate>Tue, 01 Sep 2015 22:46:47 +0000</pubDate>
      <dc:creator>ukmikeb</dc:creator>
      <guid isPermaLink="false">12351@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,</p>

<p>I'm running p5.js: 
<a href="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.8/p5.min.js" target="_blank" rel="nofollow">https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.8/p5.min.js</a></p>

<p>Image.get now seems to be returning null color values?!</p>

<p>See Dan Shiffman's Pointilism example: <a href="http://p5js.org/examples/examples/Image_Pointillism.php" target="_blank" rel="nofollow">http://p5js.org/examples/examples/Image_Pointillism.php</a></p>

<p>Add println(pix); 
and you get [null,null,null,null]</p>

<p>Thanks</p>

<p>Mike</p>
]]></description>
   </item>
   <item>
      <title>set() function does not seem to work</title>
      <link>https://forum.processing.org/two/discussion/12314/set-function-does-not-seem-to-work</link>
      <pubDate>Mon, 31 Aug 2015 04:22:07 +0000</pubDate>
      <dc:creator>applepie</dc:creator>
      <guid isPermaLink="false">12314@/two/discussions</guid>
      <description><![CDATA[<p>Hello:</p>

<p>This is a beginning to a generative art program.  I plan to have it so that rows of pixels are moved left and right based upon their "color distances" from the averages of their top and bottom neighbor rows.  The part I am concentrating on is the moveRow function.  The programmer can provide it a row to move and how many pixels to move it to the left (negative numbers) or the right (positive numbers) as parameters.  Note that moved row wraps around the screen.  I try the program and nothing moves!  I think it may have to do with the background image "neon-smoke" not being updated somehow.  Note that the set() function is supposed to do that, in my opinion.  Threw in img.updatePixels() for good measure.</p>

<pre lang="processing">
PImage img;

void setup()
{
    size(500,500);
    img = loadImage("neon-smoke.jpg");
    img.resize(width,height);
    image(img,0,0);
}

void draw() {
  image(img,0,0);
  moveRow(10,1);
}

void moveRow(int row, int offset) {
   
   color[] c = new color[width];
   int targetPos = 0;
   for (int i = 0; i &lt; width; i++) {
     if ((i+offset) &gt; width)
       targetPos = (i+offset)-width;
     else if ((i+offset) &lt; 0)
       targetPos = width+offset+i;
     else
       targetPos = i+offset;
      c[i] = img.get(row,targetPos);
      //println(i,offset,i+offset,targetPos,img.get(row,targetPos),c[i]);
   }
   
   for (int i = 0; i &lt; width; i++)
     img.set(row,i,c[i]);
   img.updatePixels();
}

</pre>
]]></description>
   </item>
   <item>
      <title>How can I get bitmap of the processing windows?</title>
      <link>https://forum.processing.org/two/discussion/12241/how-can-i-get-bitmap-of-the-processing-windows</link>
      <pubDate>Tue, 25 Aug 2015 04:42:58 +0000</pubDate>
      <dc:creator>moonblood2</dc:creator>
      <guid isPermaLink="false">12241@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I'm very new to Processing,So I want to know is it possible for me to get the bitmap out of the processing window. I mean not only from the video source but the whole video that showing in the running window. Because I want to upload it to the server on the Internet.</p>

<p>Here is my code you can see it show the same 2 video in window</p>

<pre><code>import processing.video.*;

Capture cam;

void setup(){
  size(1280,480);
  String[] cameras = Capture.list();
  cam = new Capture(this,640,480,cameras[1],30);
  cam.start();
}

void draw(){
  if(cam.available()){
    cam.read();
  }
  image(cam,0,0);
  image(cam,640,0);
}
</code></pre>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>I need a way to gradually change the color of a shape, depending on how many time it should be drawn</title>
      <link>https://forum.processing.org/two/discussion/12009/i-need-a-way-to-gradually-change-the-color-of-a-shape-depending-on-how-many-time-it-should-be-drawn</link>
      <pubDate>Sat, 08 Aug 2015 17:17:32 +0000</pubDate>
      <dc:creator>peppe87</dc:creator>
      <guid isPermaLink="false">12009@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I need to drawn a series of shapes depending on some external data. For how is structured that data, some shapes would be drawn multiple times, but what I actually want is to change their color.
So, for example, if a square would be drawn once on the same area, I'd want to fill it with some greenish color, while if it would be drawn 5 times, I'd want to fill it with something yellowish.</p>

<p>I tried to check if blendMode() can accomplish that, but from what I've seen it can only increase\decrease the value of each channel, while I need to switch at some point to a different tonality (like from green to yellow and so on).</p>

<p>I've also check if I could directly manipulate the pixels of the sketch but that doesn't seem very efficient, and moreover I can't understand how work with the values I get: e.g. unless I'm wrong, with get(x,y) or pixels[],  I can obtain a single int  (with weird values, at lest for me)- not the color array I could work with.</p>

<p>(that's one simple code example I used to try get(x,y) or pixels[] command):</p>

<pre><code>PGraphics pg;
void setup() {

  size(60, 60); 
  background(255);

  pg = createGraphics(40, 40);
  pg.beginDraw();
  noStroke();
  fill(255, 0, 0, 100);
  strokeWeight(1);
  ellipse(40, 40, 20, 20);
  pg.endDraw();

  color c = get(38,40);
   println(c);

}

void draw() {
}
</code></pre>

<p>So, could anyone help me, explaining if that's some way to work with blending, or what I'm doing wrong with get\pixels or if there's some other good way around? 
Obliviously, I'm trying to work with a solution like that because I would avoid to manipulate the data after reading it - in other words, avoiding to manually check  what shapes are drawn more than once, and manually setting their colors to what I want.</p>
]]></description>
   </item>
   </channel>
</rss>