<?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 beginrecord() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=beginrecord%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:47:28 +0000</pubDate>
         <description>Tagged with beginrecord() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedbeginrecord%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How do I record the audio input to a new audio render using minim</title>
      <link>https://forum.processing.org/two/discussion/28028/how-do-i-record-the-audio-input-to-a-new-audio-render-using-minim</link>
      <pubDate>Wed, 30 May 2018 00:23:23 +0000</pubDate>
      <dc:creator>Aurelian24</dc:creator>
      <guid isPermaLink="false">28028@/two/discussions</guid>
      <description><![CDATA[<p>So, i´ve been tryng to make the minim recorder to record the audio from the Audioplayer object when is played without any succes.</p>

<p>Something like the combination of this 2 examples :</p>

<p><a href="http://code.compartmental.net/minim/audioplayer_method_play.html" target="_blank" rel="nofollow">http://code.compartmental.net/minim/audioplayer_method_play.html</a>
<a href="http://code.compartmental.net/minim/minim_method_createrecorder.html" target="_blank" rel="nofollow">http://code.compartmental.net/minim/minim_method_createrecorder.html</a></p>

<p>I´ve found similar threats but with no anwer to it :</p>

<p><a href="https://forum.processing.org/one/topic/minim-how-to-record-minim-s-output.html" target="_blank" rel="nofollow">https://forum.processing.org/one/topic/minim-how-to-record-minim-s-output.html</a></p>

<p>The audio plays just well but the recorder comes out empty. 
If I try the "createrecorder" example it works on recording the sounds created by minim, but I need it to record the sound getting them from the audio player. This is my greates attemp :</p>

<pre><code>import ddf.minim.*;
import ddf.minim.ugens.*;

Minim         minim;
AudioOutput   out;
AudioRecorder recorder;
AudioPlayer sonido;
void setup()
{
  size(512, 200, P3D);

  minim = new Minim(this);

  out = minim.getLineOut();
  sonido = minim.loadFile("fijo2.wav");
  sonido.loop();

  recorder = minim.createRecorder(out, "myrecording.wav");  
  textFont(createFont("Arial", 12));
}

void draw()
{
  background(0); 
  stroke(255);
}

void keyReleased()
{
  if ( key == 'r' ) 
  {
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
    }
    else 
    {
      recorder.beginRecord();
    }
  }
  if ( key == 's' )
  {
    recorder.save();
    println("Done saving.");
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Rendering text in SVG files</title>
      <link>https://forum.processing.org/two/discussion/26900/rendering-text-in-svg-files</link>
      <pubDate>Sun, 18 Mar 2018 10:55:16 +0000</pubDate>
      <dc:creator>mperes</dc:creator>
      <guid isPermaLink="false">26900@/two/discussions</guid>
      <description><![CDATA[<p>Hey folks, long time no see ;) I am developing a template engine using Processing so we can quit Illustrator when doing data-driven image generation. This little tool basically allows you to pick a template file and write a a bunch of strings loaded from a json file, saving a image for each entry in the json file. The images are exported as PNG, SVG and PDF.</p>

<p>Everything is working fine except when exporting the SVG, I am getting:
<strong>textMode(SHAPE) is not supported by this renderer.</strong></p>

<p>Text is being rendered as  tags inside the svg file instead of Shapes (as I would like to). Everything is good in with PDF and PNG exporting. Tried taking a look at the SVG renderer and it looked almost as a clone of the PDF renderer so that gave me no clue how to fix this issue. Here is my code snippet:</p>

<pre><code>void exportSVG(String entryId, String entryFont, boolean entryIsRTL, JSONArray data, JSONObject geometry) {
  String format = "svg";
  String filePath = EXPORT_PATH + format + "/" + templateFile + "_" + entryId + "." + format;
  PGraphics graphic = createGraphics(templateWidth, templateHeight, SVG, filePath);
  graphic.beginDraw();
  graphic.textMode(SHAPE);
  graphic.shape(templateShape, 0, 0, templateWidth, templateHeight);
  for (int i = 0; i &lt; data.size(); i++) {
    JSONArray stringData = data.getJSONArray(i);
    String fieldName = stringData.getString(0);
    String fieldValue = stringData.getString(1);
    if(!geometry.isNull(fieldName)) {
      JSONObject fieldGeometry = geometry.getJSONObject(fieldName);
      PFont myFont = createFont(entryFont, fieldGeometry.getInt("fontSize"));
      graphic.textFont(myFont);
      graphic.textLeading(fieldGeometry.getInt("leading"));
      graphic.fill(unhex(fieldGeometry.getString("color")));
      graphic.textAlign(alignment.get(fieldGeometry.getString("aligmentX")), alignment.get(fieldGeometry.getString("aligmentY")));
      graphic.text(fieldValue, fieldGeometry.getInt("x"), fieldGeometry.getInt("y"));
    }
  }
  graphic.dispose();
  graphic.endDraw();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Hi! My file wont export to PDF! what shall i do??</title>
      <link>https://forum.processing.org/two/discussion/26663/hi-my-file-wont-export-to-pdf-what-shall-i-do</link>
      <pubDate>Tue, 06 Mar 2018 02:55:27 +0000</pubDate>
      <dc:creator>Kafilah</dc:creator>
      <guid isPermaLink="false">26663@/two/discussions</guid>
      <description><![CDATA[<p>//variable colors and leaves
color background = color (255, 245, 245); //&lt;&gt;//
color blue = color(166, 171, 214, 80);
ArrayList  list = new ArrayList  ();</p>

<p>import processing.pdf.*;
boolean capture; //set a boolean for recording a PDF of a single frame;</p>

<p>void setup() {
  size(700, 700, P2D);
  background (background);
  smooth(8);<br />
}</p>

<p>void draw() {
  //if (capture) {
    //beginRecord(PDF, "frame-####.pdf");
  //}
    for(int i = 0; i &lt; list.size(); i++) {
    list.get(i).drawball();
    if(list.get(i).s - 7 &lt; 1 &amp;&amp; list.get(i).get) {
      list.remove(i);
    }<br />
  }</p>

<p>if (capture) {
    beginRecord(PDF, "frame-####.pdf");
  }</p>

<p>// icon click
 if (capture) {
     endRecord();
     capture = false;
   }
}</p>

<p>void mouseClicked() {
  list.add(new leaves(mouseX, mouseY, random(10, 30), PI));
}</p>

<p>//maintain branch distinction
//maybe if branches had their own colors
class leaves {
  float x, y, s, ix, iy, d;
  boolean get;
  leaves(float ixv, float iyv, float sv, float dv) {
    ix=ixv;
    iy=iyv;
    s=sv;
    x=ix;
    y=iy;
    d=dv;
  }</p>

<p>void drawball() {
    noStroke();
    ellipse(x, y, s, s);
    //fill(blue);
    fill( random(255), random(255), random(255), random(255)); 
    //different shading patterns inside the dots in illustrator</p>

<pre><code>x+=sin(d)*2;
y+=cos(d)*3;
get = dist(ix, iy, x, y) &gt; 50;
if(get &amp;&amp; s-random(0.25, .75) &gt; 0) {
  list.add(new leaves(x, y, s-10, random(PI/2, PI*1.5)));
  s-=random(0.5, 1);
}
</code></pre>

<p>}
}</p>

<p>void keyPressed() {
  //press the 's' key if you want to save a .tif in your sketch folder
  if (key == 's') {
    saveFrame("forest####.tif");
    }</p>

<p>if (key == 'c'){
    capture = true;
    }
  }</p>
]]></description>
   </item>
   <item>
      <title>PDF Export (Pattern Maker)</title>
      <link>https://forum.processing.org/two/discussion/25893/pdf-export-pattern-maker</link>
      <pubDate>Wed, 10 Jan 2018 03:01:32 +0000</pubDate>
      <dc:creator>digitalcoleman</dc:creator>
      <guid isPermaLink="false">25893@/two/discussions</guid>
      <description><![CDATA[<p>Hello all!</p>

<p>I have been making an app for my students called Pattern maker (<a rel="nofollow" href="https://github.com/digitalcoleman/generativeExamples/tree/master/patternMaker_v2">https://github.com/digitalcoleman/generativeExamples/tree/master/patternMaker_v2</a>)
which includes the ability to drag and drop svg files, create patterns with them, and export a pdf which we will later translate for a plotter.</p>

<p>The problem is that the more complex the svg file, the less likely that a pdf is generated. I do not know if there is a crazy lag time and that is affecting the button from the GUI or what, but some svg might take upwards of 30 clicks on the export button, and others never produce a pdf at all. Is there any way to better understand what is going on with the pdf export to know if it is working at all, so I know if it is a GUI or library issue?</p>

<p>Any ideas are appreciated!</p>

<pre><code>import controlP5.*; //add the GUI library
import drop.*; //add the drag and drop library
import processing.pdf.*; //add the pdf library

SDrop drop; //make an instance of the sDrop library

PShape myShape; //make a shape variable to hold the svg file

ControlFrame cf; //will help us make a second window for the controls

int space = 40; //some initial settings = spacing
float scl = 40.0; //the scale of each object
float noiseScale = 200.0; //the scale of the noise (how smooth)
float noiseEffect = 0.0; //the strength of the noise affecting the position
float noiseRot = 0.0; //the strength of the noise affecting the rotation
float seed = 1; //the noise seed
boolean pdf = false;
int pdfCount = 1; //starting number for the exported pdf

void settings(){
  size(800, 800); //setup our stage/canvas
}

void setup(){
  noFill();
  smooth();
  rectMode(CENTER); //for the starting rectangles, center them
  cf = new ControlFrame(this, 300, 300, "Controls"); //make a new window at 300 wide and 300 tall
  surface.setLocation(320, 10); //move the main window over to make room for the control window
  drop = new SDrop(this); //setup the drag and drop
}

void draw(){
  background(255);

  if(pdf)beginRecord(PDF, "pattern" + pdfCount + ".pdf"); //if the button is pressed, begin recording to make the pdf
  noFill();
  for(int x = space/2; x &lt; width; x+= space) { //iterate across the canvas
    for(int y = space/2; y &lt; width; y+= space) { //iterate down the canvas
      float nx = x + noiseEffect * 2*(noise(seed, y/noiseScale, x/noiseScale)-0.5); //compute the x position noise
      float ny = y + noiseEffect * 2*(noise(x/noiseScale, seed, y/noiseScale)-0.5); //compute the y position noise
      float rot = 4 * PI * (noise(x/noiseScale, y/noiseScale, seed)-0.5) * noiseRot; //compute the rotation noise
      pushMatrix();
      translate(nx, ny); //move the shape into place
      rotate(rot); //rotate the shape
      //scale(scl);
      if(myShape !=null){ //if we have dropped on an svg, then use it
        shape(myShape, 0, 0, scl, scl); //draw the svg
      }else{
        rect(0, 0, scl, scl); //otherwise, use some squares
        //ellipse(0, 0, scl, scl); //or some ellipses
      }
      popMatrix();
    }
  }
  if(pdf) {
    endRecord();
    pdfCount++;
    pdf = false;
  }
}

void dropEvent(DropEvent theDropEvent) { //this takes care of the drag and drop
   if(theDropEvent.isFile()) {
    // for further information see
    // <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html" target="_blank" rel="nofollow">http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html</a>
      String myFile = theDropEvent.filePath(); //get the filepath
      myShape = loadShape(myFile); //load the svg into our shape variable
   }
}

//everything below this makes the control window

class ControlFrame extends PApplet {

  int w, h;
  PApplet parent;
  ControlP5 cp5;

  public ControlFrame(PApplet _parent, int _w, int _h, String _name) {
    super();   
    parent = _parent;
    w=_w;
    h=_h;
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  public void settings() {
    size(w, h);
  }

  public void setup() {
    surface.setLocation(10, 10);
    cp5 = new ControlP5(this);

    cp5.addSlider("spacing")
       .plugTo(parent, "space")
       .setRange(1, 400)
       .setValue(40)
       .setPosition(20, 20)
       .setSize(200, 30);

    cp5.addSlider("scaling")
       .plugTo(parent, "scl")
       .setRange(10.0, 400.0)
       .setValue(40.0)
       .setPosition(20, 60)
       .setSize(200, 30); 

    cp5.addSlider("noise scale")
       .plugTo(parent, "noiseScale")
       .setRange(20.0, 1000.0)
       .setValue(200.0)
       .setPosition(20, 100)
       .setSize(200, 30);

    cp5.addSlider("noise effect - pos")
       .plugTo(parent, "noiseEffect")
       .setRange(0.0, 300.0)
       .setValue(0.0)
       .setPosition(20, 140)
       .setSize(200, 30);

    cp5.addSlider("noise effect - rot")
       .plugTo(parent, "noiseRot")
       .setRange(0.0, 1.0)
       .setValue(0.0)
       .setPosition(20, 180)
       .setSize(200, 30);

    cp5.addSlider("noise seed")
       .plugTo(parent, "seed")
       .setRange(0.0, 10.0)
       .setValue(0.0)
       .setPosition(20, 220)
       .setSize(200, 30);

    cp5.addButton("exportPDF")
       .plugTo(parent, "pdf")
       .setSwitch(false)
       .setPosition(20, 260)
       .setSize(50, 30);
  }

  void draw() {
    background(190);
  }

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Unknown issue with drawing graph with data send by arduino to Raspberry Pi</title>
      <link>https://forum.processing.org/two/discussion/24749/unknown-issue-with-drawing-graph-with-data-send-by-arduino-to-raspberry-pi</link>
      <pubDate>Thu, 26 Oct 2017 11:51:12 +0000</pubDate>
      <dc:creator>maxim221</dc:creator>
      <guid isPermaLink="false">24749@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>I'm using arduino as ADC, which sends data through UART to Raspberry Pi model B, which draws a graph on 7'display, connected via HDMI.</p>

<p>So I've got a strange problem. 
<img src="https://forum.processing.org/two/uploads/imageupload/419/7UPQJMK8SSJH.PNG" alt="pic1" title="pic1" />
Randomly straight lines appear from current measuring point to top of the screen.</p>

<p>I was thinking about mistakes or zero values or Nan values of something like that. But it is not-)</p>

<p>Lines drawn like that:</p>

<p><code>line(xPos-1, height-lastfValue, xPos, height - fValue);</code></p>

<p>I was trying to filter it out by using such a construction:</p>

<pre><code>if(fValue &lt;= 0 || (height - fValue) &gt; height || ((fValue - lastfValue)*(fValue - lastfValue)/2) &gt; lastfValue + 5 ){
    fValue = lastfValue;
    }
</code></pre>

<p>It helped a little, but did't became a solution for my problem. So I tried to figure out a problem and added pdf export of what I see on the screen and logging values of "fValue" to console and find out:</p>

<p>The values:</p>

<pre><code>145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
146.04106
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
145.7478
</code></pre>

<p>and the graph:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/787/SFMDC2MDA7NK.jpg" alt="-DLm7tClrdw" title="-DLm7tClrdw" /></p>

<p>As you can see there only one different value and two peaks on the graph.</p>

<p>Does anyone know how to deal with it and get a correct graph?</p>

<p>This code works the same way on my notebook..</p>

<p>Here is the code I use for processing on raspberry Pi:</p>

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

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph

float fValue;
float lastfValue;
boolean newVal = false;

void setup () {
  size(1000, 300);
 // fullScreen();

  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 115200);
  myPort.bufferUntil('\n');
  background(28,28,28);
  beginRecord(PDF, "rawData.pdf");
}

void draw () {
//  if (newVal) {
    stroke(255, 16, 0);
   // size(100, 100, P3D);
   // noSmooth();
    //ellipse(xPos, height - fValue, 1, 1);
    line(xPos-1, height-lastfValue, xPos, height - fValue);
    println(fValue);
    lastfValue = fValue;
    //fValue = (fValue - 3);
    //stroke(28, 28, 28);
    //point(xPos, height - fValue);
    if (++xPos &gt;= width) {
      xPos = 0;
      background(28,28,28);
//    }
//    newVal = false;
  }
}

void serialEvent (Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    fValue = float(inString);
    fValue = map(fValue, 0, 1023, 0, height);
    //if(fValue &lt;= 0 || (height - fValue) &gt; height || ((fValue - lastfValue)*(fValue - lastfValue)/2) &gt; lastfValue + 5 ){
    //fValue = lastfValue;
    //}
  }
//  newVal = true;
}
  void keyPressed() {
  if (key == ' ') {
    endRecord();
    exit();
  }
}
</code></pre>

<p>Here is the code for arduino Uno that I use as ADC:</p>

<pre><code>// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>problem exporting .ase - generative design library</title>
      <link>https://forum.processing.org/two/discussion/25454/problem-exporting-ase-generative-design-library</link>
      <pubDate>Fri, 08 Dec 2017 10:29:52 +0000</pubDate>
      <dc:creator>sinanatra</dc:creator>
      <guid isPermaLink="false">25454@/two/discussions</guid>
      <description><![CDATA[<p>Hi, i was trying to  work with this <a rel="nofollow" href="https://github.com/generative-design/Code-Package-Processing-3.x">library</a>, but  i can't manage to export a proper .ase file. Illustrator never opens that, and if i print the color array i only get: <code>[I@58bd518a</code></p>

<p>Here's is my code:</p>

<pre><code>    import generativedesign.*;
    import processing.pdf.*;
    import java.util.Calendar;
    boolean savePDF = false;
    PImage img; 
    color[] colors;
    String sortMode = null; 

    void setup() {
      size(500, 500);
      colorMode(HSB, 360, 100, 100, 100);
      noStroke();
      noCursor();
      img = loadImage("pic2.jpg"); 
      img.resize(0, 500);
    }


    void draw() {
      if (savePDF) {
        beginRecord(PDF, timestamp()+".pdf");
        colorMode(HSB, 360, 100, 100, 100);
        noStroke();
      }

      int tileCount = width / 150; 

      float rectSize = width / float(tileCount); 
      int i = 0; 
      colors = new color[tileCount*tileCount]; 
      for (int gridY=0; gridY&lt;tileCount; gridY++) {
        for (int gridX=0; gridX&lt;tileCount; gridX++) {
          int px = (int) (gridX * rectSize); 
          int py = (int) (gridY * rectSize); 
          colors[i] = img.get(px, py);
          i++;
        }
      }



      // sort colors

       sortMode = GenerativeDesign.HUE;
      if (sortMode != null) colors = GenerativeDesign.sortColors(this, colors, sortMode); 
      // draw grid
      i = 0;
      for (int gridY=0; gridY&lt;tileCount; gridY++) {
        for (int gridX=0; gridX&lt;tileCount; gridX++) {
          fill(colors[i]);                                        
          rect(gridX*rectSize, gridY*rectSize, rectSize, rectSize);
          i++;
        }
      }

      if (savePDF) {
        savePDF = false;
        endRecord();
      }
    }


    void keyReleased() {
      if (key == '4') sortMode = null;
      if (key == '5') sortMode = GenerativeDesign.HUE;
      if (key == '6') sortMode = GenerativeDesign.SATURATION;
      if (key == '7') sortMode = GenerativeDesign.BRIGHTNESS;
      if (key == '8') sortMode = GenerativeDesign.GRAYSCALE;
      if (key=='s' || key=='S') savePDF = true;
      if (key=='c') {
        GenerativeDesign.saveASE(this, colors, "ase/"+timestamp()+".ase"); 
        print("salvato");
        exit();
      }
    }


    // timestamp
    String timestamp() {
      Calendar now = Calendar.getInstance();
      return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
    }
</code></pre>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>how can i change the colors of the ellipses with keyPressed?</title>
      <link>https://forum.processing.org/two/discussion/25421/how-can-i-change-the-colors-of-the-ellipses-with-keypressed</link>
      <pubDate>Wed, 06 Dec 2017 20:19:07 +0000</pubDate>
      <dc:creator>giorgiox</dc:creator>
      <guid isPermaLink="false">25421@/two/discussions</guid>
      <description><![CDATA[<blockquote class="Quote">
  <p>hello, im having trouble with this code, i would really appreciate it if someone can help me :D
  this is the code</p>
</blockquote>

<pre><code>import processing.pdf.*; //importar la liberria para trabajar con pdf

boolean imprimir;

color c; 

float a,e,i,o;


void setup() {
&gt; 
  size(500, 500);//tamaño de canvas

  a=(#F293F7);

  e=(#56E1F2);

  i=(#84E54C);

  o=(#FF8F17);
}


void draw() {

  if (imprimir==true) {

    beginRecord(PDF, "fotos.pdf");//iniciar la creacion del archivo

  }
  background(mouseX, 115, 300); // varía color del fondo

  for (int x=0; x&lt;500; x+=60) { //posicion circulos

    for (int y=0; y&lt;500; y+=40) {

      circulos(c, x, y, 5);//llamado de funciones

            square(233, x, y);
    }
  }
  //float a=(#F293F7);

  //float e=(#56E1F2);

  //float i=(#84E54C);

  //float o=(#FF8F17);

  c= color(a, e, i, o);

  noFill(); 

  strokeWeight(5);

  triangle(400, 350, 100, 350, 250, 150); //triangulo más grande

  strokeWeight(3);

  triangle(325, 250, 250, 350, 175, 250); 

  triangle(400, 350, 213, 300, 250, 250); 

  triangle(288, 300, 100, 350, 250, 250); 

  triangle(287, 300, 213, 300, 250, 150);


  if (imprimir==true) {

    endRecord();//cerrar el archivo

    imprimir=false;
  }
}


void circulos(color c, float x, float y, float t) { //funcion del circulo

  fill(c);

  ellipse(x+20, y, t, t);
}


void square ( color c, float x1, float x2) {    //funcion del cuadrado

  noFill();         //sin relleno

  strokeWeight (1);// grosor linea

  rect( x1-40, x2-40, 60, 80);//cuadrados
}

void keyPressed() {

  if (key=='a') {

fill( random(255));

  }


   else if (key=='e') {

    color (#56E1F2);

  } else if (key=='i') {

    color (#84E54C);

  } else if (key=='o') {

    color (#FF8F17);
  }

    imprimir=true;
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to extract random chunks of consecutive data</title>
      <link>https://forum.processing.org/two/discussion/23554/how-to-extract-random-chunks-of-consecutive-data</link>
      <pubDate>Sat, 22 Jul 2017 10:47:30 +0000</pubDate>
      <dc:creator>mfuster</dc:creator>
      <guid isPermaLink="false">23554@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I'm new to Processing and have run into a need that I can't work me head around.
I am loading data from a csv into a Processing sketch. I want the sketch to go through the data and select, at random, a 10 seconds (consecutive) extract of the data (which is equivalent to 10 rows).</p>

<p>What is the best way to go on about this? Do I set "i" to be a random number (constrained to length of rows) and then ask it to select the 10 rows after that? Or is there another way?</p>

<p>The following is the code I have:</p>

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

String filename = "210717 at 172333.csv";
String [] rawData;
int [] Time = new int[10];
//accelerometer data
int [] ADataX = new int[10];
int [] ADataY = new int[10];
int [] ADataZ = new int[10];
int AMinX, AMaxX;
int AMinY, AMaxY;
int AMinZ, AMaxZ;


int margin, graphHeight;
float xSpacer;
//ACCELEROMETER
PVector [] APositionsX = new PVector[10];
PVector [] APositionsY = new PVector[10];
PVector [] APositionsZ = new PVector[10];


void setup() {
  size(800,300);
  processData();
  beginRecord(PDF, "Worldlines(X,Y,Z)-01.pdf"); 
}

void draw () {
  background(20);
  drawGUI();
  endRecord();
}

  void drawGUI(){

    //ACCELEROMETER
  for (int i=0; i&lt;APositionsX.length; i++){
 stroke(200,100);
 line(APositionsX[i].x, margin, APositionsX[i].x, height-margin); // lines of same location

 if (i&gt;0) {
   stroke(255);
 line(APositionsX[i].x, APositionsX[i].y, APositionsX[i-1].x, APositionsX[i-1].y); 
  line(APositionsY[i].x, APositionsY[i].y, APositionsY[i-1].x, APositionsY[i-1].y);
  line(APositionsZ[i].x, APositionsZ[i].y, APositionsZ[i-1].x, APositionsZ[i-1].y);
  }
  }
}

void processData () {

  rawData = loadStrings(filename); //load Strings from file
  //parse through data
  for(int i=1; i&lt;rawData.length; i++) { 
  String [] thisRow = split(rawData[i],",");
  //convert to integers per column
  ADataX [i-1] = int(thisRow[0]);
  ADataY [i-1] = int(thisRow[1]);
  ADataZ [i-1] = int(thisRow[2]);

  }

 //ACCELEROMETER
 AMinX = min(ADataX); // find min value for XData
 AMaxX = max(ADataX); //find max value for XData
 AMinY = min(ADataY); // find min value for XData
 AMaxY = max(ADataY); //find max value for XData
 AMinZ = min(ADataZ); // find min value for XData
 AMaxZ = max(ADataZ); //find max value for XData

 margin = 50;
 graphHeight = (height-margin)-margin; // set height of y axis
 xSpacer = (width-margin)/Time.length;

  //ACCELEROMETER
  for (int i=0; i&lt;ADataX.length;i++){
    float adjADataX = map(ADataX[i], AMinX, AMaxX, 0, graphHeight); // map values within graph
    float yPos = height-margin - adjADataX;    
    float xPos = margin + (xSpacer *i);
   APositionsX[i]= new PVector (xPos, yPos);
}
 for (int i=0; i&lt;ADataY.length;i++){
    float adjADataY = map(ADataY[i], AMinY, AMaxY, 0, graphHeight); // map values within graph
    float yPosY = height-margin - adjADataY;    
    float xPosY = margin + (xSpacer *i);
    APositionsY[i]= new PVector (xPosY, yPosY);
}

 for (int i=0; i&lt;ADataZ.length;i++){
    float adjADataZ = map(ADataZ[i], AMinZ, AMaxZ, 0, graphHeight); // map values within graph
    float yPosZ = height-margin - adjADataZ;    
    float xPosZ = margin + (xSpacer *i);
    APositionsZ[i]= new PVector (xPosZ, yPosZ);
  }

}
</code></pre>

<p>Any help or suggestions would be greatly appreciated! Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Starting and stopping PDF recording in an animation</title>
      <link>https://forum.processing.org/two/discussion/23485/starting-and-stopping-pdf-recording-in-an-animation</link>
      <pubDate>Mon, 17 Jul 2017 15:15:27 +0000</pubDate>
      <dc:creator>grahamnewman</dc:creator>
      <guid isPermaLink="false">23485@/two/discussions</guid>
      <description><![CDATA[<p>Can you please help me. I am trying to control where I begin and end recording of a multiple frame (into one file) PDF in order to capture a segment of the animation. Currently the recording starts automatically once the animation starts playing - I want to be able to control this "in point", presumably with pressing a key e.g. "s". I can stop the animation, all ok, and it writes the pdf; I just need to able to control when I start it. Any help appreciated!</p>

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


ArrayList&lt;Snake&gt;snake;
float x,y;
float t;
float count = 0;
int delay = 0;

void setup(){
  beginRecord(PDF, "everything.pdf");


 size(500,500);
 smooth();
 snake = new ArrayList&lt;Snake&gt;();
 noStroke();
}


void draw(){
  background(6,7,175);
  translate(width/2, height/2);
  delay++;
  if(delay&gt;=5){
    count++;
    delay = 0;
    if(count&lt;=80){
      snake.add(new Snake(count));
    }
  }
  for(Snake s : snake){
    s.update();
    s.display();
  }
}

void keyPressed() {
  if (key == 'q') {
    endRecord();
    exit();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Save pdf with "save as" dialog</title>
      <link>https://forum.processing.org/two/discussion/23467/save-pdf-with-save-as-dialog</link>
      <pubDate>Sun, 16 Jul 2017 15:44:01 +0000</pubDate>
      <dc:creator>marsman</dc:creator>
      <guid isPermaLink="false">23467@/two/discussions</guid>
      <description><![CDATA[<p>This might be a noob question but I'd like to save a pdf to a user specified folder. I could get both, saving pdfs (with the processing.pdf library) and getting a save as dialog (with selectOutput) to work but putting those two together gives me a nullPointerException.</p>

<p>For now, I'm just using my own "drawAndSave" method and don't even use the user specified location. If I put "drawAndSave()" inside the keyPressed() Method, it works, just not inside the selectOutput callback.</p>

<p>here is my code</p>

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

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

void draw(){

}

void keyPressed(){
  if(key == 'q'){
    exit();
  }else if(key == 's'){
    selectOutput("Select desination;", "savePdf");
  }
}

public void drawAndSave(){
  beginRecord(PDF, "newFile.pdf");
  background(102);
  pushMatrix();
    // draw something
  popMatrix();
  endRecord();
}

void savePdf(File destination){
  if(destination != null){
    drawAndSave();
  }
}
</code></pre>

<p>Thank you very much</p>
]]></description>
   </item>
   <item>
      <title>I have a current code but I need to make the outer squares move, please help</title>
      <link>https://forum.processing.org/two/discussion/22759/i-have-a-current-code-but-i-need-to-make-the-outer-squares-move-please-help</link>
      <pubDate>Thu, 25 May 2017 15:10:53 +0000</pubDate>
      <dc:creator>KingSpagooter</dc:creator>
      <guid isPermaLink="false">22759@/two/discussions</guid>
      <description><![CDATA[<pre><code>// =================================================================
//Variables
StopWatchTimer sw;
float x = 0;
float y = 100;
float speed = 1;
// =================================================================
// Main
void setup() {
  size(700, 560);
  println (millis());
  sw = new StopWatchTimer();
  sw.start();
  rectMode(CENTER);
}
// Draw
void draw () {
  time();
  println(mouseX);
  println(mouseY);
  stroke (153);
  fill (204, 102, 0);
  rect (555, 275, 50, 50);
  rect (345, 475, 50, 50);
  rect (115, 275, 50, 50);
  rect (345, 75, 50, 50);
  frame.setTitle(int(frameRate) + " fps");
  fill (235, 235, 0);
  noStroke();
  rect (mouseX, mouseY, 30, 30);
}
// =================================================================
// Other
void time() {
  background(#C9C9C9);
  fill(#000000);
  textAlign(CENTER);
  text(nf(sw.minute(), 2)+":"+nf(sw.second(), 2), 656, 14);
}
// =================================================
// classes
class StopWatchTimer {
  int startTime = 0, stopTime = 0;
  boolean running = false; 
  void start() {
    startTime = millis();
    running = true;
  }
  void stop() {
    stopTime = millis();
    running = false;
  }
  int getElapsedTime() {
    int elapsed;
    if (running) {
      elapsed = (millis() - startTime);
    } else {
      elapsed = (stopTime - startTime);
    }
    return elapsed;
  }
  int second() {
    return (getElapsedTime() / 1000) % 60;
  }
  int minute() {
    return (getElapsedTime() / (1000*60)) % 60;
  }
}
// ====================================================
//High Rez
void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, JAVA2D);
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
//=======================================================
//collision 
boolean mouseOverRect(int x, int y, int w, int h) {
  return (mouseX &gt;= x &amp;&amp; mouseX &lt;= x+w &amp;&amp; mouseY &gt;= y &amp;&amp; mouseY &lt;= y+h);
}
// =====================================================
void move() {
  x = x + speed;
  if (x &gt; width) {
    x = 0;
  }
}
void display() {
  rect(x,y,30,10);
}``
</code></pre>
]]></description>
   </item>
   <item>
      <title>Fisica library - exporting results in vector ( PDF or SVG)?</title>
      <link>https://forum.processing.org/two/discussion/22969/fisica-library-exporting-results-in-vector-pdf-or-svg</link>
      <pubDate>Wed, 07 Jun 2017 01:17:58 +0000</pubDate>
      <dc:creator>bigblackgnaoui</dc:creator>
      <guid isPermaLink="false">22969@/two/discussions</guid>
      <description><![CDATA[<p>hello all,
i am new to processing and Fisica library. i wrote a little program for simulating bodies falling on a static one. ( very simple one), the shapes are geometric SVG that i import ( using lines from an existing example). everything is working fine, at the end of the simulation i am trying to export the result to vector file ( PDF would be perfect).
exporting PDF is not working and i can figure out how to do it , is there any possible solution?)
i thought about solving the problem by myself, so the solution i thought about is getting the position , rotation , and scale of every existing body in the simulation and redrawing everything as polygons which will get me the same result but with the possibility of exporting to PDF this time. when i use the Fpoly.getX() in the draw loop i get a nullPointerException.
so my question is :
- is there a way to export to PDF in Fisica?
- if  not, can you help me with the coordinate thing at the end of my simulation, getX(), getY(),...</p>

<p>to make it simple i wrote the sketch with just one shape.</p>

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

        import fisica.*;
        import geomerative.*;


        FWorld world;
        FPoly poly;

        String filename = "zel1.svg";
        RShape m_shape;
        RShape fullSvg;
        RShape outline;
        RPoint[] points;

        float xx,yy;


        void setup(){
         size(400,400);
         smooth();
         frameRate(60);
         Fisica.init(this);
         Fisica.setScale(10);
         RG.init(this);
         RG.setPolygonizer(RG.ADAPTATIVE);
         FPoly poly = new FPoly();
         world = new FWorld();
         world.setEdges(this,color(0));
         world.setGravity(0,300);
         RShape fullSvg = RG.loadShape(filename);
         RShape outline = fullSvg.getChild("outline");


         RPoint[] points = outline.getPoints();

         for (int i=0; i&lt;points.length; i++) { poly.vertex(points[i].x, points[i].y);}


          poly.setFill(120, 30, 90);
          poly.setPosition(width/2,50);     
          poly.setDensity(10);
          poly.setRestitution(0.5);



              world.add(poly);
                xx=poly.getX(); // it is working here
                println(xx);

        }

        void draw() {


          background(255);

          world.step();

          world.draw(this);
          yy=poly.getY(); // getting an NPE erro here
          xx= poly.getX();// getting an NPE erro here


        }
</code></pre>
]]></description>
   </item>
   <item>
      <title>multi page PDF. / getting blank page every 5 pages</title>
      <link>https://forum.processing.org/two/discussion/22702/multi-page-pdf-getting-blank-page-every-5-pages</link>
      <pubDate>Sun, 21 May 2017 13:07:23 +0000</pubDate>
      <dc:creator>Johnny_coder</dc:creator>
      <guid isPermaLink="false">22702@/two/discussions</guid>
      <description><![CDATA[<p>Wrote this little program that takes a master image (local), splits it into pages (because it's big), and reproduces it with tiles (taken from Flikr) based on averaged colors. On the back of each sheet is a page number, so we know ho to put them back order. All works great! very pleased! But for some reason, i get a blank page every 5 pages... why? Master image size is currently 4771 x 3181px</p>

<p>Also, this code probably needs some optimization, but that's another topic.</p>

<pre><code>/**
 * This code is copyright (c) Mathias Markl 2016 (the imageLoader part)
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see &lt;<a href="http://www.gnu.org/licenses/&gt;" target="_blank" rel="nofollow">http://www.gnu.org/licenses/&gt;</a>.
 */

import at.mukprojects.imageloader.*;
import at.mukprojects.imageloader.flickr.*;
import at.mukprojects.imageloader.image.*;

import processing.pdf.*;


PGraphicsPDF pdf;


ImageLoader loader;
ImageList list;
Image img;

String apiKey = "xxxx";
String apiSecret = "xxxx";

PImage master = new PImage();
PImage cover = new PImage();

int maxImages = 50;
int detail = 50;
int loaderOn = 1;
int extra;

PImage[] myImages = new PImage[50];

StringList imageSorter = new StringList(0);
int c=0;
int i=0;
int j =0;
int k =0;
int n =0;
int o=0;

//// Image Thingies

PImage baseImage;
int baseIndex=5;
int maxHeight=900;
int maxWidth=900;

int rounderY;
int rounderX;

IntList rTile = new IntList(0);
IntList gTile = new IntList(0);
IntList bTile = new IntList(0);
int rBase;
int gBase;
int bBase;
IntList cRVar = new IntList(0);
IntList cGVar = new IntList(0);
IntList cBVar = new IntList(0);
IntList cVar = new IntList(0);
IntList targetArray = new IntList(0);

int target;
int page=1;
PFont noPage;

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

  loader = new FlickrLoader(this, apiKey, apiSecret);
  list = loader.start("sunset", false, 60*1000);

  master=loadImage("master.jpg");

  pdf = (PGraphicsPDF)beginRecord(PDF, "Lines.pdf");

  frameRate (60);
}

void draw() {


  if (loaderOn==1) {
    println("retrieved "+list.size()+" photos");
    //println(list.getIds());


    // Remove Duplicates

    if (list.size()==maxImages) {
      for (int b=0; b&lt;maxImages; b++) {
        if (imageSorter.size()==0) {
          img = list.getImage(k);
          imageSorter.append(img.getImgUrl());
          k++;
        } else if (imageSorter.size()&gt;0) {
          img = list.getImage(k);
          if (imageSorter.get(imageSorter.size()-1)==img.getImgUrl()) {
            k++;
          } else {
            imageSorter.append(img.getImgUrl());
            k++;
          }
        }
      }


      // Resizing all the funzies!

      println("LOADING IMAGES INTO PIMAGE ARRAY AND RESIZING");

      for (int i=0; i&lt;imageSorter.size(); i++) {
        myImages[i]=loadImage(imageSorter.get(i), "jpg");
        myImages[i].resize(detail, detail);
      }


      // Tile Pixel Averaging Baby Boy

      println("LOADING AND AVERAGING TILE PIXEL COLORS");

      for (int i=0; i&lt;imageSorter.size(); i++) {
        myImages[i].loadPixels();
        color r = 0, g = 0, b = 0;

        for (color c : myImages[i].pixels) {
          r += c &gt;&gt; 020 &amp; 0xFF;
          g += c &gt;&gt; 010 &amp; 0xFF;
          b += c        &amp; 0xFF;
        }

        r /= myImages[i].pixels.length;
        g /= myImages[i].pixels.length;
        b /= myImages[i].pixels.length;

        rTile.append(r);
        gTile.append(g);
        bTile.append(b);
      }
      println("DONE");
      loader.stop();
      list=null;
      loaderOn=0;
    }
  }



  // Fonctions répetées à chaques page //


  if (loaderOn==0) {

    // Découpage du master en pages (imageBase)

    for (int v=0; v&lt;master.height; v+=height) {
      for (int w=0; w&lt;master.width; w+=width) {


        baseImage=master.get(v, w, width, height);


        // Découpage de la page en détails




        for (i=0; i&lt;baseImage.width; i+=detail) {
          for (j=0; j&lt;baseImage.height; j+=detail) {

            println("LOADING AND AVERAGING DETAIL COLORS"+" "+"DETAIL NO"+" "+(i+j));

            PImage newImg = baseImage.get(i, j, detail, detail);

            // Analyze de la couleur de chaque détail


            newImg.loadPixels();

            color rBase = 0, gBase = 0, bBase = 0;

            for (color c : newImg.pixels) {
              rBase += c &gt;&gt; 020 &amp; 0xFF;
              gBase += c &gt;&gt; 010 &amp; 0xFF;
              bBase += c        &amp; 0xFF;
            }

            rBase /= newImg.pixels.length;
            gBase /= newImg.pixels.length;
            bBase /= newImg.pixels.length;

            if ((rBase+gBase+bBase)==0) {
              fill(255);
              noStroke();
              rect(i, j, detail, detail);
            } else {

              // Calcule de détail le plus près de l'image de base

              println("ANALYSING TILE COLOR PROXIMITY");


              for (k=0; k&lt;maxImages; k++) {
                cRVar.append(abs(rBase-rTile.get(k)));

                cGVar.append(abs(gBase-gTile.get(k)));

                cBVar.append(abs(bBase-bTile.get(k)));

                cVar.append(cRVar.get(k)+cGVar.get(k)+cBVar.get(k));

                println("APPROX TILE NO"+k );
              }

              target = cVar.index(cVar.min());
              println("MATHCHING TILE="+target);
              image(myImages[target], i, j);   
              println("CLEARING ALL VARIABLES");

              c=o;

              k=0;
              n=o;
              o=0;

              cRVar.clear();
              cGVar.clear();
              cBVar.clear();
              cVar.clear();

              println("PRINTING TILE "+(i+j));
            }
          }
        }
        i=0;
        j=0;
        //baseImage.resize(0, 250);
        //image(baseImage, width-baseImage.width, height-baseImage.height);

        pdf.nextPage();

        PFont noPage = createFont("Helvetica", 100, true);
        textFont(noPage, 500);
        fill(225);
        textAlign(CENTER, CENTER);
        text(page, width/2, height/2);

        pdf.nextPage();
        page++;
      }
    }
    cover=master;

    if (cover.width&gt;cover.height) {
      cover.resize(width-200, 0);
      rounderY = (cover.height%20);
      cover.resize(width-200, cover.height-rounderY);
    } else if (cover.width&lt;cover.height) {
      cover.resize(0, height-200);
      rounderX = (cover.width%20);
      cover.resize(cover.width-rounderX, height-200);
    }
    PFont noPage = createFont("Helvetica", 100, true);
    textAlign(CENTER, CENTER);
    textFont(noPage, 20);
    text("Mosaïc Poster Maker", width/2, ((height-cover.height)/2)-100);
    text("Jonathan Mélançon", width/2, ((height+cover.height)/2)+100);
    imageMode(CENTER);
    image(cover, width/2, height/2);

    endRecord();
    println("PDF DONE!");
    exit();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to get 4 mirrored quadrants</title>
      <link>https://forum.processing.org/two/discussion/21978/how-to-get-4-mirrored-quadrants</link>
      <pubDate>Thu, 13 Apr 2017 16:27:23 +0000</pubDate>
      <dc:creator>k8e9</dc:creator>
      <guid isPermaLink="false">21978@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm working on a final project for a class and I want to create an interactive piece with 4 mirrored quadrants. I found code to get the left half to reflect on the right half of the composition.  Any suggestions on how I can get the bottom half to mirror the top half as well?</p>

<pre><code>float r, w;
PImage leftHalf;


import processing.pdf.*;

void setup(){
  size(720,720);
  background(255);
  frameRate(1);

  beginRecord(PDF, "P4Reflect-1.pdf");
}

void draw(){
  r = random(0,360);
  w = random(5,50);
  fill(75,0,130);
  stroke(w);
  line(0, r, mouseX, mouseY);
    leftHalf = get(0, 0, width/2, height);
  translate(width, 0);
  scale(-1, 1);
  image(leftHalf, 0, 0);
}

void mousePressed(){
  endRecord();
  exit();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Does the PDF library only work in ellipseMode(CENTER)? Can you change it somehow</title>
      <link>https://forum.processing.org/two/discussion/21380/does-the-pdf-library-only-work-in-ellipsemode-center-can-you-change-it-somehow</link>
      <pubDate>Mon, 13 Mar 2017 17:39:05 +0000</pubDate>
      <dc:creator>jbounds6</dc:creator>
      <guid isPermaLink="false">21380@/two/discussions</guid>
      <description><![CDATA[<p>Hey I am trying to make a program that uses some vectors and I am having troubles using the ellipseMode(RADIUS)
with the PDF library it seems to change the draw function back to ellipseMode(CENTER). Or at least it appears to be doing that, any information would be helpful.</p>

<blockquote class="Quote">
  <p>import processing.pdf.*;</p>
  
  <p>boolean record;</p>
  
  <p>void setup() {<br />
    size(500, 500);<br />
    noSmooth();<br />
    noFill();<br />
    ellipseMode(RADIUS); // I believe this is where my problem is(?)<br />
  }</p>
  
  <p>void draw() {<br />
    if (record) {<br />
      beginRecord(PDF, "NotTheSameImage.pdf");<br />
    }</p>
  
  <p>arc(200, 200, 50, 50, 0, 40 * (TAU/64));<br />
    arc(200, 200, 20, 20, 40 * (TAU/64), TAU);<br />
    rect(10, 10, 400, 400);<br />
    ray(200,200,3 * TAU/4,50);<br />
  </p>
  
  <p>if (record) {<br />
      endRecord<img src="" alt="" />();<br />
      record = false;<br />
    }<br />
  }</p>
  
  <p>void keyPressed() {<br />
    // Use a key press so that it doesn't make a million files<br />
    if (key == 'r') {<br />
      record = true;<br />
    }<br />
  }</p>
  
  <p>void ray(float x, float y, float rad, float dist) {<br />
    float xx = x + (dist * cos(rad));<br />
    float yy = y + (dist * sin(rad));<br />
    line(x, y, xx, yy);<br />
  }</p>
</blockquote>

<p>P.S. I need to re-read the section on posting code sorry about the lack of indentions.</p>
]]></description>
   </item>
   <item>
      <title>Problem in converting to PDF</title>
      <link>https://forum.processing.org/two/discussion/21191/problem-in-converting-to-pdf</link>
      <pubDate>Mon, 06 Mar 2017 06:08:01 +0000</pubDate>
      <dc:creator>adddramabutton</dc:creator>
      <guid isPermaLink="false">21191@/two/discussions</guid>
      <description><![CDATA[<p>Hello!
I'm completely new and I found a triangulation code on OpenProcessing which I'm trying to adapt to my task, but PDF export from References library doesn't work on this code. I suppose it's because the code uses "void display()" instead of "void draw()" and I can't figure out the proper place to paste lines from PDF Export reference library.</p>

<p>How should I use pdf export with this code? Sorry for posting all of it, I'm afraid I'll miss smth important:</p>

<pre><code>/**
* Delaunay Triangulations
* author aa_debdeb
/
import processing.pdf.*;
int frame = 100;
void setup(){
  size(500, 500);
  background(255);
  smooth();
  noLoop();
  beginRecord(PDF, "logo9.pdf"); 

  ArrayList&lt;Point&gt; points = new ArrayList&lt;Point&gt;();
  for(int i = 0; i &lt; 9; i++){
    points.add(new Point(random(frame, width-frame), random(frame, height-frame)));
  }
  ArrayList&lt;Triangle&gt; triangles = new ArrayList&lt;Triangle&gt;();

  float globalRadious = sqrt(sq(width) + sq(height)) / 2.0;
  Point globalPoint1 = new Point(width/2.0 - sqrt(3) * globalRadious,height/2.0 - globalRadious); //upper left                             
  Point globalPoint2 = new Point(width/2.0 + sqrt(3) * globalRadious,height/2.0 - globalRadious); //upper right
  Point globalPoint3 = new Point(width/2.0, height/2.0 + 2.0 * globalRadious); // lower center

  Triangle globalTriangle = new Triangle(globalPoint1, globalPoint2, globalPoint3);

  triangles.add(globalTriangle);

 for(Point point : points){
    ArrayList&lt;Triangle&gt; dividedTrianglesQueue = new ArrayList&lt;Triangle&gt;();
    for(Triangle triangle: triangles){
      if(triangle.isInTriangle(point)){
       dividedTrianglesQueue.add(triangle);        
      }
     }
   while(!dividedTrianglesQueue.isEmpty()){
  Triangle dividedTriangle = dividedTrianglesQueue.remove(0);
  triangles.remove(dividedTriangle);
  Triangle newTriangle1 = new Triangle(dividedTriangle.point1, dividedTriangle.point2, point);
  Triangle newTriangle2 = new Triangle(dividedTriangle.point1, point, dividedTriangle.point3);
  Triangle newTriangle3 = new Triangle(point, dividedTriangle.point2, dividedTriangle.point3);
  Side leagalizedEdge1 = new Side(dividedTriangle.point1, dividedTriangle.point2);
  Side leagalizedEdge2 = new Side(dividedTriangle.point1, dividedTriangle.point3);
  Side leagalizedEdge3 = new Side(dividedTriangle.point2, dividedTriangle.point3);
  ArrayList&lt;Triangle&gt; leagalizedTriangleQueue = new ArrayList&lt;Triangle&gt;();
  ArrayList&lt;Side&gt; leagalizedSideQueue = new ArrayList&lt;Side&gt;();
  leagalizedTriangleQueue.add(newTriangle1);
  leagalizedTriangleQueue.add(newTriangle2);
  leagalizedTriangleQueue.add(newTriangle3);
  leagalizedSideQueue.add(leagalizedEdge1);
  leagalizedSideQueue.add(leagalizedEdge2);
  leagalizedSideQueue.add(leagalizedEdge3);

  while(!leagalizedTriangleQueue.isEmpty()){
    Triangle leagalizedTriangle = leagalizedTriangleQueue.remove(0);
    Side leagalizedSide = leagalizedSideQueue.remove(0);
    Triangle triangleWithSameSide = findTriangleWithSameSide(triangles, leagalizedSide);
    if(triangleWithSameSide == null){
      triangles.add(leagalizedTriangle);
    } else {
      Point notOnSidePoint = triangleWithSameSide.getPointNotOnSide(leagalizedSide);
      if(leagalizedTriangle.isInCircumcircle(notOnSidePoint)){
        // flip
        triangles.remove(triangleWithSameSide);
        Point notOnSidePoint2 = leagalizedTriangle.getPointNotOnSide(leagalizedSide);
        leagalizedTriangleQueue.add(new Triangle(leagalizedSide.point1, notOnSidePoint, notOnSidePoint2));
        leagalizedSideQueue.add(new Side(leagalizedSide.point1, notOnSidePoint));
        leagalizedTriangleQueue.add(new Triangle(leagalizedSide.point2, notOnSidePoint, notOnSidePoint2));
        leagalizedSideQueue.add(new Side(leagalizedSide.point2, notOnSidePoint));
      } else {
        triangles.add(leagalizedTriangle);
      }
    }
  }
}
  }

  noFill();
  stroke(0);
  strokeWeight(1);
  for(Triangle triangle: triangles){
    if(!triangle.hasGlobalPoint(globalPoint1, globalPoint2, globalPoint3)){
      triangle.display();
    }
      }

  fill(0);
  noStroke();
  for(Point point : points){
    point.display();
  }

}

Triangle findTriangleWithSameSide(ArrayList&lt;Triangle&gt; triangles, Side side){
  for(Triangle triangle: triangles){
    if(side.hasPoints(triangle.point1, triangle.point2) ||
       side.hasPoints(triangle.point1, triangle.point3) ||
       side.hasPoints(triangle.point2, triangle.point3)){
         return triangle;
       }
  }
  return null;
}

class Point {

  float x;
  float y;

  Point(float x, float y){
    this.x = x;
    this.y = y;
 }

  void display(){
    ellipse(x, y, 10, 10);
  }
}

class Side {
  Point point1;
  Point point2;

  Side(Point point1, Point point2){
    this.point1 = point1;
    this.point2 = point2;
  }

  boolean hasPoints(Point p1, Point p2){
    return (point1 == p1 &amp;&amp; point2 == p2) || (point1 == p2 &amp;&amp; point2 == p1);
  }

  boolean equals(Side side){
    return (point1 == side.point1 &amp;&amp; point2 == side.point2) || (point1 == side.point2 &amp;&amp; point2 == side.point1);
  }

}

class Triangle {

  Point point1;
  Point point2;
  Point point3;
  Point circumcircleCenter;
  float circumcircleRadious;  

  Triangle(Point point1, Point point2, Point point3){
    this.point1 = point1;
    this.point2 = point2;
    this.point3 = point3;
    float c = 2.0 * ((point2.x - point1.x) * (point3.y - point1.y) - (point2.y - point1.y) * (point3.x - point1.x));
    float centerX = ((point3.y - point1.y) * (sq(point2.x) - sq(point1.x) + sq(point2.y) - sq(point1.y)) +
                     (point1.y - point2.y) * (sq(point3.x) - sq(point1.x) + sq(point3.y) - sq(point1.y))) / c;
    float centerY = ((point1.x - point3.x) * (sq(point2.x) - sq(point1.x) + sq(point2.y) - sq(point1.y)) +
                 (point2.x - point1.x) * (sq(point3.x) - sq(point1.x) + sq(point3.y) - sq(point1.y))) / c;
    circumcircleCenter = new Point(centerX, centerY);
    circumcircleRadious = getDistance(point1, circumcircleCenter);
  }

  boolean isInTriangle(Point p){
    float c1 = (point3.x - point2.x) * (p.y - point2.y) - (point3.y - point2.y) * (p.x - point2.x);
    float c2 = (point1.x - point3.x) * (p.y - point3.y) - (point1.y - point3.y) * (p.x - point3.x);
    float c3 = (point2.x - point1.x) * (p.y - point1.y) - (point2.y - point1.y) * (p.x - point1.x);
    return (c1 &gt; 0 &amp;&amp; c2 &gt; 0 &amp;&amp; c3 &gt; 0) || (c1 &lt; 0 &amp;&amp; c2 &lt; 0 &amp;&amp; c3 &lt; 0); 
  }

  boolean isInCircumcircle(Point p){
    return getDistance(p, circumcircleCenter) &lt; circumcircleRadious;
  }

  float getDistance(Point p1, Point p2){
    return sqrt(sq(p1.x - p2.x) + sq(p1.y - p2.y));
 }

  boolean hasGlobalPoint(Point gp1, Point gp2, Point gp3){
    return ((gp1 == point1 || gp1 == point2 || gp1 == point3) ||
            (gp2 == point1 || gp2 == point2 || gp2 == point3) ||
            (gp3 == point1 || gp3 == point2 || gp3 == point3));
  }

  Point getPointNotOnSide(Side side){
    Side side1 = new Side(point1, point2);
    Side side2 = new Side(point1, point3);
    Side side3 = new Side(point2, point3);
    if(side.equals(side1)){
      return point3;
    } else if(side.equals(side2)){
      return point2;
    } else if(side.equals(side3)){
      return point1;
    } else {
      return null;
    }
  }

  void display(){
    triangle(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);
  }
  endRecord();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Incrementing PDF filenames</title>
      <link>https://forum.processing.org/two/discussion/20784/incrementing-pdf-filenames</link>
      <pubDate>Mon, 13 Feb 2017 21:09:41 +0000</pubDate>
      <dc:creator>Gotovo</dc:creator>
      <guid isPermaLink="false">20784@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm trying to make my program save a new pdf file every time i press "s".
I'm having trouble incrementing filenames. i would like them to be timestamped with the date and time.
This currently just names the file after the frame i save it on, which works, but isn't ideal.</p>

<p>I found a sugested solution by user Koogs, but I have absolutely no idea how to implement it.</p>

<blockquote class="Quote">
  <p>maybe put the date and time in the filename so ensure the filenames are unique.</p>
  
  <p>use yyyymmdd_hhmmss format to preserve the creation order.</p>
</blockquote>

<p>As you can probably see from the mess of the code, I tried to do some stuff with adding one number to the filename after each save, but to no avail.</p>

<p>Any comments would be appreciated</p>

<pre><code>import processing.pdf.*;  // Import PDF code

boolean saveOneFrame = false;
float x;
float y;
int value;
int number=0;
MouseEvent event;
void setup()
{
  size(1920, 1080);
  background(200);

}
void draw() {
    if (saveOneFrame == true) {            // When the saveOneFrame boolean is true,
    beginRecord(PDF,"stringz###.pdf");    // start recording to the PDF
    }

if (mousePressed) { 
 x = lerp(x, mouseX, 0.01); //što je bliže nuli, to više interpolira. i obrnuto ofc
  y = lerp(y, mouseY, 0.01); //što je bliže nuli, to više interpolira. i obrnuto ofc

     int a = int(random(width-200, width+800));
     int b = int(random(height)); 

  noFill();
  stroke(value);
  beginShape();
  curveVertex(x, y); 
  curveVertex(x/2, y/2);
  curveVertex(x*2, y*2);
  curveVertex(a, b);
  curveVertex(a-b, b-a);
  curveVertex(y-200, 500);
  endShape();}
  if (saveOneFrame == true) {             // If the PDF has been recording,&lt;/em&gt;
    endRecord();                          // stop recording, 
    saveOneFrame = false;                 // and set the boolean value to false
  }
}



void keyPressed(){
  if (key == 'F' || key == 'f') // ako stisneš F ili f, izbrišeš sve
    background(200);
  if (key == 'S' || key == 's') { 
    beginRecord(PDF, "stringz###.pdf"); 
    number+=1;
  } else if (key == 'D' || key == 'd') { 
    endRecord();
    exit();
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Saving frame to new PDF</title>
      <link>https://forum.processing.org/two/discussion/19759/saving-frame-to-new-pdf</link>
      <pubDate>Thu, 15 Dec 2016 01:29:28 +0000</pubDate>
      <dc:creator>almoce</dc:creator>
      <guid isPermaLink="false">19759@/two/discussions</guid>
      <description><![CDATA[<p>I was looking around to find out about how to save current freme to PDF.
I want to record the drawing so that i need beginRecord at setup(), but any time if i endRecord, i cant save the another frame.
if i put the record in draw(), it will only record the current frame not all previously frames.</p>

<p>does any one know how to save different frame to pdf, just like saveframe(), but output the pdf vector file?</p>
]]></description>
   </item>
   <item>
      <title>Name automatically in the code layers for Illustrator</title>
      <link>https://forum.processing.org/two/discussion/19763/name-automatically-in-the-code-layers-for-illustrator</link>
      <pubDate>Thu, 15 Dec 2016 09:36:46 +0000</pubDate>
      <dc:creator>giwena</dc:creator>
      <guid isPermaLink="false">19763@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I have a question regarding PDF exportation. When I export my work in PDF and open it in Adobe Illustrator, every "<em>ellipse</em>" I drew in the code represents a layer in Illustrator. Would it be possible to name them automatically in Processing? I mean, each of them, with a different name I take from my a csv file. In this way, as I work with a huge amount of data, I could afterward use these layers in java.</p>

<p>Thanks you very much.</p>

<p>**This is my code : 
**</p>

<pre><code>// GLOBAL VARIABLES
PShape baseMap;
String csv[];
String myData[][];
PFont f;

// SETUP
void setup() {
  size(765, 627); 
  noLoop();
  f = createFont("Verdana", 11);
  baseMap = loadShape("Europe_location_map.svg");
  csv = loadStrings("airportdata(2).csv");
  myData = new String[csv.length][3];
  for(int i=0; i&lt;csv.length; i++){
   myData[i] = csv[i].split(";");    
 }

}

// DRAW 
void draw(){
beginRecord(PDF, "airporttest(scale).pdf");

shape(baseMap, 0, 0, width, height);
for (int i=0; i&lt;myData.length; i++){

fill(255, 0, 0, 100);
noStroke ();
println (myData[i][1]);

float graphLong = map(float(myData[i][3]), -25, 54, 0, width);
float graphLat = map(float(myData[i][2]), 82, 28, 0, height);
float markerSize = 0.014*sqrt(float(myData[i][1]))/PI;
ellipse (graphLong, graphLat, markerSize, markerSize);    

  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Not displaying graphics on screen when using beginRecord()</title>
      <link>https://forum.processing.org/two/discussion/18839/not-displaying-graphics-on-screen-when-using-beginrecord</link>
      <pubDate>Wed, 02 Nov 2016 11:06:47 +0000</pubDate>
      <dc:creator>Hypersim</dc:creator>
      <guid isPermaLink="false">18839@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>I hope, you can help me with a little problem:
I want to draw something on the screen as well as drawing this into a PDF file.
The PDF file is written correctly, but there is no output on the screen.</p>

<p>Do you have an idea, why it does not work?</p>

<p>Thanks a lot!</p>

<p>Cheers, Sebastian</p>

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

void setup() {
  size(400, 400);
  noLoop();
}

void draw() {
  selectInput("Select a listener file:", "fileSelected");
}


void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    drawGraphic(selection.getAbsolutePath());
  }
}


void drawGraphic(String inputString) {

  // DRAWING
  beginRecord(PDF, "filename.pdf");

  background(127);
  text(inputString, 10, 10);

  endRecord();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>OBJ Export with nervoussystem on Android with version 3.2.1 of Processing?</title>
      <link>https://forum.processing.org/two/discussion/18007/obj-export-with-nervoussystem-on-android-with-version-3-2-1-of-processing</link>
      <pubDate>Mon, 29 Aug 2016 18:17:52 +0000</pubDate>
      <dc:creator>Argandos</dc:creator>
      <guid isPermaLink="false">18007@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys.
I'm new to this forum but i know processing since version 2. Now i started learn it and got a big problem with my code for android. Here's my code:</p>

<pre><code>import nervoussystem.obj.*;
boolean record = false;

void setup() {
  size(400, 400,P3D);
}

void draw() {
  if (record) {
    beginRecord("nervoussystem.obj.OBJExport", "filename.obj");
  }  
  beginShape();
  vertex(-100, -100, -100);
  vertex( 100, -100, -100);
  vertex(   0,    0,  100);

  vertex( 100, -100, -100);
  vertex( 100,  100, -100);
  vertex(   0,    0,  100);

  vertex( 100, 100, -100);
  vertex(-100, 100, -100);
  vertex(   0,   0,  100);

  vertex(-100,  100, -100);
  vertex(-100, -100, -100);
  vertex(   0,    0,  100);

  if (keyPressed) 
  {
    if (key == 'b' || key == 'B')
    {
      vertex (-200, 200, -100);
    }
  }

  endShape();
  if (record) {
    endRecord();
    record = false;
  }
}

void mousePressed() {
  record = true;
}
</code></pre>

<p>I've got errors with the functions: beginRecord() and endRecord(). Processing says that the functions aren't exist, but on the java mode it works well. This library means much to me for the beginning, so, are there any solutions to solve this problem? Or do i have to write my own library? Thanks in advance ;)
Greetings
Argandos</p>
]]></description>
   </item>
   <item>
      <title>How can I change this to lines?</title>
      <link>https://forum.processing.org/two/discussion/18609/how-can-i-change-this-to-lines</link>
      <pubDate>Tue, 18 Oct 2016 14:10:30 +0000</pubDate>
      <dc:creator>Franz654</dc:creator>
      <guid isPermaLink="false">18609@/two/discussions</guid>
      <description><![CDATA[<p>I'm in a processing class and I'm terrible at it.</p>

<pre><code>    float spacing, x, y, diameter;
    import processing.pdf.*;
    boolean saveOneFrame = false;


    void setup(){
      size(720, 720);
      spacing=width/6;
      frameRate(2);

    }

    void draw(){
       if(saveOneFrame == true){
        beginRecord(PDF, "Dots-####.pdf");
      }

      background(255);
      fill(0);
      noStroke();
      translate(width/6, height/6);



      for(int dotX=0; dotX&lt;5; dotX ++){
        for(int dotY=0; dotY&lt;5; dotY ++){
        x= dotX*spacing;
        y= dotY*spacing;
           //diameter=60;
            //diameter=60+dotX*20;
             //diameter= 60+dotY*20;
           //diameter= 20+dotX*20 +dotY*20;
           diameter= random(20+60);
           //  diameter= 60+dist(x+spacing, y+spacing, mouseX, mouseY)/4;
           //diameter= 20-dist(x+spacing, y+spacing, mouseX, mouseY)/6;

           //noLoop();
      ellipse(x, y, diameter, diameter);

      }
      }
      if(saveOneFrame == true){
        endRecord();
        saveOneFrame = false;
      }
    }




    void mousePressed(){
      saveOneFrame = true;
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I change the circles to triangles?</title>
      <link>https://forum.processing.org/two/discussion/18509/how-can-i-change-the-circles-to-triangles</link>
      <pubDate>Tue, 11 Oct 2016 23:17:28 +0000</pubDate>
      <dc:creator>Franz654</dc:creator>
      <guid isPermaLink="false">18509@/two/discussions</guid>
      <description><![CDATA[<p>I'm fairly new to processing and I can't figure out how to change the circles to triangles in this code</p>

<pre><code>    float spacing, x, y, diameter;
    import processing.pdf.*;
    boolean saveOneFrame = false;


    void setup(){
      size(720, 720);
      spacing=width/6;
      frameRate(2);

    }

    void draw(){
       if(saveOneFrame == true){
        beginRecord(PDF, "Dots-####.pdf");
      }

      background(255);
      fill(0);
      noStroke();
      translate(width/6, height/6);



      for(int dotX=0; dotX&lt;5; dotX ++){
        for(int dotY=0; dotY&lt;5; dotY ++){
        x= dotX*spacing;
        y= dotY*spacing;
           //diameter=60;
            //diameter=60+dotX*20;
             //diameter= 60+dotY*20;
           //diameter= 20+dotX*20 +dotY*20;
           diameter= random(20+60);
           //  diameter= 60+dist(x+spacing, y+spacing, mouseX, mouseY)/4;
           //diameter= 20-dist(x+spacing, y+spacing, mouseX, mouseY)/6;

           //noLoop();
      ellipse(x, y, diameter, diameter);

      }
      }
      if(saveOneFrame == true){
        endRecord();
        saveOneFrame = false;
      }
    }




    void mousePressed(){
      saveOneFrame = true;
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is it possible to write to a PDF while using the P2D renderer?</title>
      <link>https://forum.processing.org/two/discussion/18293/is-it-possible-to-write-to-a-pdf-while-using-the-p2d-renderer</link>
      <pubDate>Mon, 26 Sep 2016 01:57:54 +0000</pubDate>
      <dc:creator>aNew</dc:creator>
      <guid isPermaLink="false">18293@/two/discussions</guid>
      <description><![CDATA[<p>I have a programming that is using the P2D renderer and I want to save frames to a PDF at a button press. I simply want to implement this code from the PDF examples on the processing website.</p>

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

boolean record;

void setup() {
  size(400, 400);
}

void draw() {
  if (record) {
    // Note that #### will be replaced with the frame number. Fancy!
    beginRecord(PDF, "frame-####.pdf"); 
  }

  // Draw something good here
  background(255);
  line(mouseX, mouseY, width/2, height/2);

  if (record) {
    endRecord();
    record = false;
  }
}

// Use a keypress so thousands of files aren't created
void mousePressed() {
  record = true;
}
</code></pre>

<p>Unfortunately, this implementation did not work for my code. It simply to produced blank PDF files. I tried simply switching the renderer to default, as it is in the example above and it was able to write a file with the image. However, my code uses PShapes and due to a bug in processing, it only looks correct using the P2D renderer, not the default. (<a rel="nofollow" href="https://github.com/processing/processing/issues/4678#issuecomment-249374889">this link shows why</a>)</p>

<p>Is there a way around this? I really would like to save frames of my program to manipulate in Illustrator.</p>
]]></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>PShapes in P2D</title>
      <link>https://forum.processing.org/two/discussion/17431/pshapes-in-p2d</link>
      <pubDate>Wed, 06 Jul 2016 11:08:38 +0000</pubDate>
      <dc:creator>ukmikeb</dc:creator>
      <guid isPermaLink="false">17431@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>My sketch is setup to run under P2D: size(1920,1080,P2D);</p>

<p>I'm using beginRecord(PDF, etc) &amp; endRecord(); to output a PDF from 1 single frame.</p>

<p>If I draw shapes dynamically they appear in the PDF no problem using beginShape(), vertex(), endShape().</p>

<p>However if I create a PShape object and create a shape that way (which is more efficient) then that shape does not appear in the PDF but does appear on screen.</p>

<p>I'm guessing this is something to do with the way the P2D OPENGL works, but just want to see if it's intended behaviour or a "bug".</p>

<p>Any insight to help me understand this better would be great.</p>

<p>(BTW, I realise there is also a PDF mode, but ideally I'd like a screen preview too?)</p>

<p>Thank</p>

<p>Mike</p>
]]></description>
   </item>
   <item>
      <title>PGraphics::scale() not exporting in P3D</title>
      <link>https://forum.processing.org/two/discussion/17200/pgraphics-scale-not-exporting-in-p3d</link>
      <pubDate>Sat, 18 Jun 2016 15:09:03 +0000</pubDate>
      <dc:creator>chrisb78</dc:creator>
      <guid isPermaLink="false">17200@/two/discussions</guid>
      <description><![CDATA[<p>When exporting a PGraphicss P3D object, save() doesn't reflect calls to scale().
Consider the example, taken from <a href="https://forum.processing.org/two/discussion/3227/high-resolution-export-p3d" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/3227/high-resolution-export-p3d</a>:
(note that endRecord() and PGpx.scale() had to be changed in order for the original example to work):</p>

<pre><code>boolean record;
int scalePG = 2;

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

void draw() {
    if(!record)
        background(#ffffff);
    translate(width/2, height/2);
    fill(#ff0000);
    rotateX(60);
    rotateZ(60);
    box(100);
}
void keyPressed() {
    save("lowres.png");

    if(keyCode == ENTER) {
        PGraphics PGpx = createGraphics(width * scalePG, height * scalePG, P3D);
        record = true;
        beginRecord(PGpx);
        PGpx.background(#ffffff, 0); // Clear the offscreen canvas (make it transparent)
        PGpx.scale(scalePG);
        draw();
        endRecord(); // originally was AFTER call to save() in next line - but didn't save anything.
        PGpx.save("highres.png"); // Save image as PNG (JPGs can't have an alpha channel) and save it before endRecord()

        record = false;
    }
}
</code></pre>

<p>I posted some pictures about this in this post: <a href="https://forum.processing.org/two/discussion/17162/high-resolution-output-for-p3d" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/17162/high-resolution-output-for-p3d</a></p>

<p>Does anyone know how to fix this?</p>
]]></description>
   </item>
   <item>
      <title>High Resolution Export P3D</title>
      <link>https://forum.processing.org/two/discussion/3227/high-resolution-export-p3d</link>
      <pubDate>Sat, 22 Feb 2014 01:26:28 +0000</pubDate>
      <dc:creator>sephm</dc:creator>
      <guid isPermaLink="false">3227@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys! Has anyone successfully exported a high resolution transparent png image from a sketch using a P3D render mode? This is possible before using P5 v1.5.1, but it seems there are some errors working it in P5 v2.</p>

<p>Any help will be greatly appreciated. Thanks!</p>
]]></description>
   </item>
   <item>
      <title>High Resolution Output for P3D</title>
      <link>https://forum.processing.org/two/discussion/17162/high-resolution-output-for-p3d</link>
      <pubDate>Wed, 15 Jun 2016 22:00:23 +0000</pubDate>
      <dc:creator>chrisb78</dc:creator>
      <guid isPermaLink="false">17162@/two/discussions</guid>
      <description><![CDATA[<p>I'm using the following code snippet (from <a href="https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/" target="_blank" rel="nofollow">https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/</a> - number 16) to export a scaled-up high resolution file. Everything works perfectly as long as size() and createGraphics() use the 2D renderer:</p>

<pre><code>void setup() {
  size(500, 500); // IMPLICIT USE OF 2D RENDERER
}

void draw() {
  background(255);
  smooth();
  strokeWeight(10);
  fill(255, 0, 0);
  ellipse(width/2, height/2, 200, 200);
}

void keyPressed() {
  if (key == 's') {
    save("normal.png");
    saveHiRes(5);
    exit();
  }
}

void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, JAVA2D); // CREATION OF 2D PGRAPHICS OBJECT
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
</code></pre>

<p>However, once the two bold lines use P3D instead (code at the end of this post), the program results in two problems:
1. The following error message appears: "OpenGL error 1282 at top endDraw(): invalid operation" (on Win7 with updated drivers)
2. Scaling doesn't actually happen - instead, unscaled image sits in the left bottom of the hi-res PGraphics object - like this:
<img src="https://forum.processing.org/two/uploads/imageupload/439/RUX1T1PICDSM.png" alt="_hires_800px_test" title="_hires_800px_test" /></p>

<p>The correct result should look like this:
<img src="https://forum.processing.org/two/uploads/imageupload/644/BSEB4ZNGTSG3.png" alt="normal" title="normal" /></p>

<p>After researching this, I couldn't find any high-resolution output for people working with a 3D renderer. I don't care so much about how to create hi-res output, and tried several approaches - without luck yet.</p>

<p>Any help would be greatly appreciated!</p>

<p>Here's the 3D version of the initial code snippet:
    void setup() {
      size(500, 500, P3D); // 3D RENDERER
    }</p>

<pre><code>void draw() {
  background(255);
  smooth();
  strokeWeight(10);
  fill(255, 0, 0);
  ellipse(width/2, height/2, 200, 200);
}

void keyPressed() {
  if (key == 's') {
    save("normal.png");
    saveHiRes(5);
    exit();
  }
}

void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, P3D); // CREATION OF 3D PGRAPHICS OBJECT
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to export a PDF from a part of the screen only ?</title>
      <link>https://forum.processing.org/two/discussion/16763/how-to-export-a-pdf-from-a-part-of-the-screen-only</link>
      <pubDate>Sun, 22 May 2016 18:03:26 +0000</pubDate>
      <dc:creator>AdrienColrat</dc:creator>
      <guid isPermaLink="false">16763@/two/discussions</guid>
      <description><![CDATA[<p>I'm working on automatic books generated with processing, and for one of these books I need to export the left of my screen to one PDF page, and the right to the next page and so on. 
This is a static and simplified version of my sketch:</p>

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

void setup() {
  size(1218,870);
  pdf = (PGraphicsPDF)beginRecord(PDF, "test.pdf");
  PImage img = loadImage("test.jpg");
  image(img, 0,0);
  pdf.nextPage();
  get(595,0,623,870).save("left.jpg");
  get(0,0,623,870).save("right.jpg");
  endRecord();
}
</code></pre>

<p>Obviously, this doesn't work at all. I get how I can separate the screen in two — with get() —, but is there any way to make that work with the pdf nextPage() function ? And is there any way at all to export a pdf that's not the size of your sketch?
Thanks !</p>
]]></description>
   </item>
   </channel>
</rss>