2

I'm trying to space text logarithmically. My goal is essentially the same as the one presented here, which is useful but doesn't help me as the only advice provided is to use JS, which I'm not familiar enough with to write something like this in from scratch, let alone in Illustrator.

Here is some code linked in the answer I'm referring to (JSFiddle):

function log10(val) {
  return Math.log(val) / Math.LN10;
}
var paper = Raphael('meh', 1000,1000);
for (var i = 1; i <= 100; i++) {
    var log = log10(i) * 125;
    var yPos = 260 - log;
    var r = paper.rect(0,yPos,5,1,1);
    if (i==1 || i==10 || i==100) {
      paper.text(15,yPos,i);
    }
  r.attr({opacity: 0.6, 'stroke-width': 0, fill: '#000000'});
    console.log(yPos);
};

Credit: user568458

My first thought was to use a blend and replace the spine, but as I'm using outlined text, that wouldn't work. It would blend between the letters as well as space them but that's not what I want. I need the letterforms to stay intact.

If someone could help me adapt this code to a script that I could run in Illustrator I would appreciate it. I would need to be able to input custom values to control the spacing each time I ran the script.

EDIT: Thanks for the replies so far. Here's an image of what I'd like to accomplish. I placed these letters by hand using the logarithmic grid tool in illustrator, but I have several hundred characters of text I'd like to set with varying bases to achieve different spacings.

Logarithmically spaced letters.

2
  • 1
    Can you put an image of your desired result? For example, are you spacing different letters or the same letters? Vertically? Only in black color?
    – Silly-V
    Apr 26, 2017 at 16:57
  • Illustrator javascript is not the same thing as normal javascript sp none of the web programming API thing applies.
    – joojaa
    Apr 26, 2017 at 17:17

1 Answer 1

3
#target illustrator

function log10(val) {
  return Math.log(val) / Math.LN10;
}


docRef=app.activeDocument;
for (var i = 1; i <= 20; i++) {
    var pointTextRef = docRef.textFrames.add();
    pointTextRef.contents = "Text #"+i;
    pointTextRef.translate(10,400*log10(i));
};
3
  • Thank you for the reply, but I can't seem to get that to work. I've saved it as a JS file but anytime I try to run it, whether by drag & drop or from 'File > Scripts > Other Script...' nothing happens. Sorry if I'm just missing something super basic.
    – alecmarcus
    Apr 27, 2017 at 18:18
  • Normally the file extension should be jsx. Are you sure you have a document open.
    – joojaa
    Apr 27, 2017 at 20:00
  • Ah, I see now. I was assuming the script was designed to space/align pre-existing objects, but I see that it's designed to create text. I was trying to run it on objects that already existed. My apologies for not being specific enough; I would like to be able to apply horizontal logarithmic spacing/distribution, similar to the equal spacing offered by the Align tool. I have many objects that I would like to select and apply the spacing to. My edit in the question shows a simple depiction.
    – alecmarcus
    Apr 27, 2017 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.