<?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 lastmodified() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=lastmodified%28%29</link>
      <pubDate>Sun, 08 Aug 2021 16:16:37 +0000</pubDate>
         <description>Tagged with lastmodified() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedlastmodified%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>real time data program</title>
      <link>https://forum.processing.org/two/discussion/28059/real-time-data-program</link>
      <pubDate>Sat, 16 Jun 2018 22:21:54 +0000</pubDate>
      <dc:creator>vjjv</dc:creator>
      <guid isPermaLink="false">28059@/two/discussions</guid>
      <description><![CDATA[<p>hey guys. in this time i need some help to optimize a system to pick shaders in real time (fragment shaders, and vertex shaders). This code is a mix that i recoleted in internet with code writing by myself.</p>

<p>Theres a lot of problem and i need help:</p>

<p>the idea of the program is that user can pick the shader in real time. 
there are two problems, first, i dont know how uploading the vertexShader, when i save it and reload it i need to click in another frag and then vertex upload.</p>

<p>second, it seems very inestable.the window of shaders crash very often, specially when frame rate is lowest. I wondering how to fix that. maybe with thread(), but it dont know exactly how apply this method..</p>

<p>If someone have time and wants to help, im sure that this code needs to be re writing. Thanks!</p>

<pre><code>ShaderWindow shaderWin;

boolean recording = false;


import netP5.*;
import oscP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

import themidibus.*;
MidiBus bus;
MidiBus apc;
float cc [] =new float [256];


boolean record, load;
double folderTime;
File folderShader;
float desmouse = 0.5;

// BUFFERS-SHADERS

String dirFolderShaders;
String dirFolderShaders2;
String dirFolderShadersvertex;

PGraphics [] buffers = new PGraphics [4];
PGraphics buffer;

LoadShader loadshader;

LoadShader loadshader2;
LoadShader loadshaderVertex;

ArrayList&lt;ViewShader&gt;vs = new ArrayList&lt;ViewShader&gt;();
ViewShaderVertex ss;

PShader sh, buffer1;
float count;
float angle = random(0, 0.005);

int choiceSize =1;
//int ww =  1920;
//int h = 1080;

void settings() {
  if (choiceSize==0) fullScreen(P3D, 2);
  if (choiceSize==1) size(1000, 1000, P3D);
  if (choiceSize==2) size(720, 1280, P3D);
}

void setup() {

  // BUFFERS-SHADERS

  dirFolderShaders = sketchPath("frag/");  //PUT SOME FRAGMENT IN THIS FOLDER

  dirFolderShadersvertex = sketchPath("vertex/"); PUT SOME VERTEX IN THIS FOLDER

  loadshader = new LoadShader(dirFolderShaders);

  loadshaderVertex = new LoadShader(dirFolderShadersvertex);


  for (int i = 0; i &lt; buffers.length; i++) {
    buffers[i] = createGraphics(width, height, P3D);
  }


  ss = new ViewShaderVertex(loadshaderVertex.shadersPaths[1], loadshaderVertex, buffer);
  vs.add(new ViewShader(loadshader.shadersPaths[0], loadshader, buffer, ss));

  shaderWin = new ShaderWindow();
}

void draw() {

  background(0);


  for (ViewShader s : vs) {
    s.update();
  }


  if (folderShader.listFiles().length != loadshader.shadersNames.length) {
    loadshaderVertex.loadFolderShader();
  }

  if (folderShader.listFiles().length != loadshader.shadersNames.length) {
    loadshader.loadFolderShader();
  }




  buffers[0].beginDraw();
  buffers[0].background(0);
  buffers[0].translate(width/2, height/2);


  buffers[0].sphere(100);
  buffers[0].endDraw();

  image(buffers[0],0,0);
}



// LOAD SHADER CLASS

class LoadShader {

  String dirFolderShaders;

  String[] shadersNames;
  String[] shadersPaths;

  LoadShader(String _dirFolderShaders) {
    dirFolderShaders= _dirFolderShaders;
    loadFolderShader();
  }

  void loadFolderShader() {
    load = true;
    folderShader = new File(dirFolderShaders);
    File files[] = folderShader.listFiles();
    shadersNames = new String[files.length];
    shadersPaths = new String[files.length];
    for (int i = 0; i &lt; files.length; i++) {
      shadersNames[i] = split(files[i].getName(), ".")[0];
      shadersPaths[i] = files[i].getAbsolutePath();
      //println(shadersNames[i]);
    }
    load = false;
  }
}

class ViewShader {

  boolean reload, error, loaded;
  File fileShader;

  long timeModi;
  long timeModis;
  String src;

  PShader shader;
  PShader shader1;
  PShader shader2;
  float a;
  LoadShader loadshader;
  ViewShaderVertex ss;
  PGraphics b;

  ViewShader(String _src, LoadShader _loadshader, PGraphics _b) {
    src = _src;
    fileShader = new File(src);
    openShader(fileShader);
    //shader1 = loadShader("blur.glsl", "bloomVert.glsl");
    //shader2 = loadShader("blur_vertical.glsl", "bloomVert.glsl");
    loadshader = _loadshader;
    b = _b;
  }

  ViewShader(String _src, LoadShader _loadshader, PGraphics _b, ViewShaderVertex _s) {
    ss = _s;

    //shader = loadShader("test2.glsl", "defaultVertex2.glsl");
    //shader1 = loadShader("blur.glsl", "bloomVert.glsl");
    //shader2 = loadShader("blur_vertical.glsl", "bloomVert.glsl");

    src = _src;
    fileShader = new File(src);
    openShader(fileShader);
    loadshader = _loadshader;
    b = _b;
  }


  void update() {
    if (reload) {      
      openShader(fileShader);
      reload = false;
    }
    if (shader != null) {

      //float p = map(cc[15], 0, 1, 0, 1);
      //float amt = map(cc[16], 0, 1, 1, 50);
      //float  h = map(cc[48], 0, 1, 0, 0.1);
      // //float  h = map(cc[14], 0, 1, 0, 0.5);


      shader.set("u_time", random(10));

      //shader1.set("u_time", angle);
      //shader2.set("u_time", angle);

      //shader.set("var2", p);
      //shader.set("amt", amt);

      //shader1.set("var2", p);
      //shader2.set("var2", p);


      if (fileShader.lastModified() != timeModi) {
        openShader(fileShader);
      }
    }
  }


  void newShader(String _srcc) {
    src = _srcc;
    fileShader = new File(src);
    reload = true;
    openShader(fileShader);
  }

  void openShader(File file) {
    if (file != null) {
      fileShader = file;
      timeModi = fileShader.lastModified();  
      try {
        shader = loadShader(file.getAbsolutePath(), ss.fileShader.getAbsolutePath());

        buffers[0].shader(shader);


        println(file.getAbsolutePath());
        error = false;
        loaded = true;
      }
      catch (RuntimeException e) {
        if (error == false) {
          error = true;
          // String time = nf(str(hour()),2) + ":" + nf(str(minute()),2) + ":" + nf(str(second()),2);
          println("\n");
          // println("At", time, "loadShader() returned the following error: \n");
          println("loadShader() returned the following error: \n");
          e.printStackTrace();
        }
        loaded = false;
      }
    }
  }
}

public class ShaderWindow extends PApplet {

  ShaderWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  boolean mover;

  void settings() {
    size(600, 800, P2D);
  }

  void setup() {
    this.frameRate(30);
  }


  void draw() {

    background(25);


    for (int i = 0; i &lt; vs.size(); i++) {
      ViewShader sss = vs.get(i);
      selector(i*100, 16, 100, width-16, sss, sss.loadshader, this);
    }

    ViewShaderVertex s = ss;  
    selector2(400, 16, 100, width-16, s, ss.loadshader, this);

  }

  void selector(float xx, float yy, float ww, float hh, ViewShader vs, LoadShader loadshader, PApplet p) {
    p.fill(150);
    p.noStroke();
    p.rectMode(CORNER);

    int cant = loadshader.shadersNames.length;
    p.rect(xx, yy+cant*16, ww, hh-cant*16);
    for (int i = 0; i &lt; cant; i++) {
      boolean sobre = false;
      if (p.mouseX &gt;= xx &amp;&amp; p.mouseX &lt; xx+ww &amp;&amp; p.mouseY &gt;= yy+i*16 &amp;&amp; p.mouseY &lt; yy+(i+1)*16) {
        sobre = true;
      }
      if (sobre) {
        p.fill(125);
      } else {
        p.fill(100, 50);
      }
      boolean selec = vs.src.equals(loadshader.shadersPaths[i]);
      if (p.mousePressed &amp;&amp; sobre &amp;&amp; !selec) {
        vs.newShader(loadshader.shadersPaths[i]);
      }

      if (selec) {
        p.fill(100);
        if (vs.error) {
          p.fill(200, 10, 10);
        }
      }

      p.rect(xx, yy+i*16, ww, 16);
      p.textAlign(LEFT, TOP);
      p.fill(250);
      if (i &lt; loadshader.shadersNames.length &amp;&amp; !load)
        text(loadshader.shadersNames[i], xx+5, yy+i*16);
    }
  }

  void selector2(float xx, float yy, float ww, float hh, ViewShaderVertex vs, LoadShader loadshader, PApplet p) {
    p.fill(150);
    p.noStroke();
    p.rectMode(CORNER);

    int cant = loadshader.shadersNames.length;
    p.rect(xx, yy+cant*16, ww, hh-cant*16);
    for (int i = 0; i &lt; cant; i++) {
      boolean sobre = false;
      if (p.mouseX &gt;= xx &amp;&amp; p.mouseX &lt; xx+ww &amp;&amp; p.mouseY &gt;= yy+i*16 &amp;&amp; p.mouseY &lt; yy+(i+1)*16) {
        sobre = true;
      }
      if (sobre) {
        p.fill(125);
      } else {
        p.fill(100, 50);
      }
      boolean selec = ss.src.equals(loadshader.shadersPaths[i]);
      if (p.mousePressed &amp;&amp; sobre &amp;&amp; !selec) {
        vs.newShader(loadshader.shadersPaths[i]);
      }

      if (selec) {
        p.fill(100);
        if (vs.error) {
          p.fill(200, 10, 10);
        }
      }

      p.rect(xx, yy+i*16, ww, 16);
      p.textAlign(LEFT, TOP);
      p.fill(250);
      if (i &lt; loadshader.shadersNames.length &amp;&amp; !load)
        p.text(loadshader.shadersNames[i], xx+5, yy+i*16);
    }
  }
}

class ViewShaderVertex {

  boolean reload, error, loaded;
  File fileShader;
  long timeModi;
  String src;
  String src2;

  PShader shader;

  float a;
  LoadShader loadshader;
  ViewShader ss;

  ViewShaderVertex(String _src, LoadShader _loadshader, PGraphics b) {

    src = _src;
    fileShader = new File(src);
    openShader(fileShader);

    loadshader = _loadshader;
  }



  void update() {
    if (reload) {      
      openShader(fileShader);
      reload = false;
    }
    if (shader != null) {

      if (fileShader.lastModified() != timeModi) {
        openShader(fileShader);

      }
    }
  }


  void newShader(String src) {
    this.src = src;
    fileShader = new File(src);
    reload = true;
    openShader(fileShader);
  }

  void openShader(File file) {

    if (file != null) {
      fileShader = file;
      timeModi = fileShader.lastModified();

      try {
                for (ViewShader s : vs) {
          s.update();
        }
        //shader = loadShader("test.glsl", file.getAbsolutePath());
        shader.setVertexShader(file.getAbsolutePath());
        buffers[0].shader(shader);

        println(file.getAbsolutePath());
        error = false;
        loaded = true;
      }
      catch (RuntimeException e) {
        if (error == false) {
          error = true;
          // String time = nf(str(hour()),2) + ":" + nf(str(minute()),2) + ":" + nf(str(second()),2);
          println("\n");
          // println("At", time, "loadShader() returned the following error: \n");
          println("loadShader() returned the following error: \n");
          e.printStackTrace();
        }
        loaded = false;
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Sorting a hashmap by value</title>
      <link>https://forum.processing.org/two/discussion/27863/sorting-a-hashmap-by-value</link>
      <pubDate>Fri, 27 Apr 2018 15:58:35 +0000</pubDate>
      <dc:creator>dehyde</dc:creator>
      <guid isPermaLink="false">27863@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>I have a hashmap that represents word frequencies with String:Int combinations to represent the Word:count respectively.
How can I sort the hashmap, so the most common words would be first and the least common would appear last?
I've only found examples for earlier versions of processing on this forum.</p>

<p>Here's the code (also contains other things):</p>

<pre><code>import java.util.Date;
import java.util.Map;

PImage[] img;

//===============  margins and stuff
int galleryImageHeight = 13;  


//=============== fonts and styles
PFont countryTitle;
PFont labels;

//=============== loading tables
Table wordsTable;

//============== Words Hashmaps
HashMap&lt;String, Integer&gt; hm = new HashMap&lt;String, Integer&gt;();

void setup() {
  size(1024, 768, P2D);
 ((PGraphicsOpenGL)g).textureSampling(3);
  //fonts and styles
  countryTitle = createFont("QLRG.TTF", 32);
  labels = createFont("Roboto-Regular.ttf", 10);

  //=============== loading tables
  wordsTable = loadTable("syriaWords.csv", "header");

  for (TableRow row : wordsTable.rows()) {
    hm.put(row.getString("word"), row.getInt("count"));
  }



// Using just the path of this sketch to demonstrate,
// but you can list any directory you like.
String path = sketchPath();

println("Listing all filenames in a directory: ");
String[] filenames = listFileNames(path+"/data");
printArray(filenames);

println("\nListing info about all files in a directory: ");
File[] files = listFiles(path);
for (int i = 0; i &lt; files.length; i++) {
  File f = files[i];    
  println("Name: " + f.getName());
  println("Is directory: " + f.isDirectory());
  println("Size: " + f.length());
  String lastModified = new Date(f.lastModified()).toString();
  println("Last Modified: " + lastModified);
  println("-----------------------");
}

println("\nListing info about all files in a directory and all subdirectories: ");
ArrayList&lt;File&gt; allFiles = listFilesRecursive(path);

img = new PImage[allFiles.size()];
int i = 0;
for (File f : allFiles) {
  println("Name: " + f.getName());
  println("Full path: " + f.getAbsolutePath());
  println("Is directory: " + f.isDirectory());
  println("Size: " + f.length());
  String lastModified = new Date(f.lastModified()).toString();
  println("Last Modified: " + lastModified);
  println("-----------------------");
  println("Is Image: " + isItAnImage(f.getName()));
  if (isItAnImage(f.getAbsolutePath())==true) {
    img[i] = loadImage(f.getAbsolutePath());
    println(f.getAbsolutePath());
    println (img[i]);
    img[i].resize(0, galleryImageHeight);
    i++;
  }
}

noLoop();
}

// Nothing is drawn in this program and the draw() doesn't loop because
// of the noLoop() in setup()
void draw() {
  background(255, 255, 255);
  for (int i=1; i&lt;img.length; i++) {
    println("i = "+i);
    println(img[i]);
    for (int r=0; r&lt;(img.length)/5; r++) {         //rows
      int playHead = 30;
      for (int c=0; c&lt;15; c++) {      //columns
        if (i&lt;img.length-30) {
          image(img[i], playHead, r*(galleryImageHeight)+30);
          playHead = playHead + img[i].width;
          i++;
        }
      }
    }
  }
  textFont(countryTitle);
  textAlign(LEFT);
  fill(200);
  text("SYRIA", 30, height/2);
  textFont(labels);
  int t=1;
  for (Map.Entry me : hm.entrySet()) {
    int freq = hm.get(me.getKey());
    String s = "";
    for (int i=0; i&lt;freq; i++){
      s = s+" "+me.getKey();
      }
    fill(10*t);
    text(s.toLowerCase(), 30, t*10+400);  // Text wraps within text box
    t++;
    print(me.getKey() + " is ");
    println(me.getValue());
    }

}

// This function returns all the files in a directory as an array of Strings  
String[] listFileNames(String dir) {
  File file = new File(dir);
  if (file.isDirectory()) {
    String names[] = file.list();
    return names;
  } else {
    // If it's not a directory
    return null;
  }
}

// This function returns all the files in a directory as an array of File objects
// This is useful if you want more info about the file
File[] listFiles(String dir) {
  File file = new File(dir);
  if (file.isDirectory()) {
    File[] files = file.listFiles();
    return files;
  } else {
    // If it's not a directory
    return null;
  }
}

// Function to get a list of all files in a directory and all subdirectories
ArrayList&lt;File&gt; listFilesRecursive(String dir) {
  ArrayList&lt;File&gt; fileList = new ArrayList&lt;File&gt;(); 
  recurseDir(fileList, dir);
  return fileList;
}

// Recursive function to traverse subdirectories
void recurseDir(ArrayList&lt;File&gt; a, String dir) {
  File file = new File(dir);
  if (file.isDirectory()) {
    // If you want to include directories in the list
    a.add(file);  
    File[] subfiles = file.listFiles();
    for (int i = 0; i &lt; subfiles.length; i++) {
      // Call this function on all files in this directory
      recurseDir(a, subfiles[i].getAbsolutePath());
    }
  } else {
    a.add(file);
  }
}

boolean isItAnImage(String loadPath) {
  return (
    loadPath.endsWith(".jpg") ||
    loadPath.endsWith(".jpeg") ||
    loadPath.endsWith(".png")  ) ;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>out of memory error on loadImage() in Draw loop</title>
      <link>https://forum.processing.org/two/discussion/27810/out-of-memory-error-on-loadimage-in-draw-loop</link>
      <pubDate>Fri, 20 Apr 2018 21:30:06 +0000</pubDate>
      <dc:creator>jeffmarc</dc:creator>
      <guid isPermaLink="false">27810@/two/discussions</guid>
      <description><![CDATA[<p>So the Java garbage collection and memory management works in the background .
In post from 2016 from Henri , "PImage won't release memopry"
KevinWorkman says the Java garbage collection and memory management works in the background so "Out of Memory"
error should never happen.
Wonder if it is fixed in later versions or what cause I get it in  the following scenerio.</p>

<pre><code>Using 2.2.1 and getting out of memory when i run sketch. basically it asks the user to grab an image. The image is then loaded with loadImage() After 1000's of draw loops , i get out of memory and sketch halts with error messages in console. Is the auto memory management in Java the same in this version or better in later versions of Processing? The program uses an event counter to allow only one iteration of each condition in the draw loop. 

  Step 1 - wait for user to request image grab 
  Step 2 - loadImage and display with image() 
  Step 3- perform image processing 
  Step 4- report numeric results ( count all pixels below threshold) 
  Reset event counter to 1

  I inserted a wait time of 1 second to auto initiate the loop and it runs for hours and finally gives out of memory 
 So is the garbage collector not working in theis version or what?
</code></pre>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Fast loading images directly from Disk</title>
      <link>https://forum.processing.org/two/discussion/27792/fast-loading-images-directly-from-disk</link>
      <pubDate>Wed, 18 Apr 2018 12:50:47 +0000</pubDate>
      <dc:creator>tom_tm</dc:creator>
      <guid isPermaLink="false">27792@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>is there a way to sequencially load images directly from disk with realtime perfomance?
loadImage is very slow, and I would like to avoid preloading the images first.</p>

<p>I could do this with old good Flash with Full HD imagery in realtime, so it has nothing to do with my disk performance.</p>

<p>Thanks for any hints
Tom</p>
]]></description>
   </item>
   <item>
      <title>Reading File Attributes</title>
      <link>https://forum.processing.org/two/discussion/26252/reading-file-attributes</link>
      <pubDate>Tue, 06 Feb 2018 10:28:20 +0000</pubDate>
      <dc:creator>Rob3991</dc:creator>
      <guid isPermaLink="false">26252@/two/discussions</guid>
      <description><![CDATA[<p>Hey,
I'm currently working on reading data out of CSV-files with a processing sketch and sending them via serial communication to a microcontroller. Now I need to get the file attributes of the CSV-files (for example the last modification time of the file). Is there any library or reference I can use/integrate in my processing sktech to get those file attributes?</p>

<p>Thank you very much 
Rob</p>
]]></description>
   </item>
   <item>
      <title>Load newest image in folder</title>
      <link>https://forum.processing.org/two/discussion/22004/load-newest-image-in-folder</link>
      <pubDate>Fri, 14 Apr 2017 22:02:52 +0000</pubDate>
      <dc:creator>bramblepelt</dc:creator>
      <guid isPermaLink="false">22004@/two/discussions</guid>
      <description><![CDATA[<p>I was wondering if anyone knew a way to only load the newest image in the data folder when the code starts,or IDEALY using a keyCode to switch between images in the folder. I want to be able to change which image is being displayed without having to go into the code to change the file name in " image= loadImage("<em>file name</em>.JPG"); ".</p>
]]></description>
   </item>
   <item>
      <title>How to filter and order a set of files?</title>
      <link>https://forum.processing.org/two/discussion/2578/how-to-filter-and-order-a-set-of-files</link>
      <pubDate>Wed, 22 Jan 2014 10:27:27 +0000</pubDate>
      <dc:creator>HaPK</dc:creator>
      <guid isPermaLink="false">2578@/two/discussions</guid>
      <description><![CDATA[<p>I need to filter an ArrayList of Files by png images, and I need to order it from oldest to most recent, but it would be nice if it ordered not by last modified but by creation date.</p>

<p>This is the relevant code (variable names and methods in Spanish, sorry):</p>

<p>AdminImagen class</p>

<pre><code>import java.io.File;
import java.util.Date;
import java.util.ArrayList;

class AdminImagen {
  ArrayList&lt;File&gt; archivos;
  ArrayList&lt;Imagen&gt; imagenes;

  AdminImagen(String ruta) {
    archivos=listarArchivos(ruta);
    imagenes=prepararImagenes(archivos);
  }

  ArrayList&lt;File&gt;listarArchivos(String ruta) {
    File file=new File(ruta);

    ArrayList&lt;File&gt; lista = new ArrayList&lt;File&gt;();
    if (file.isDirectory()) {
      File[] arch=file.listFiles();
      for (int i=0;i&lt;arch.length;i++) {
        lista.add(arch[i]);
      }
      return lista;
    } 
    else return null;
  }

  ArrayList&lt;Imagen&gt; prepararImagenes(ArrayList&lt;File&gt; arch) {
    ArrayList&lt;Imagen&gt; im=new ArrayList&lt;Imagen&gt;();
    for (File f:arch) {
      String ruta=f.getAbsolutePath();
      Date fecha=new Date(f.lastModified());
      Imagen imagen=new Imagen(ruta, fecha);
      im.add(imagen);
    }
    return im;
  }

  String getRutaImagen(int a) {
    return imagenes.get(a).rutaArchivo;
  }

  Date getFechaImagen(int a) {
    return imagenes.get(a).hora;
  }

  String getHoraImagen(int a) {
    Date fecha = getFechaImagen(a);
    String hora = fecha.getHours()+":"+fecha.getMinutes();
    return hora;
  }
}
</code></pre>

<p>Imagen class</p>

<pre><code>import java.io.File;
import java.util.Date;

class Imagen {
  String rutaArchivo;
  Date hora;

  Imagen(String ruta, Date fecha) {
    rutaArchivo=ruta;
    hora=fecha;
  }

  Imagen() {
    rutaArchivo="";
    hora=null;
  }

  //crear un objeto Imagen a partir de un File
  void extraerInfoImagen(File archivo) {
    rutaArchivo=archivo.getAbsolutePath();
    hora=new Date(archivo.lastModified());
  }
}
</code></pre>

<p>I really don't know how to make these operations, so could you help me out here? Thanks</p>
]]></description>
   </item>
   </channel>
</rss>