# Type + Code (Caligraft Sketch)

**URL:** https://discourse.processing.org/t/type-code-caligraft-sketch/12237
**Category:** Libraries
**Created:** [June 22, 2019, 5:59am UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237 "2019-06-22T05:59:42Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![PixelMx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pixelmx/32/4478_2.png) [@PixelMx](https://discourse.processing.org/u/PixelMx)
#### Post date: [June 22, 2019, 5:59am UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/1 "2019-06-22T05:59:42Z")

</div>

I was trying to replicate some code from the book [Type + Code](https://issuu.com/jpagecorrigan/docs/type-code_yeohyun-ahn) (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.

```auto
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);
  }
}

    

```

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [June 22, 2019, 6:50am UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/2 "2019-06-22T06:50:11Z")

</div>

Quite simply, yes, it used to be possible.

I’m not sure exactly why it was removed, but it might have been confusing and not really needed.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 22, 2019, 8:45am UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/3 "2019-06-22T08:45:47Z")

</div>

> [@PixelMx](#):
>
> Was it possible to use variables on the size function on previous version of processing?

- [Ok to use constants in call to size() in immediate mode? - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/12105/ok-to-use-constants-in-call-to-size-in-immediate-mode#Item_1)

> <https://github.com/processing/processing/issues/4328#issuecomment-203934010>
>
> The following code refuses to compile in Processing 3.0.2, despite the fact that… the \`final\` keyword is used to create constants, not variables.
> 
> \`\`\`
> final int dim = 40;
> 
> void setup() {
> size(dim, dim); 
> }
> \`\`\`
> 
> The error is "the size of your sketch could not be determined", but reasonably speaking it should be entirely possible to.
> 
> It feels like this is either a regression w.r.t Processing 2.x, which compiled this code just fine, or is an issue with the IDE's syntax validator possibly using "numbers" (very easy to verify, but wrong) rather than "number constants" (harder to verify because a symbol table needs to be consulted to check for \`final \[int|long|etc\]\` type, but correct) to do its signature validation.

---

<div class="post-metadata">

### Author: ![PixelMx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pixelmx/32/4478_2.png) [@PixelMx](https://discourse.processing.org/u/PixelMx)
#### Post date: [June 22, 2019, 6:41pm UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/4 "2019-06-22T18:41:19Z")

</div>

Thanks for the clear up!  
After I fixed the size problem I get the following error with this portion of the code

The constructor RFont(caligraft\_dibuixant, String, int, int) is undefined

```auto
f = new RFont(this, FONT, 372, RFont, CENTER);

```

but I’m declaring it in the begining

```auto
RFont f;

```

What am I missing here?  
Thanks in advance (again)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 22, 2019, 8:27pm UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/5 "2019-06-22T20:27:10Z")

</div>

Check the number of parameters first

It must the same in this line (with `new`) as in the constructor

Then check the type of each parameter - must match as well

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [June 23, 2019, 12:54am UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/6 "2019-06-23T00:54:37Z")

</div>

the book / site info is 10 years old  
and misses a info what processing version was used.

* * *

so let’s make it better and give all your sketch code  
a file header with

- filename
- creation/revision date
- author and copyright
- environments tested ( OS / processing version / loaded libs + version…)

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [June 28, 2019, 3:24pm UTC](https://discourse.processing.org/t/type-code-caligraft-sketch/12237/7 "2019-06-28T15:24:26Z")

</div>

Processing and geomerative have both changed – when you hit an error in size, it is because Processing changed (now uses settings) – when you hit an error in Rfont, it is because RFont has changed (now takes different constructor arguments).

Keep in mind two general ways to approach this problem:

1, In both cases,ook at the current references (for Processing 3 and for the latest geomerative), and update the code accordingly.

1. Try to run an old version of Processing – available from the Processing downloads page – with an old version of Geomerative – so that the code example you are working with runs on those specific versions, with the correct size and RFont.
