Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top