1

I want to read a string of numbers from a .txt file on my harddrive, convert the numbers to variables in an array and draw circles with the numbers in the .txt file as radiuses.

This works fine in processing with code like this:

String[] numbers = loadStrings("data.txt"); 
radius = int(split(numbers[0], ',' ));

However, I can't get it to work in basil.js (and have been toying for a week). This is my closest attempt:

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";

function draw() {   

var linesArray = b.loadString("males.txt");
data = int(b.split(linesArray[0], ',' ));

b.ellipse(200, 200, data[0], data[0]);
}

As far as I can tell, it failed to split the numbers in the .txt-file and store it in array.

This is my first post on stackoverflow, forgive my amateurism!

Edit: Here is the link to the txt-file, I want to convert into an array: http://whereverywhere.com/males.txt

  • 1
    Welcome to SO! Please read the [About](http://stackoverflow.com/about) page some time. Can you tell why your "closest attempt" is not good? (Please *edit* your post for that.) – Jongware Dec 16 '13 at 11:10

1 Answers1

1

could you please add to the post the structure of the external data file? otherwise it's quite hard to give you a specific recommendation ...

furthermore there is a tutorial working with CSV files which explains pretty much what you want to do ... and there is this example demos / B08_bar_chart_from_csv_data / bar_chart.jsx which is also very close.

  • Danke! I finally also got your tutorials to work, after I realized I had to put the scripts in the same folder as the Indesign files and the data-folder. I could also modify it to read a single digit from a .txt file and draw the circle, but not load multiple numbers into an array. – user3046833 Jan 05 '14 at 14:01