We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Type tutorial? (Read 563 times)
Type tutorial?
Oct 7th, 2009, 9:38am
 
Hi i'm an extremely new user, and i'm looking for as many tutorials etc for processing as possible are there any other tutorials other than in the learning section of this site?

specifically at the moment i am looking for a way to import a list of numbers from a .txt file to use in a few ways, one being to sort the numbers into a line in ascending order, bt cant find much in the way of help using the strings and loadStrings functions. Any help would be  brilliant! L.
Re: Type tutorial?
Reply #1 - Oct 7th, 2009, 12:43pm
 
Here the loadNumbers function asks for a file name, suppose the file contains 4 numbers in a row, two integers then two floats, all separated by tabs. It splits each line into four elements and convert them into numbers to assign to temporary variables x, y, fx, and fy. It also stores x values in an array. The array starts with zero elements and expands every time a new number is added.

void loadNumbers(String fileName)
{
 String[] lines;
 int[] xArray=new int[0];
 int index = 0;
 lines = loadStrings(fileName); //Ask file name.
 while (index < lines.length)
 {
   String[] pieces = split(lines[index], '\t');
   if (pieces.length == 4)
   {
     int x = int(pieces[0]);
     int y = int(pieces[1]);
     float fxm = float(pieces[2]);
     float fy = float(pieces[3]);
     xArray=(int[])append(xArray,x); // Add the new number to the end of the array.
   }
     index ++;
 }
 
 return (loadVectors);
}
Page Index Toggle Pages: 1