I was trying to replicate some code from the book Type + Code (page 68)
I was surprised to see that the size function is called with variables, as I expected I’m getting an error. I changed the values with 800, 600, P3D and I got a different error.
Was it possible to use variables on the size function on previous version of processing? any clue on how to fix the code? At this point I’m learning by copying, I have no coding background other than online tutorials.
Regards.
import processing.pdf.*;
import processing.opengl.*;
import geomerative.*;
float toldist;
RFont f;
RGroup groupo;
boolean restart = false;
Particle[] psys;
int numPoints.numParticles;
float maxvel;
boolean SAVEVIDEO = false;
boolean SAVEFRAME = false;
String DEFAULTAPPLETRENDERER = P3D;
int DEFAULTAPPLETWIDTH = 600;
int DEFAULTAPPLETHEIGHT = 600;
String DEFAULTAPPLICRENDERER = OPENGL;
int DEFAULTAPPLICWIDTH = 600;
int DEFAULTAPPLICHEIGHT = 600;
String STRNG = "Fear";
String FONT = "arial.ttf";
int VELOCITY = 1;
float TOLCHANGE = 0.0001;
float INKERRCOEFF = 0.8;
float INKCOEFF = 0.3;
float PRECCOEFF = 0.88;
String newString = "";
void setup(){
int w = DEFAULTAPPLICWIDTH;
int h = DEFAULTAPPLICHEIGHT;
String r = DEFAULTAPPLICRENDERER;
if(!APPLICATION){
w = int(param("width"));
h = int(param("height"));
r = (String)param("renderer");
if(r != OPENGL && r != JAVA2D && r != P2D){
r= DEFAULTRENDERER;
}
if(w<=0){
w = DEFAULTAPPLETWIDTH;
}
if(h<=0){
h = DEFAULTAPPLETHEIGHT;
}
}
size(w,h,r);
frameRate(25);
try{
}
catch(Exception e){
}
background(255);
f = new RFont(this, FONT, 372, RFont, CENTER);
initialize();
}
void draw(){
pushMatrix();
translate(width/2, height/2);
noStroke();
for(int i=0; i<numParticles; i++){
for(int j=0; j<VELOCITY; j++){
psys[i].update(grupo);
psys[i].draw(g);
}
}
popMatrix();
if(SAVEVIDEO) saveFrame("filesvideo/"+STRNG+"-####.png");
toldist += TOLCHANGE;
}
void initialize(){
toldist - ceil(width/200F) * (6F/STRNG.length()+1));
maxvel = width/80F * INKERRCOEFF * (6F/(STRNG.length()+1));
grupo = f.toGroup(STRNG);
RCommand.setSegmentStep(1-constrain(PRECCOEFF,0,0,99));
RCommand.setSegmentator(RCommand.UNIFORMSTEP);
grupo = grupo.toPolygonGroup();
grupo.centerln(g, 5, 1, 1);
background(255);
RPoint[] ps = grupo.getPoints();
numPoints = ps.length;
psys = new Particle[numParticles];
for(int i=0; i<numParticles;i++){
psys[i] = new Particle(g, i, int(float(i)/float(numPartocles)*125));
psys[i].pos = new RPoint(ps[i]);
psys[i].vel.add(new RPoint(random(-10,10)));
}
toldist = 8;
}
void keyReleased(){
if(keyCode==ENTER){
STRNG = newString;
newString = "";
initialize();
}
else if(keyCode==BACKSPACE){
if(newString.length() !=0){
newString = newString.substring(0,newString.lenght()-1);
}
}
else if(keyCode==SHIFT){
newString += key;
}
}
public class Particle{
RPoint vel;
RPoint pos;
RPoint lastpos;
int col;
int hueval;
float sz;
int id;
public Particle(PGraphics gfx, int ident, int huevalue){
pos = new RPoint(random(-gfx.width/2,gfx.width/2);
lastpos = new RPoint(pos);
vel = new RPoint(0,0);
colorMode(HSB);
sz = random(2,3);
id = ident;
hueval = huevalue;
}
public void update(Rgroup grp){
lastpos = new RPoint(pos);
pos.add(vel);
RPoint[] ps = grp.getPoints();
if(ps != null){
float distancia = dist(pos.x.pos.y.ps[id].x.ps[id].y);
if(distancia <= toldist){
id = (id + 1) % ps.length;
}
RPoint distPoint = new RPoint(ps[id]);
distPoint.sub(pos);
distPoint.scale(random(0.028,0.029));
vel.scale(random(0.5,1.3));
vel.add(distPoint);
float sat = constrain((width - distancia) * 0.25,0.001,255);
float velnorm = constrain(vel.norm(),0.maxvel);
sat = abs(maxvel - velnorm)/maxvel*INKCOEFF*255;
sat = constrain(sat,0,255);
col = color(hueval,150,255,sat*(toldist/80));
}
}
public void setPos(RPoint newpos){
laspos = new RPoint(pos);
pos = newpos;
}
public void draw(PGraphics gfx){
noSmooth();
stroke(2);
line(lastpos.x/1.4,lastpos.y/1.4,pos.x/1.4,pos.y/1.4);
}
}