<?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 brightness() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=brightness%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:47:48 +0000</pubDate>
         <description>Tagged with brightness() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedbrightness%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to compute 3D Delaunay Triangulation ? (with or without library)</title>
      <link>https://forum.processing.org/two/discussion/27866/how-to-compute-3d-delaunay-triangulation-with-or-without-library</link>
      <pubDate>Fri, 27 Apr 2018 21:52:59 +0000</pubDate>
      <dc:creator>solub</dc:creator>
      <guid isPermaLink="false">27866@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I'm desperately and unsuccessfully trying to compute Delaunay triangulation from a 3D point cloud. It's a thing that many people have been trying to tackle for years (the same question has been asked over a dozen times on this forum: <a rel="nofollow" href="https://forum.processing.org/two/discussion/16972/3d-triangulation-library">here</a>, <a rel="nofollow" href="https://forum.processing.org/one/topic/delaunay-in-3d-space.html">here</a>, also <a rel="nofollow" href="https://forum.processing.org/one/topic/toxiclib-voronoi-example-sketch.html">here</a>, <a rel="nofollow" href="https://forum.processing.org/one/topic/creating-an-irregular-3d-mesh.html">here</a> again...) but that has never found a proper solution.</p>

<p>To the best of my knowledge, there are 4 libraries capable of computing Delaunay triangulation:</p>

<ul>
<li>Mesh by Lee Byron</li>
<li>iGeo by Satoru Sugihara</li>
<li>Hemesh (WBlut)</li>
<li>Toxiclibs by Karsten Schmidt </li>
</ul>

<p>However:</p>

<ul>
<li>Mesh only works in 2 dimensions (+ is flawed)</li>
<li>iGeo has not been ported yet to Processing 3 </li>
<li><code>Voronoi</code> &amp; <code>DelaunayTriangulation</code> classes from Toxiclibs do not support 3D </li>
</ul>

<p>It seems therefore the only solution lies in the Hemesh library.</p>

<p><strong>GOAL</strong></p>

<p>I would like to transform the colors of a painting into a 3D mesh via Delaunay triangulation. It's a relatively widespread technique that media artist <a rel="nofollow" href="https://www.quayola.com/">Quayola</a> (among others) has been brilliantly using for years.</p>

<p><img src="http://www.dreamideamachine.com/en/wp-content/uploads/sites/3/2016/01/004-004_30x53_detail_0.jpg" alt="" />
<img src="http://www.dreamideamachine.com/en/wp-content/uploads/sites/3/2016/01/0037.jpg" alt="" /></p>

<p><strong>PROBLEMS</strong> (hard to explain in english)</p>

<ul>
<li>Instead of displaying a <em>single</em> 3D <strong>terrain</strong> (like in the pictures above) from a cloud of 3D points, the Hemesh library seems to compute <em>multiple</em> <strong>polyhedrons</strong> (like diamonds with cavities). </li>
<li>There is a threshold (<code>triangulation.getAlphaTriangles(threshold)</code>) to limit the amount of surrounding points to connect to, but that very threshold prevents from connecting to neighboring points that are far.</li>
</ul>

<p><img src="https://i.imgur.com/OsFvgbp.png" alt="" /></p>

<p>As a result, this painting from John William Waterhouse:</p>

<p><img src="https://i.imgur.com/GxBjlOV.jpg" alt="" />
<em>(some dude getting hit on at a pool party)</em></p>

<p>is tranformed to this:</p>

<p><img src="https://i.imgur.com/ASWhKZO.png" alt="" />
<em>(all the shapes are "closed" (P3 connected to P1) but it shouldn't be that way)</em></p>

<p>With a higher threshold:
<img src="https://i.imgur.com/tA4nYYe.png" alt="" /></p>

<p><img src="https://i.imgur.com/fleAf92.png" alt="" />
<em>(Between two layers of polyhedrons)</em></p>

<p><strong>QUESTIONS</strong></p>

<ul>
<li>How can I avoid this behavior (if possible) ?</li>
<li>Do you know another library that could compute Delaunay triangulations in 3D space ?</li>
<li>Is there another way to achieve what I'm trying to do here (3D terrain from point cloud) ?</li>
</ul>

<p>Important parts of the code (it's in Python but PLEASE DO NOT MOVE THIS QUESTION TO PYTHON MODE):</p>

<p><strong>setup()</strong></p>

<pre><code>threshold = 35
render = WB_Render(this)
for p in points:
        new_points = WB_Point(p.x, p.y, p.z)
        list.append(new_points)
triangulation = WB_Triangulate.alphaTriangulate3D(list)
triangles = triangulation.getAlphaTriangles(threshold)
</code></pre>

<p><strong>draw()</strong></p>

<pre><code>noStroke()
for i in range(0, len(triangles), 3):
    render.drawTriangle(liste[triangles[i]], liste[triangles[i+1]], liste[triangles[i+2]])
</code></pre>

<p>Thank you</p>
]]></description>
   </item>
   <item>
      <title>TIS/TSM ERROR &amp; crash while looping()</title>
      <link>https://forum.processing.org/two/discussion/27904/tis-tsm-error-crash-while-looping</link>
      <pubDate>Wed, 02 May 2018 12:43:57 +0000</pubDate>
      <dc:creator>je5c</dc:creator>
      <guid isPermaLink="false">27904@/two/discussions</guid>
      <description><![CDATA[<p>anyone know why this is crashing right when it should loop?</p>

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

// Declare the processing sound variables 
SoundFile sample;
Amplitude rms;

// Declare a scaling factor
float scale=1;

// Declare a smooth factor
float smooth_factor=0.25;

// Used for smoothing
float sum;

PImage img;       // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows;   // Number of columns and rows in our system

public void setup() {
  size(800, 1000, P3D); 
  //fullScreen(P3D);
  img = loadImage("...");  // Load the image
  columns = img.width / cellsize;  // Calculate # of columns
  rows = img.height / cellsize;  // Calculate # of rows

    //Load and play a soundfile and loop it
    sample = new SoundFile(this, "...");
    sample.loop();

    // Create and patch the rms tracker
    rms = new Amplitude(this);
    rms.input(sample);

}

void draw() {
  background(255,0,255);
  // Begin loop for columns
  for ( int i = 0; i &lt; columns; i++) {
    // Begin loop for rows
    for ( int j = 0; j &lt; rows; j++) {
      int x = i*cellsize + cellsize/2;  // x position
      int y = j*cellsize + cellsize/2;  // y position
      int loc = x + y*img.width;  // Pixel array location
      color c = img.pixels[loc];  // Grab the color
      // Calculate a z position as a function of mouseX and pixel brightness
      //float z = width/2 * brightness(img.pixels[loc]) - 20.0;
        float rms_scaled=sum*width/10 * brightness(img.pixels[loc]) - 20.0;

     // smooth the rms data by smoothing factor
    sum += (rms.analyze() - sum) * smooth_factor;  

    // rms.analyze() return a value between 0 and 1. It's
    // scaled to height/2 and then multiplied by a scale factor


      // Translate to the location, set fill and stroke, and draw the rect
      pushMatrix();
      //translate(x + 300, y + 250, rms_scaled);
      translate(x + 200, y + 200, rms_scaled);
      fill(c, 204);
      noStroke();
      rectMode(CENTER);
      rect(0, 0, cellsize, cellsize);
      popMatrix();
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Brightness tracking on background image</title>
      <link>https://forum.processing.org/two/discussion/26151/brightness-tracking-on-background-image</link>
      <pubDate>Sun, 28 Jan 2018 13:17:47 +0000</pubDate>
      <dc:creator>dyrra</dc:creator>
      <guid isPermaLink="false">26151@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I wanted to make interactive brightness tracking - same as here <a href="https://processing.org/examples/brightness.html" target="_blank" rel="nofollow">https://processing.org/examples/brightness.html</a>, but use video to track brightness (so I can shine on the camera to reveal the image). I was not able to put this example with brightness tracking example in processing library together. Or just make an ellipse with blurred edges and the rest of the image black?</p>

<p>/**
 * Brightness Tracking 
 * by Golan Levin. 
 *
 * Tracks the brightest pixel in a live video signal. 
 */</p>

<pre><code>PImage bg;
int y;
import processing.video.*;

Capture video;

void setup() {
  size(640, 480);
  video = new Capture(this, width, height);
  video.start();  
  bg = loadImage("02.jpg");
  noStroke();
  smooth();
}

void draw() {

  if (video.available()) {
    video.read();
    background(bg);
    image(video, 0, 0, 20, 20); 
    int brightestX = 0; 
    int brightestY = 0; 
    float brightestValue = 0;
    video.loadPixels();
    int index = 0;
    for (int y = 0; y &lt; video.height; y++) {
      for (int x = 0; x &lt; video.width; x++) {
        int pixelValue = video.pixels[index];
        float pixelBrightness = brightness(pixelValue);

        if (pixelBrightness &gt; brightestValue) {
          brightestValue = pixelBrightness;
          brightestY = y;
          brightestX = x;
        }
        index++;
      }

    }
    fill(255, 204, 0, 80);
    ellipse(brightestX, brightestY, 250, 250);

  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to obtain 3D textured Sphere</title>
      <link>https://forum.processing.org/two/discussion/26925/how-to-obtain-3d-textured-sphere</link>
      <pubDate>Mon, 19 Mar 2018 14:24:24 +0000</pubDate>
      <dc:creator>BrokenCode</dc:creator>
      <guid isPermaLink="false">26925@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody,
I'd like to ask what kind of technique this render is using:</p>

<p><a href="http://cpetry.github.io/NormalMap-Online/" target="_blank" rel="nofollow">http://cpetry.github.io/NormalMap-Online/</a></p>

<p>I man, I don't know how that is called, 3D texture? How can I obtain something like this? Even a simple example :)</p>

<p>Any reference or link will be appreciated,
thank you</p>
]]></description>
   </item>
   <item>
      <title>Cant get image from webcam</title>
      <link>https://forum.processing.org/two/discussion/26817/cant-get-image-from-webcam</link>
      <pubDate>Tue, 13 Mar 2018 21:41:57 +0000</pubDate>
      <dc:creator>Pjlons83</dc:creator>
      <guid isPermaLink="false">26817@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have my first processing sketch running with no errors but I cannot get an image from the webcam.</p>

<pre><code>import hypermedia.video.*;
import java.awt.Rectangle;

OpenCV opencv;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;



void setup() {

    size( 320, 240 );

    opencv = new OpenCV( this );
    opencv.capture( width, height );                   // open video stream
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-&gt; front face detection : "haarcascade_frontalface_alt.xml"


    // print usage
    println( "Drag mouse on X-axis inside this sketch window to change contrast" );
    println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

}


public void stop() {
    opencv.stop();
    super.stop();
}



void draw() {

    // grab a new frame
    // and convert to gray
    opencv.read();
    opencv.convert( GRAY );
    opencv.contrast( contrast_value );
    opencv.brightness( brightness_value );

    // proceed detection
    Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

    // display the image
    image( opencv.image(), 0, 0 );

    // draw face area(s)
    noFill();
    stroke(255,0,0);
    for( int i=0; i&lt;faces.length; i++ ) {
        rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); 
    }
}



/**
 * Changes contrast/brigthness values
 */
void mouseDragged() {
    contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
    brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}
</code></pre>

<p>The programme is supposed to display an image, detect a face and draw a rectangle around the face. I am using windows 7 with a USB webcam. I have tried a couple of versions of processing and both are the same.</p>

<p>Any ideas of where to look first?</p>

<p>Thanks
Paul</p>
]]></description>
   </item>
   <item>
      <title>Copy pixel[] and overlay</title>
      <link>https://forum.processing.org/two/discussion/26241/copy-pixel-and-overlay</link>
      <pubDate>Mon, 05 Feb 2018 01:09:50 +0000</pubDate>
      <dc:creator>MforMatt</dc:creator>
      <guid isPermaLink="false">26241@/two/discussions</guid>
      <description><![CDATA[<p><img src="https://forum.processing.org/two/uploads/imageupload/236/ZE7GTQUNOB4F.png" alt="Screen Shot 2018-02-05 at 1.16.36 PM" title="Screen Shot 2018-02-05 at 1.16.36 PM" /></p>

<p>I'm trying to create an effect like the image above which I have done by crudely exporting a frame then loading it and blending it - which isn't very memory/processor efficient. I'm wanting to know what the best way producing this effect would be with the pixel array. ie - how to store the pixels[] of a single frame.</p>

<p>thanks.</p>

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


PImage test, test2;
float FPS;
int count;
int mod;
int rand;


Capture video;

void setup() {
  size(640, 420, P2D);
  video = new Capture(this, 640, 360, 30);
  video.start();

}

void captureEvent(Capture video) {
  video.read();
}

void draw() {
  FPS = frameRate;
  count = ceil(millis()/1000);
  mod = count % 5;

  background(245, 238, 96);

  image(video, 0, 0, 640, 420);

  loadPixels();
  for (int i = 0; i &lt; pixels.length; i++) {

    float b = brightness(pixels[i]);
    if (b &gt; 97) {
      pixels[i] = color (255);
    } else {
      pixels[i] = color (245, 238, 96);
    }
  }

  updatePixels();
  textSize(16);
  fill(0);
  text(FPS, 50, 50);
  text(count, 50, 75);
  text(mod, 50, 100);
  text(mouseX, 50, 125);


}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Light drawing: make 2 light sources interact with eachother</title>
      <link>https://forum.processing.org/two/discussion/26181/light-drawing-make-2-light-sources-interact-with-eachother</link>
      <pubDate>Tue, 30 Jan 2018 21:58:28 +0000</pubDate>
      <dc:creator>ga77</dc:creator>
      <guid isPermaLink="false">26181@/two/discussions</guid>
      <description><![CDATA[<p>I'm new to processing and have been doing funprogramming.org light drawing tutorial (no. 150). Just wondering if it's possible to include a second light source, maybe a red and a white light, and have something happen when the 2 cross paths. Is this possible and how would I go about it? thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>RGB and HSB - how do they relate?</title>
      <link>https://forum.processing.org/two/discussion/24844/rgb-and-hsb-how-do-they-relate</link>
      <pubDate>Thu, 02 Nov 2017 15:23:07 +0000</pubDate>
      <dc:creator>allonestring</dc:creator>
      <guid isPermaLink="false">24844@/two/discussions</guid>
      <description><![CDATA[<p>I've spent far too long whittling down a problem to this:</p>

<pre><code>color bg;


colorMode(RGB, 255, 255, 255); //default
bg = color( 0, 169, 255 );
background(bg);
println(hue(bg) +", "+ saturation(bg) +", "+ brightness(bg)); //outputs 141.83333, 255.0, 255.0
println(red(bg) +", "+ green(bg) +", "+ blue(bg)); //outputs 0.0, 169.0, 255.0


colorMode(HSB, 360, 100, 100);
bg = color( 200, 100, 100 );
background(bg);
println(hue(bg) +", "+ saturation(bg) +", "+ brightness(bg)); //outputs 200.23529, 100.0, 100.0
println(red(bg) +", "+ green(bg) +", "+ blue(bg)); //outputs 0.0, 66.27451, 100.0
</code></pre>

<p>It can be boiled down to:</p>

<pre><code>colorMode(HSB, _anything_, 100, 100);
println(hue(color(200, 100, 100))); //outputs 200.23529
</code></pre>

<p>According to my colour picker, (R0, G169, B255) = (H200, S100, B100), so why don't they output the same values?</p>

<p>I'm manipulating the hue of various colours and am finding this inaccuracy, er, challenging.</p>

<p>☺</p>
]]></description>
   </item>
   <item>
      <title>Transforming PVectors into p5.vector (or createVector?)</title>
      <link>https://forum.processing.org/two/discussion/24074/transforming-pvectors-into-p5-vector-or-createvector</link>
      <pubDate>Sat, 09 Sep 2017 06:17:16 +0000</pubDate>
      <dc:creator>paul_young1984</dc:creator>
      <guid isPermaLink="false">24074@/two/discussions</guid>
      <description><![CDATA[<p>Hi Folks,</p>

<p>I've been reading through every 'convert Processing into P5' document I can get a hold of, and I still can't figure out how to translate PVector's (processing) into p5.vector syntax.</p>

<p>Beneath is code in Processing (working). Beneath that is my code for p5 (not working) I'm pretty sure it's my Vector syntax that is out of wack. Can someone please provide direction? Saying that, there might be other things wrong, and I'm open to suggestions.</p>

<p>PROCESSING:</p>

<pre><code>PImage img;
ArrayList pts;


void setup() {
  img = loadImage("ASKEW A.jpg");

    size(500, 500, P3D);

  pts = new ArrayList();
  findPoints();
}

void draw () {
  background(255);


for (int i = pts.size()-1; i &gt;= 0; i --){
      PVector pt = (PVector)pts.get(i);

      fill(pt.z);

      noStroke();

      stroke(0, 30);
      for (int j = pts.size()-1; j &gt;= 0; j --){
      if(i&gt;1){  
        PVector pt2 = (PVector)pts.get(j);
        if (pt.dist(pt2) &lt; 20){

          int r = 10;
          float x = r * tan(radians(i*(360.0/ (mouseX * tan(3)) )));
          float y = r * sin(radians(i*(360.0/ (mouseY*  tan(3)) )));

          int r1 = 2;
          float x1 = r1 * tan(radians(i*(360.0 / (mouseX* tan(3)))));
          float y1 = r1 * sin(radians(i*(360.0 / (mouseY* tan(3)))));


          stroke(0, 30);
          line(pt.x + x, pt.y + y, 
          pt2.x + x1, pt2.y + y1);
        }
      }
    }
  }
}

void findPoints(){

  img.loadPixels();
  for (int i = img.width-1; i &gt;= 0; i -= 3){
    for (int j = img.height; j &gt;=0; j -= 3){

      color c = img.get(i, j);
      if (brightness(c) &lt; 255){
        pts.add(new PVector(i, j, brightness(c)));
      }
    }
  }
}
</code></pre>

<p>p5 :</p>

<pre><code>var img;
var pts = [];
var i, j;


function setup() {

  createCanvas(500, 500);

    img = loadImage("ASKEW A.jpg");
    findPoints();
    }


function draw () {
  background(255);

for (i = pts.length()-1; i &gt;= 0; i --){
      var pt = new p5.Vector.pts.get(i);
      fill(pt.z);

      noStroke();

      stroke(0, 30);
      for (j = pts.length()-1; j &gt;= 0; j --){
      if(i&gt;1){  
        var pt2 = new p5.Vector.pts.get(j);
        if (pt.dist(pt2) &lt; 20){

          var r = 20;
          var x = r * tan(radians(i*(360.0/ (mouseX) )));
          var y = r * sin(radians(i*(360.0/ (mouseY) )));

          var r1 = 2;
          var x1 = r1 * tan(radians(i*(360.0 / (mouseX))));
          var y1 = r1 * sin(radians(i*(360.0 / (mouseY))));


          stroke(0, 30);
          line(pt.x + x, pt.y, 
          pt2.x + x1, pt2.y + y1);
        }
      }
    }
  }
}


function findPoints(){

  img.loadPixels();
  for (var i = img.width-1; i &gt;= 0; i -= 3){
    for (var j = img.height; j &gt;=0; j -= 3){

      var c = img.get(i, j);
      if (brightness(c) &lt; 255){
        pts.push(new p5.Vector(i, j, brightness(c)));
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>getting out of bounds exeption:0 dont know why</title>
      <link>https://forum.processing.org/two/discussion/23572/getting-out-of-bounds-exeption-0-dont-know-why</link>
      <pubDate>Mon, 24 Jul 2017 20:06:12 +0000</pubDate>
      <dc:creator>sincos</dc:creator>
      <guid isPermaLink="false">23572@/two/discussions</guid>
      <description><![CDATA[<p>this is the code</p>

<pre><code>import processing.video.*;//importa la biblioteca de video

Capture cam1;
Capture cam2;
//Capture cam3;para agregar mas camaras

void setup() {
  size(640, 480);

  String[] cameras = Capture.list();
  //if de seguridad
  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():
  cam1 = new Capture(this, cameras[14]);
  cam2 = new Capture(this, cameras[1]);
//metodo para comenzar las camaras
  cam1.start();
  cam2.start();
//carga de pixeles y pixeles de las camaras
  loadPixels();
  cam1.loadPixels();
  cam2.loadPixels();
}

void draw() {
  if (cam1.available() == true) {
    cam1.read();
  }

  if (cam2.available() == true) {
    cam2.read();
  }
//recorrer los pixeles de las camaras
  for (int y = 0; y&lt;height; y++)
    {
      for (int x = 0; x&lt;width; x++)
      {        
        int loc = x+y*width;
      //color pixelactual = pixels[loc];
      float treshold = mouseX;

      color fondo = color(0,0,0);

      float bright1 = brightness(cam1.pixels[loc]);
      float bright2 = brightness(cam2.pixels[loc]);

      if(bright1&gt;treshold)
      {
        pixels[loc]=fondo;
      }
    }
  }
  updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>pixels array edge detection</title>
      <link>https://forum.processing.org/two/discussion/23593/pixels-array-edge-detection</link>
      <pubDate>Thu, 27 Jul 2017 01:18:52 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">23593@/two/discussions</guid>
      <description><![CDATA[<p>Does anyone know how to turn this processing code</p>

<p><a href="https://www.openprocessing.org/sketch/441474" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/441474</a></p>

<p>into p5.js?</p>

<p><a href="https://www.openprocessing.org/sketch/441671" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/441671</a></p>
]]></description>
   </item>
   <item>
      <title>How can I optimize Box drawing ?</title>
      <link>https://forum.processing.org/two/discussion/23220/how-can-i-optimize-box-drawing</link>
      <pubDate>Mon, 26 Jun 2017 22:13:07 +0000</pubDate>
      <dc:creator>Nath7009</dc:creator>
      <guid isPermaLink="false">23220@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I've tried to make a program that shows a 2D image in 3D, using the brightness of each pixel. So I draw a box at each x and y, the z is the birghtness. Unfortunately, the only way I've found to see the image is to draw boxes in draw(), but it gets really slow for images bigger than 400*400. I think that there are ways to make that better, so how can I do it ?</p>

<p>Code :</p>

<pre><code>import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam camera;
PImage img;

void setup() {
  size(800, 800, P3D);
  ambientLight(255, 255, 255, 0, 0, 0);
  img = loadImage("download.jpg");
  camera = new PeasyCam(this, img.width/2, img.height/2, 0, 1000);
  img.loadPixels();
}
void draw() {
  background(0);
  for (int i=0; i&lt;img.pixels.length; i++) {
    color c = img.pixels[i];
    float b = map(brightness(c), 0, 255, -100, 100);
    fill(c);
    noStroke();
    int x = i%(img.width);
    int y = (i-x)/img.width;
    translate(x, y, b);
    box(1);
    translate(-x, -y, -b);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>brightness(pixel) doesnt work</title>
      <link>https://forum.processing.org/two/discussion/23093/brightness-pixel-doesnt-work</link>
      <pubDate>Fri, 16 Jun 2017 18:37:26 +0000</pubDate>
      <dc:creator>res</dc:creator>
      <guid isPermaLink="false">23093@/two/discussions</guid>
      <description><![CDATA[<p>Hello 2gether,</p>

<p>i want to generate objects (ellipse) on a typo of an Image (pic.png).</p>

<p>Sadly, the code doesnt work and the objects on the entire screen.
Thanks for HELP!!!!<br />
Heres the Code:</p>

<pre><code>    ArrayList &lt;PVector&gt; circles = new ArrayList &lt;PVector&gt; ();
    float diameter;
    PImage typo;

    void setup() {
      background(255);
      size(500, 500);
      colorMode(RGB, 100, 100, 100);
      noStroke();
      smooth();
      typo = loadImage("pic.png");
    }

    void draw() {

      addCircle();
      for (int i=0; i&lt;circles.size(); i++) {
        PVector p = circles.get(i);
        fill(i % 360, 100, 100);
        ellipse(p.x, p.y, p.z, p.z);
      }
    }

    void addCircle() {
      diameter=random(10, 40);
      PVector c = randomVector();
      int tries = 1000000;
      color pixel;

      pixel = typo.get((int)c.x, (int)c.y);

      while (overlap(c) &amp;&amp; tries &gt; 0) {
        c = randomVector();
        tries--;
      }

      if (!overlap(c) &amp;&amp; brightness(pixel)&gt;0) {
        circles.add(c);
      } else {
        addCircle();
      }
    }

    PVector randomVector() {
      return new PVector(random(width), random(height), diameter);
    }

    boolean overlap(PVector c) {
      for (PVector p : circles) {
        if ((dist(c.x, c.y, p.x, p.y) &lt; (c.z + p.z)*0.5)) {
          return true;
        }
      }
      return false;
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to move the histogram at different coordinates</title>
      <link>https://forum.processing.org/two/discussion/23011/how-to-move-the-histogram-at-different-coordinates</link>
      <pubDate>Sat, 10 Jun 2017 12:55:18 +0000</pubDate>
      <dc:creator>mohammadarifien</dc:creator>
      <guid isPermaLink="false">23011@/two/discussions</guid>
      <description><![CDATA[<p><img src="https://forum.processing.org/two/uploads/imageupload/438/7Q1FV4737V8C.jpg" alt="Hist" title="Hist" /></p>

<p>I've followed the instructions in the histogram example but I get into trouble when I want to move the histogram to different coordinates, here's the script I've created in accordance with the histogram example that's on the processing page :</p>

<p>PImage object;</p>

<p>size(1000,500);</p>

<p>background(0);</p>

<p>object=loadImage("og.jpg");</p>

<p>image(object,0,0);</p>

<p>int [] hist = new int[256];</p>

<p>for (int i = 0; i&lt; object.width; i++){</p>

<p>for (int j = 0; j&lt; object.height; j++){</p>

<p>int bright = int (brightness(get(i,j)));</p>

<p>hist[bright]++;</p>

<p>}</p>

<p>}</p>

<p>int histMax = max(hist);</p>

<p>stroke(255);</p>

<p>for (int i = 0; i&lt; object.width; i +=2){</p>

<p>int which = int(map(i,0, object.width,0,255));</p>

<p>int y = int (map(hist[which], 0, histMax,object.height,0));</p>

<p>line(i,object.height,i,y);</p>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>brightness and contrast of the webcam</title>
      <link>https://forum.processing.org/two/discussion/22012/brightness-and-contrast-of-the-webcam</link>
      <pubDate>Sat, 15 Apr 2017 16:58:26 +0000</pubDate>
      <dc:creator>gius</dc:creator>
      <guid isPermaLink="false">22012@/two/discussions</guid>
      <description><![CDATA[<p>Hello everybody,
I want that while there is a live webcam it is possible to adjust the brightness and contrast of color and gray images.
This is my code:</p>

<pre><code>import processing.video.*;
import g4p_controls.*;
import java.awt.Font;
import gab.opencv.*;


OpenCV opencv;

PFont f;     

boolean filterT=false;


Capture cam;

GButton btnFilterT;

int n = 1;

void setup() {
  size(1024, 768); 

  f = createFont("Arial", 48, true);

  btnFilterT = new GButton(this, 740, 50, 140, 20);
  btnFilterT.setText("On");
  btnFilterT.setLocalColorScheme(GCScheme.GREEN_SCHEME);

  cam = new Capture(this, 640, 480);
  cam.start();
}


void draw() {

  if (cam.available() == true) {
    cam.read();
  }


  pushMatrix();
  scale(-1, 1);
  image(cam.get(), -width, 0, width, height);
  popMatrix();  

  opencv = new OpenCV(this, cam);
  opencv.loadImage(cam);


  if (filterT==true) {
    opencv.brightness((int)map(mouseX, 0, width, -255, 255));
    image(opencv.getOutput(),0, 0, width, height);
  }
}

public void handleButtonEvents(GButton button, GEvent event) {

  if (button == btnFilterT) {
    filterT=true;
  }
}
</code></pre>

<p>I have two problems:</p>

<p>if I press the T button to start  the brightness and contrast in gray, the screen flips over and becomes no mirror.</p>

<p>how can I have brightness and contrast  with the mirror video?</p>

<p>how can I have the brightness and contrast of the webcam color?</p>

<p>thank you</p>
]]></description>
   </item>
   <item>
      <title>Create new image with pixels</title>
      <link>https://forum.processing.org/two/discussion/22506/create-new-image-with-pixels</link>
      <pubDate>Wed, 10 May 2017 21:59:21 +0000</pubDate>
      <dc:creator>Jose_Aparecido</dc:creator>
      <guid isPermaLink="false">22506@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>I'm trying to build a new image, capturing only part that interests me from another, I used this base to begin with:
<a href="https://processing.org/tutorials/pixels/" target="_blank" rel="nofollow">https://processing.org/tutorials/pixels/</a></p>

<p>I am in doubt as to the image below, the part where it seems "rainbow", would I use the function (hue), or (r, g, b) individually to capture?</p>

<p>And what about the circled part (very badly done, sorry) more in the middle, would have to use the function (brightness), since it is kind of "brightness" in the image?</p>

<p>Thanks any hint, below is the sample code, and the image as template.</p>

<p>Thank you,</p>

<pre><code>    PImage source;       
    PImage destination;  
    float threshold = 0;

    void setup() {
      size(400, 300);
      source = loadImage("Img01.jpg"); 
      source.resize(400, 300); 
      destination = createImage(source.width, source.height, RGB);
    }

    void draw() {  
      //threshold = 127;
      threshold = 70;

      source.loadPixels();
      destination.loadPixels();

      for (int x = 0; x &lt; source.width; x++) {
        for (int y = 0; y &lt; source.height; y++ ) {
          int loc = x + y*source.width;
          if (brightness(source.pixels[loc]) &gt; threshold) {
          //if (hue(source.pixels[loc]) &gt; threshold) {
            //destination.pixels[loc]  = source.pixels[loc];  // White
            destination.pixels[loc]  = source.pixels[loc];
          }
        }
      }

      destination.updatePixels();
      image(destination,0,0);
      //image(source,0,0);
    }

    void keyPressed(){
      if (key == 'A' || key == 'a')
        threshold = threshold + 10;

      if (key == 'D' || key == 'd')
        threshold = threshold - 10;

      println(threshold);  
    }
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/514/V1CE41MQRF0U.png" alt="Imagem01" title="Imagem01" /></p>
]]></description>
   </item>
   <item>
      <title>interactive screen using live video, changing letters positions</title>
      <link>https://forum.processing.org/two/discussion/22123/interactive-screen-using-live-video-changing-letters-positions</link>
      <pubDate>Fri, 21 Apr 2017 11:34:54 +0000</pubDate>
      <dc:creator>MilaYume</dc:creator>
      <guid isPermaLink="false">22123@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm new to programming with Processing. Trying to make a code for my art bachelor degree. What I want to do: make the interactive screen, filled with letters(text), with a live cam recording what's happening in front, detecting motion. When there is a motion letter that meets motion line(human body contours) flips position with a letter from the side with motion come from. 
for that as a base, I used raindrops sketch and Shiffman's Example 16-13: Simple motion detection.
But now I'm getting a gray screen and letters appear non-stop. Did I mess up something with arrays? should text be put not in a string? I read about Kinect but not sure if it would help at this point. Hope to get hints or something that to do next :]</p>

<pre><code>    import processing.video.*;
    import java.awt.Frame;
    import java.awt.Image;
    import java.text.*;

    Capture cam;
    Letter[][] drops;
    int dropsLength;
    PImage prevFrame;
    int sWidth = 1280;
    int sHeight = 720;

    String inputString = "Įsivaizduokime pasaulį, kur visi viską žino tiksliai, ir niekada neklysta. Niekam nekiltų abejoių, koks bus rytoj oras, kaip išsaugoti tirpstačius ledynus, ar koks visatos dydis. Žvelgiant į krentantį kamuoliuką kiekvienas galėtų pasakyti: -  O šito kamuoliuko kritimo greitis 6,325 m/s. -  Tikrai taip - atsakytų kitas. Ir viskas, daugiau nebebūtų jokių diskusijų, ieškojimų, matavimų. Su absoliučiu žinojimu gyvenimas taptų nebeįdomus, monotoniškas, tokiu atveju net progresas neįmanomas. Kai pradedu taip galvoti, džiaugiuosi nežinojimu, diskusijų galimybe, tiesos ieškojimu. Klaida suvokiama kaip neišvengiamas procesas teisybės ieškojime leidžia drąsiai žengti į praktikos sritį, nebijoti suklysti, o neteisingus procesus paversti progresu, žingsneliu link tikslo. Menininkas nebėra tas genijus, kuris turi sukurti kažką naujo, tarsi nežemiško, keičiančio visą mūsų suvokimą. Jo praktikos esmė eksperimentuoti ir klysti, organizuoti jau esamomis reikšmėmis ir kurti nau";
    char[] inputLetters;
    int dupStrings = 3;   //times to dublicate text
    int k = 800;
    float threshold = 50;

    void settings() {
      size(1280, 720);
    }
    void setup() {
      String[] cameras = Capture.list();

      drops = new Letter[dupStrings][inputString.length()];  //[inputString.length()]; 

      int wspace = 50;
      inputLetters = new char[inputString.length()]; 
      splitString();


      // first row hight
      int addLineHeight = 30;                                                       
      for (int i = 0; i &lt; dupStrings; i++) {     
            for (int j = 0; j &lt; inputLetters.length; j++) {   
                 if  (inputLetters[j] &lt; k + wspace ){
                   Letter testLetter = new Letter(inputLetters[j]);
                   testLetter.x = wspace;
                   testLetter.y = addLineHeight;
                   drops[i][j] = testLetter;
                   wspace += 10;   //spaces between letters

                   // new row
                   if (wspace &gt;= sWidth) {   
                                wspace = 10;
                               addLineHeight += 40; } // space between 

                    }
                           else {
                               addLineHeight += 50;
                                }
                                                                  }
                                               }
    // cam conect//

      if (cameras.length == 0) {
        println("There are no cameras available...");
        size(400, 400);
        exit();
      }
      else {
        cam = new Capture(this, sWidth, sHeight);
        cam.start();
        cam.loadPixels();
        prevFrame = createImage(cam.width, cam.height, RGB);

        size(sWidth, sHeight);
      }
      dropsLength = inputString.length();
    }

    void captureEvent(Capture cam) {
      // Save previous frame for motion detection!!
      prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height); 
      // Before we read the new frame, we always save the previous frame for comparison!```
      prevFrame.updatePixels();  // Read image from the camera
      cam.read();
    }


    void splitString() { 

      for (int i = 0; i &lt; inputString.length() ; i++) {
        inputLetters[i] = inputString.charAt(i);
      }
    }

    void draw() {

        loadPixels();
      cam.loadPixels();
      prevFrame.loadPixels();
        // Begin loop to walk through every pixel
      for (int x = 0; x &lt; cam.width; x ++ ) {
        for (int y = 0; y &lt; cam.height; y ++ ) {

          int loc = x + y*cam.width;            // Step 1, what is the 1D pixel location
          color current = cam.pixels[loc];      // Step 2, what is the current color
          color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current); 
          float g1 = green(current); 
          float b1 = blue(current);
          float r2 = red(previous); 
          float g2 = green(previous); 
          float b2 = blue(previous);
          float diff = dist(r1, g1, b1, r2, g2, b2);

          // Step 5, How different are the colors?
          // If the color at that pixel has changed, then there is motion at that pixel.
          if (diff &gt; threshold) { 
            // If motion, display black
            pixels[loc] = color(0);
          } else {
            // If not, display white
            pixels[loc] = color(255);
          }
        }
      }

       //Responding to the brightness/color of the screen
       for (int i = 0; i &lt; dupStrings; i++) {
        for (int j = 0; j &lt; dropsLength; j++) {

          if (drops[i][j].y &lt; sHeight &amp;&amp; drops[i][j].y &gt; 0) {   
           int loc = drops[i][j].x + ((drops[i][j].y)-1)*sWidth;                                           
           float bright = brightness(cam.pixels[loc]);                                                                                                                                                          
            if (bright &gt; threshold) {   
              drops[i][j].dropLetter();
              drops[i][j].upSpeed = 1;
            }
            else {                                                                            
              if (drops[i][j].y &gt; threshold) {
                int aboveLoc = loc = drops[i][j].x + ((drops[i][j].y)-1)*sWidth;
                float aboveBright = brightness(cam.pixels[aboveLoc]);
                if (aboveBright &lt; threshold) {                                              
                  drops[i][j].liftLetter();
                  drops[i][j].upSpeed = drops[i][j].upSpeed * 5;                           
                }
              }
            }
          }
          else {
            drops[i][j].dropLetter(); 
          }

          drops[i][j].drawLetter();
          cam.updatePixels();
        }
      }
    }

    class Letter {
      int x;
      int y; 
      int m;
      char textLetter;
      int upSpeed;
      int alpha = 150;
      Letter(char inputText) {
        x = 100;
        y = 100;
        textLetter = inputText;
        textSize(16);
        upSpeed = 1;
      }
      void drawLetter() {
       // if ( m &lt; 1) {
        fill(150, 150, 150 , alpha);                 
        text(textLetter, x, y);

      }

      void letterFade() {
        alpha -= 5;
        if(alpha &lt;= 0) {
          y = int(random(-350, 0));
          alpha = 255; 
        }
      }


      void dropLetter() {
      //  y++;                         
        if (y &gt; 730) {
          letterFade();
        }
      }

      void liftLetter() {
        int newY = y - upSpeed;       
        if (newY &gt;= 0) {
          y = newY;
        }
        else {
          y = 0;
        }
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Hey guys! Need help on my coding project! (webcam amplifier)</title>
      <link>https://forum.processing.org/two/discussion/21915/hey-guys-need-help-on-my-coding-project-webcam-amplifier</link>
      <pubDate>Mon, 10 Apr 2017 15:01:41 +0000</pubDate>
      <dc:creator>prolly02</dc:creator>
      <guid isPermaLink="false">21915@/two/discussions</guid>
      <description><![CDATA[<p>Delete!</p>
]]></description>
   </item>
   <item>
      <title>how to make a pixel transparent?</title>
      <link>https://forum.processing.org/two/discussion/21653/how-to-make-a-pixel-transparent</link>
      <pubDate>Tue, 28 Mar 2017 09:43:12 +0000</pubDate>
      <dc:creator>Xeronimo74</dc:creator>
      <guid isPermaLink="false">21653@/two/discussions</guid>
      <description><![CDATA[<p>I seem to recall there was already a topic on this but I can't find it ... so what I want to do is loop through an array of pixels and make all the pixels above a certain brightness value transparent. How would I do this? Thanks!</p>
]]></description>
   </item>
   <item>
      <title>slider freezing</title>
      <link>https://forum.processing.org/two/discussion/21318/slider-freezing</link>
      <pubDate>Fri, 10 Mar 2017 18:39:44 +0000</pubDate>
      <dc:creator>gek07</dc:creator>
      <guid isPermaLink="false">21318@/two/discussions</guid>
      <description><![CDATA[<p>``I should work from rgb to hsb , but for some reason the sliders are freezing I got the color right at least ( more ore less )
    Slider RSlider ;
    Slider GSlider ;
    Slider BSlider ;
    Slider HSlider ;
    Slider SSlider ;
    Slider VSlider ;
    float rs = 0, gs=0, bs=0, hs=0, ss=0, vs=0;
    color filler = color(rs, gs, bs);
    color filler2= color (hs, ss, vs);</p>

<pre><code>void setup()
{  
  size(1200, 500);
  RSlider = new Slider (150, 350, "R");
  GSlider = new Slider (150, 400, "G");
  BSlider = new Slider (150, 450, "B");
  HSlider = new Slider (450, 350, "H");
  SSlider = new Slider (450, 400, "S");
  VSlider = new Slider (450, 450, "V");

  RSlider.lock();
  GSlider.lock();
  BSlider.lock();
  HSlider.lock();
  SSlider.lock();
  VSlider.lock();
}

void draw()
{ 
  background (255);
  colorMode(RGB, 255);
  fill(0, 0, 0);
  rect(0, 300, width, height-300);
  RSlider.display();
  GSlider.display();
  BSlider.display();
  HSlider.display();
  SSlider.display();
  VSlider.display();
  if (mouseX&gt;0&amp;&amp;mouseX&lt;=150+180) {
    float rs = map(RSlider.x, RSlider.rctx, 180, 0, 255);  
    float bs = map(BSlider.x, BSlider.rctx, 180, 0, 255); 
    float gs = map(GSlider.x, GSlider.rctx, 180, 0, 255);
    fill(rs, gs, bs);
    rect(0, 0, width, height-200);
  }
  if (mouseX&gt;330&amp;&amp;mouseX&lt;width) {
    colorMode(HSB, 255);
    HSlider.x=(int)hue(filler);
    SSlider.x=(int)saturation(filler);
    VSlider.x=(int)brightness(filler);
    float hs = map(HSlider.x, HSlider.rctx, 180, 0, 255);  
    float ss = map(SSlider.x, SSlider.rctx, 180, 0, 255); 
    float vs = map(VSlider.x, VSlider.rctx, 180, 0, 255); 
    fill(hs, ss, vs);
    rect(0, 0, width, height-200);
  }
}

void mousePressed()
{
  RSlider.unlock();
  GSlider.unlock();
  BSlider.unlock();
  HSlider.unlock();
  SSlider.unlock();
  VSlider.unlock();
}
void mouseDragged()
{
  RSlider.drag();
  GSlider.drag();
  BSlider.drag();
  HSlider.drag();
  SSlider.drag();
  VSlider.drag();
}
void mouseReleased()
{
  RSlider.lock();
  GSlider.lock();
  BSlider.lock();
  HSlider.lock();
  SSlider.lock();
  VSlider.lock();
}
class Slider 
{ 
  //  Slider mySlider ; // ?????????????????????????????????????
  PFont f;
  float x, y, 
  w=180, h = 10, 
  rctx;
  String text;
  boolean locked ;

  Slider (int x, int y, String text  ) {
    rctx=x;
    this.x = x ;
    this.y = y ;
    locked = true ;
    this.text=text;
    f = createFont(text, 20, true);
    textFont(f);
  }

  void lock () 
  {
    locked = true ;
  }

  void unlock ()
  {
    if (mouseX&gt;=x-(w/2) &amp;&amp; 
      mouseX&lt;= x+(w/2) &amp;&amp;
      mouseY&gt;= (y)-(h/2) &amp;&amp;
      mouseY&lt;= (y)+(h/2))
      locked = false;
  }

  void drag() 
  {
    if (!locked)
    {
      x=mouseX;
    }
  }

  void display()
  { 
    x=constrain (x, rctx, rctx+w);
    fill(200, 200, 200);
    rect(rctx, y, 180, 10);
    ellipse(x, y+5, 20, 20);
    text(text, rctx-40, y+12 );
  }//method
  //
}// class
</code></pre>
]]></description>
   </item>
   <item>
      <title>Using a Pixels X and Y Coordinates</title>
      <link>https://forum.processing.org/two/discussion/21237/using-a-pixels-x-and-y-coordinates</link>
      <pubDate>Wed, 08 Mar 2017 01:48:35 +0000</pubDate>
      <dc:creator>starkarma</dc:creator>
      <guid isPermaLink="false">21237@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm fairly new to programming and I'm currently having some trouble using the <code>pixels[]</code> array.
I've written a small formula which works on paper, but requires singular pixel's X and Y coordinates to work.</p>

<p>In essence, I'm trying to gather all pixels X and Y-coordinates and weigh them according to their darkness.</p>

<p>Extracting the average brightness (and reversing it) works just fine:</p>

<p><code>loadPixels();
  for (int i = 0; i &lt; pixels.length; i++) {
    bri += map(brightness(pixels[i]), 0, 100, 1, 0);
  }
  updatePixels();</code></p>

<p>But when I try to get the X-coordinate and weigh it using this method...</p>

<p><code>for (int x = 0; x &lt; width; x++) {
    for (int y = 0; y &lt; height; y++) {
     pix += (x + 1) * map(brightness(pixels[i]), 0, 100, 1, 0);
    }
    updatePixels();
  }</code></p>

<p>It only works with the first X-line of pixels, and even then, it outputs either 0s or other numbers I can't place.</p>

<p>I suspect that I'd have to write something around <code>x + y * width</code>, but I can't quite wrap my head around it.</p>

<p><strong>To summarise:</strong>
I need every pixel's X and Y-coordinates and that same pixel's brightness.</p>

<p>Thank you for reading! 
Please post your thoughts; and if I'm missing something extremely obvious as per usual, please point it out!</p>
]]></description>
   </item>
   <item>
      <title>Depth Values of Z Axis per Pixel</title>
      <link>https://forum.processing.org/two/discussion/20986/depth-values-of-z-axis-per-pixel</link>
      <pubDate>Fri, 24 Feb 2017 13:00:43 +0000</pubDate>
      <dc:creator>Sinned800</dc:creator>
      <guid isPermaLink="false">20986@/two/discussions</guid>
      <description><![CDATA[<p>Hello Guys,</p>

<p>im quite fresh in the processing world and no native speaker so please be gentle :)</p>

<p>but direct to the Point:</p>

<p>Im would like to know  is there any possibilty to get an defined Z axis output of every pixel ? 
with the code below (copied from shiffman) i can get an matrix out of the kinect so is there any possibility to map every single pixel and send it to an arduino ?</p>

<pre><code>        import org.openkinect.freenect2.*;
        import org.openkinect.processing.*; //&lt;&gt;//

        Kinect2 kinect2;

        void setup() {
          size(32, 16, P2D);
          kinect2 = new Kinect2(this);
          kinect2.initVideo();
          kinect2.initDepth();
        }


        void draw() {
          background(0);

    PImage img = kinect2.getDepthImage();
    //image(img, 0, 0);

    for (int x = 0; x &lt; img.width; x++); {
    for (int y = 0; y &lt; img.height; x++);{
    int index = x +y * img.widht;
    float b = brightness (img.pixels[index]);
    float z = map(b, 0, 255, 250, -250);
    fill(255-b);
    pushMatrix();
    translate( x, y, z);
    rect( 0, 0,skip/2,skip/2);
    popMatrix();
        }
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>hi everyone. guys helpme. i want to scan from 100 to 380 of my video.height</title>
      <link>https://forum.processing.org/two/discussion/20654/hi-everyone-guys-helpme-i-want-to-scan-from-100-to-380-of-my-video-height</link>
      <pubDate>Sun, 05 Feb 2017 10:32:06 +0000</pubDate>
      <dc:creator>doni</dc:creator>
      <guid isPermaLink="false">20654@/two/discussions</guid>
      <description><![CDATA[<pre><code>import processing.video.*;
Capture video;


void setup() {
  size(640, 480);
  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, width, height);
  video.start();  
  noStroke();
  smooth();
}

void draw() {
  if (video.available()) {
    video.read();
    image(video, 0, 0, width, height); // Draw the webcam video onto the screen
    int brightestX = 0; // X-coordinate of the brightest video pixel
    int brightestY = 0; // Y-coordinate of the brightest video pixel
    float brightestValue = 0; // Brightness of the brightest video pixel
    // Search for the brightest pixel: For each row of pixels in the video image and
    // for each pixel in the yth row, compute each pixel's index in the video
    video.loadPixels();
    int index = 0;
    for (int y =0 ; y &lt; video.height; y++) {
      for (int x = 0; x &lt; video.width; x++) {
        // Get the color stored in the pixel
        int pixelValue = video.pixels[index];
        // Determine the brightness of the pixel
        float pixelBrightness = brightness(pixelValue);
        // If that value is brighter than any previous, then store the
        // brightness of that pixel, as well as its (x,y) location
        if (pixelBrightness &gt; brightestValue) {
          brightestValue = pixelBrightness;
          brightestY = y;
          brightestX = x;
           pixelBrightness = color(256);
        }
        index++;
      }
    }
    // Draw a large, yellow circle at the brightest pixel
    fill(255, 204, 0, 128);
    ellipse(brightestX, brightestY, 50, 50);
     text("brightestX: " + brightestX, 20,20);
      text("brightestY: " + brightestY, 20,40);
      text("brightnesslevel: " + brightestValue, 20, 60);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>question about what i did wrong</title>
      <link>https://forum.processing.org/two/discussion/20525/question-about-what-i-did-wrong</link>
      <pubDate>Sat, 28 Jan 2017 23:53:11 +0000</pubDate>
      <dc:creator>sLucas</dc:creator>
      <guid isPermaLink="false">20525@/two/discussions</guid>
      <description><![CDATA[<p>my Code:</p>

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

Capture video;



void setup() {
  size(640, 480);
  pixelDensity(1);
  frameRate(60);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[1]);
  video.start();
}

void captureEvent(Capture video) {
  video.read();
}



void draw() {

  video.loadPixels();
  image(video, 0, 0);
  grid();
}

void grid() {
  int square = 0;
  int nr = 20;
  int[] avg = new int[width * height];
  background(255, 0, 0);
  loadPixels();
  if (width % nr == 0 &amp; height % nr == 0) {
    for (int s1 = 0; s1 &lt; height; s1 += height/nr) {
      for (int s2 = 0; s2 &lt; width; s2 += width/nr) {

        for (int x = 0; x &lt; width/nr; x++) {
          for (int y = 0; y &lt; height/nr; y++) {
            square = (x + y * width) + s1 * width + s2;
            avg[square] = int(brightness(get(x + s2, y + s1 * width)));
            pixels[square] = color(avg[square]);
          }
        }

      }
    }
    updatePixels();
  }
}
</code></pre>

<p>END</p>

<p>when i run this code it only shows me a black screen. I already tried the same code with just slightly changed for() loops</p>

<pre><code>void grid() {
  int[] avg = new int[width*height]; 
  loadPixels();
  for (int x = 0; x &lt; width; x++) {
    for (int y = 0; y &lt; height; y++) {
      avg[x+y*width] = int(brightness(get(x,y)));
      pixels[x+y*width] = color(avg[x+y*width]);
    }
  }
  updatePixels();
}
</code></pre>

<p>and it worked 100% correct, so I assume the problem must be in the for() loops or how i used the variables s1 and s2, but I just can not find the mistake. Thanks in advance.</p>

<p>~sLucas</p>
]]></description>
   </item>
   <item>
      <title>Color theory between LCD and LED</title>
      <link>https://forum.processing.org/two/discussion/20231/color-theory-between-lcd-and-led</link>
      <pubDate>Fri, 13 Jan 2017 01:40:59 +0000</pubDate>
      <dc:creator>goodsignal</dc:creator>
      <guid isPermaLink="false">20231@/two/discussions</guid>
      <description><![CDATA[<p>Does anyone understand how color and brightness is processed for display monitors working in RGB space? For this conversation, I'm assuming <code>colorMode(RGB,255)</code>.</p>

<p>Analyzing readings for brightness(rgb) has me wondering why 
<code>brightness(color(200,200,0)) == brightness(color(200,0,0))</code></p>

<p>I've worked with LEDs quite a bit and by experience and knowledge of additive light theory, rgb(200,200,0) generally produces twice the lumen output as rgb(200,0,0). In other words it's twice as bright because two color dies are illuminated instead of one. I'm pretty sure most modern color monitors also produce color with additive light theory.</p>

<p>My assumption when calling brightness(rgb) would have been</p>

<pre><code>brightness(color(255,255,255)) = 255.0
brightness(color(255,255,0)) = 170.0
brightness(color(255,0,0)) = 85.0
</code></pre>

<p>Obviously I'm wrong with respect to working with Processing since all three of those =  255.0</p>

<p>So what's going on here? Is my confusion due to a misunderstanding of what <code>brightness()</code> represents? Or, are there behind the scene rules that Processing is accounting for to produce balanced output for LCD monitors? If so, what are they? And how are others managing color and brightness output when we intend to use LED displays for graphical output?</p>
]]></description>
   </item>
   <item>
      <title>webcam light-drawing</title>
      <link>https://forum.processing.org/two/discussion/19960/webcam-light-drawing</link>
      <pubDate>Wed, 28 Dec 2016 08:57:10 +0000</pubDate>
      <dc:creator>wnovotny</dc:creator>
      <guid isPermaLink="false">19960@/two/discussions</guid>
      <description><![CDATA[<p>...basically I want to go on with a tutorial I found. My aim is to draw a continous curve by capturing light(brigthness) via the webcam. 
The problem I have at the moment is that the drawn ellipse is always refreshed, so I don't see a curve but just a circle...
Thanks!</p>

<pre><code>import processing.video.*;
Capture cam;
int x,y;

void setup (){
  size (640,480);
  frameRate (30);
  background (0);

  printArray (Capture.list()); //choose Webcam, change according the size!
 //cam = new Capture (this, 640,480, "Logitech QuickCam Express/Go",30);
  cam = new Capture (this, 640,480, "Integrated Camera",30);
  cam.start();
}

void draw (){

  if (cam.available()){
    cam.read();
    cam.loadPixels();
    float maxBri = 0.0;
    int theBrightPixel=0;
    for (int i=0; i&lt;cam.pixels.length; i++){
      if(brightness(cam.pixels[i]) &gt; maxBri){ //find the brightest
        maxBri = brightness (cam.pixels[i]);
        theBrightPixel =i; //store id of brightest pixel
      }
    }
   x= theBrightPixel % cam.width; //find x with modolo
   y= theBrightPixel /cam.width; //find y with int, row

}
   image (cam,0,0);
   fill (255,0,0);
   ellipse (x,y,20,20);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to extract pictrure 0-255 value in a matrix</title>
      <link>https://forum.processing.org/two/discussion/19491/how-to-extract-pictrure-0-255-value-in-a-matrix</link>
      <pubDate>Sat, 03 Dec 2016 20:32:27 +0000</pubDate>
      <dc:creator>mdel</dc:creator>
      <guid isPermaLink="false">19491@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I want to extract the luminosity value of the pixels of greyscale images as a matrix in a .txt file, process them mathematicaly in a suitable program (e.g excel) and recombine them in a new image. I'm totaly ignorant about programming so any help would be of great help. Thanks</p>
]]></description>
   </item>
   <item>
      <title>Lagging video: CameraGettingStarted example</title>
      <link>https://forum.processing.org/two/discussion/16117/lagging-video-cameragettingstarted-example</link>
      <pubDate>Wed, 20 Apr 2016 06:05:30 +0000</pubDate>
      <dc:creator>kfrajer</dc:creator>
      <guid isPermaLink="false">16117@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>I was working with an android sample code accessing the camera and I notice it is lagging. Is that normal? I am using 5.0.1. and processing 3.0.2 on a Galaxy VI (no emulator). I am hopping to quantify color segments in the screen but the videos seems to skip frames. It feels like is playing one frame every 2 or 3 seconds instead of the desirable 30 fps that you get running in java mode (using an external camera - and not this specific example). Is there anything I could do to have better video rates?</p>

<p>Cheers,</p>

<p>Kf</p>

<pre><code>import android.os.Environment;
import ketai.camera.*;


KetaiCamera cam;

void settings() {
  fullScreen();
}

void setup() {
  orientation(LANDSCAPE);
  imageMode(CENTER);
  textSize(45);  
}
void draw() {  
  if(cam != null &amp;&amp; cam.isStarted()){
     image(cam, width/2, height/2, width, height);    
     text("Number of cams \n" +
      cam.getNumberOfCameras(),  0, 0, width/2-100, height/2);

    cam.loadPixels();
    int brightestX = 0; // X-coordinate of the brightest video pixel
    int brightestY = 0; // Y-coordinate of the brightest video pixel
    float brightestValue = 0; // Brightness of the brightest video pixel
     int index = 0;
    for (int y = 0; y &lt; cam.height; y++) {
      for (int x = 0; x &lt; cam.width; x++) {
        // Get the color stored in the pixel
        int pixelValue = cam.pixels[index];
        // Determine the brightness of the pixel
        float pixelBrightness = brightness(pixelValue);
        // If that value is brighter than any previous, then store the
        // brightness of that pixel, as well as its (x,y) location
        if (pixelBrightness &gt; brightestValue) {
          brightestValue = pixelBrightness;
          brightestY = y;
          brightestX = x;
        }
        index++;
      }
    }
    // Draw a large, yellow circle at the brightest pixel
    fill(255, 204, 0, 128);
    ellipse(brightestX, brightestY, 200, 200);       
  }
  else
    {
      background(128);
      text("Waiting for camera....touch to activate", 100, height/2);
    }
}

void onCameraPreviewEvent()
{
  cam.read();
}

// start/stop camera preview by tapping the screen
void mousePressed()
{
  //HACK: Instantiate camera once we are in the sketch itself
  if(cam == null)
      cam = new KetaiCamera(this, 640, 480, 24);

  if (cam.isStarted())
  {
    cam.stop();
  }
  else
    cam.start();
}
void keyPressed() {
  if(cam == null)
    return;

  if (key == CODED) {
    if (keyCode == MENU) {
      if (cam.isFlashEnabled())
        cam.disableFlash();
      else
        cam.enableFlash();
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Image generating code hangs up</title>
      <link>https://forum.processing.org/two/discussion/17960/image-generating-code-hangs-up</link>
      <pubDate>Wed, 24 Aug 2016 11:54:56 +0000</pubDate>
      <dc:creator>Luis93</dc:creator>
      <guid isPermaLink="false">17960@/two/discussions</guid>
      <description><![CDATA[<p>Hi all, i have the following code which seems to me alright:</p>

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


Serial myPort;  // Create object from Serial class

int layers=24;

int switches;

byte[] temp = new byte[4];


PImage[] source = new PImage[layers+1];      // Source image
PImage destination;  // Destination image

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

  myPort = new Serial(this, "/dev/tty.usbmodem621", 9600);


for(int n=0;n&lt;layers+1;n++){
  source[n] = loadImage("layer"+n+".jpg"); 
} 
  // The destination image is created as a blank image the same size as the source.
  destination = createImage(source[0].width, source[0].height, RGB);


  set();
}

void draw() {  
  background(255);

  if ( myPort.available() &gt; 0) {  // If data is available,

    switches = Integer.parseInt(myPort.readString());
    println(switches);
    if(switches==-9294){
    beginRecord(PDF,"output.pdf");
    destination=source[24];
    image(destination,0,0);
    set();
    print();
    }else{
        loop();
    beginRecord(PDF,"output.pdf");
    display();
    textSize(26);
    fill(0);
    text(switches,width-150,height-30);
    print();
    }
  }  
  /*switches=55;*/  
  display();

}

void set(){

destination.loadPixels();
  for (int x = 0; x &lt; destination.width; x++) {
    for (int y = 0; y &lt; destination.height; y++ ) {
      int loc = x + y*source[0].width;
      // Test the brightness against the threshold      
        destination.pixels[loc]  = color(255);  // White
    }
  }

}

void createimg(int n){

float threshold = 127;

  // We are going to look at both image's pixels
  source[n].loadPixels();
  destination.loadPixels();

  for (int x = 0; x &lt; source[n].width; x++) {
    for (int y = 0; y &lt; source[n].height; y++ ) {
      int loc = x + y*source[n].width;
      // Test the brightness against the threshold
      if (brightness(source[n].pixels[loc]) &lt; threshold) {
        destination.pixels[loc]  = color(0);
      }
    }
  }

  // We changed the pixels in destination
  destination.updatePixels();

}

void display(){

  // Display the destination
  image(destination,0,0);
  set();
}

void loop(){

  for(int i = 0; i &lt; layers; i++)
  {
    if(isBitOn(i, switches) &amp;&amp; (switches != 0))
    {
    createimg(i);
    }
  }
}

boolean isBitOn(int bit, long value)
{
  long mask = 1;
  mask = mask &lt;&lt; bit;
  if((value &amp; mask)&gt;0){
    return true;
  }else{
    return false;
  }
}

void print(){
endRecord();
saveFrame("img/test/bild-######.png");
open("printpdf.app");
}
</code></pre>

<p>When it stops, the error is "NumberFormatEcxeption: For input string:"xxxxx". Does anybody find the problem?
Thanks for the help!</p>
]]></description>
   </item>
   <item>
      <title>dithering results not perfectly white.</title>
      <link>https://forum.processing.org/two/discussion/17245/dithering-results-not-perfectly-white</link>
      <pubDate>Tue, 21 Jun 2016 10:36:09 +0000</pubDate>
      <dc:creator>corneel_cannaerts</dc:creator>
      <guid isPermaLink="false">17245@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I'm writing a custom dithering algorithm based on: <a href="http://www.tannerhelland.com/4660/dithering-eleven-algorithms-source-code" target="_blank" rel="nofollow">http://www.tannerhelland.com/4660/dithering-eleven-algorithms-source-code</a> &amp; <a href="https://github.com/dpiccone/dithering_algorithms" target="_blank" rel="nofollow">https://github.com/dpiccone/dithering_algorithms</a>. Somehow the pixels that are supposed to be white are not.  It seems to be related to how processing handles colors or brightness. A workaround is commented out in the code, but i'd like to understand why this is happening.</p>

<pre><code>PImage img;

float[][] errorDiffusion = {{1,0,1.0}};
float[][] floydSteinberg = {{-1, 1, 3.0/16}, {0, 1, 5.0/16}, {1, 0, 7.0/16}, {1, 1, 1.0/16}};
float[][] falseFloydSteinberg = {{0, -1, 3.0/8}, {1, 0, 3.0/8}, {1, 1, 2.0/8}};
float[][] atkinson = {{1, 0, 1.0/8}, {2, 0, 1.0/8}, {-1, 1, 1.0/8}, {0, 1, 1.0/8}, {1, 1, 1.0/8}, {0, 2, 1.0/8}};

void setup() {
  size(800, 800, JAVA2D);
  img = loadImage("mona.jpg");
  img = dither(img, falseFloydSteinberg);
  noStroke();
  noSmooth();
}

void draw() {
  background(255, 0, 0);
  image(img, 0, 0);

  color c = img.get(mouseX, mouseY);
  println(brightness(c));  
}

PImage dither(PImage inp, float[][] matrix) {
  PImage src = inp.copy();
  for (int x = 0; x &lt; src.width; x++) {
    for (int y = 0; y &lt; src.height; y++) {
      color oldpixel = src.get(x, y);
      color newpixel = findClosestColor(oldpixel);

      src.set(x, y, newpixel);

      float quant_error = brightness(oldpixel) - brightness(newpixel);

      for (int k=0; k&lt;matrix.length; k++) {   
        int xi = int(x+matrix[k][0]);
        int yi = int(y+matrix[k][1]);       
        src.set(xi, yi, color(brightness(src.get(xi, yi)) + matrix[k][2]* quant_error));
      }
    }
  }
//doing a second pass gives a workaround  
/*
  for (int x = 0; x &lt; src.width; x++) {
    for (int y = 0; y &lt; src.height; y++) {
      color oldpixel = src.get(x, y);
      color newpixel = findClosestColor(oldpixel);
      src.set(x, y, newpixel);
    }
  }
*/
  return src;
}

color findClosestColor(color c) {
  color r;
  if (brightness(c) &lt; 127) {
    r = color(0);
  } else {
    r = color(255);
  }
  return r;
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>