Seeking Help with Complex Processing Script for Visual Representation Generator

Here would be a little trick using a little trick to generating the visualizations with fewer lines of code provided you add constructors too each of your classes:
Here would be a little example of that. (There also is a way to do it without however there is some “dark magic” involved)

abstract class SuperCl {
  abstract void printStuff();
}
class Ext1 extends SuperCl {
  public Ext1() {
  }
  void printStuff() {
    println("Extension 1");
  }
}
class Ext2 extends SuperCl {
  public Ext2() {
  }
  void printStuff() {
    println("Extension 2");
  }
}
class Ext3 extends SuperCl {
  public Ext3() {
  }
  void printStuff() {
    println("Extension 3");
  }
}
import java.util.*;
import java.lang.reflect.*;
void setup() {
  //Number of extension
  int extCount=3;
  //List of the extensions
  List<SuperCl> exts=new ArrayList<SuperCl>();
  try {
    Class<?> sketchClass=this.getClass();
    String baselineClassName=sketchClass.getName()+"$Ext";
    for (int i=1; i<=extCount; i++) exts.add(
      (SuperCl)Class.forName(baselineClassName+i)
      .getConstructor(sketchClass)
      .newInstance(this));
  }
  catch(Exception e) {
    throw new RuntimeException(e);
  }
  for(SuperCl ext:exts) ext.printStuff(); 
}

Since your code already uses an index of wich visualisation is active you can do the folowing. First add the “volatile” keyword to currentVisualizationIndex .

java.util also provides a Timer class that can be used to set this variable.

1 Like