I have both Processing 1.2.1. & 1.5.1 installed on my machine - Windows 7, 64 bit. They have worked fine for many years. However, each time I install Processing 2.0 (or any of the earlier beta versions thereof) I can't seem to set the file associativity in such a way that the machine automatically recognises version 2.0. Version 1.5.1 is always started by default. Even when I try the ‘Open with’ option I can't manage to force the system to get version 2.0 recognised. It doesn't get recognised. I then went into ‘regedit’ and amended the file associativity there but still no joy. All of the versions were installed by extracting the folder from the website, unzipping and placing inside ‘Program Files’. Has anybody had a similar experience and managed to overcome this? I haven’t yet been able to find any related threads on the forum regarding this issue.
If you have objects all of one class, how do you differentiate between them? This is the issue: I have a class that generates boxes in a 2D array (class name = Block). Depending on how they interact with their environment, their individual size changes so that there are small boxes (those with a width and depth less than 35 pixels) and larger blocks (those with a width and depth of more than 35 pixels). I want to be able to differentiate between blocks on the basis of their size, albeit all from the same class, so that the smaller blocks, when acceleration is added to them, won’t ‘walk’ into the larger blocks. It seems the larger blocks should have a neighbourhood radius and be should be able to measure any small blocks that come into their radius space. When they do, the smaller blocks must stop moving. This is what I currently have but I can't get this function to work:
float distance(Block [][]grid)
{
for (int i = 0; i < grid.length; ++i)
{
for (int j = 0; j < grid.length; ++j)
{
if (grid[i][j].depth > 35 && grid[i][j].w > 35) // go through the loop for large blocks
{
for (int m = 0; m < grid.length; ++m)
{
for (int n = 0; n < grid.length; ++n)
{
if (grid[m][n].h == 35 && grid[m][n].depth == 35 && grid[m][n].w == 35) // go through the loop for smaller blocks
{
distanceBlock = PVector.dist(grid[i][j].pos, grid[m][n].pos);
}
}
}
}
}
}
return distanceBlock;
}
Perhaps I need to look into an id or serial number for each block rather than the strategy outlined above. I've been working on this sketch for some time and any suggestions as how to solve this issue would be greatly appreciated.
I hope my question makes sense. I am parsing data for 10 cities through the BufferedReader class and using this information further downstream in my code. It all works fine, however, I am trying to compress the repetitive unweildy parts in the code to a single function where only the names are being changed. At present I have 10 identical functions (with only the names changing), one for each city, called inside void draw(), and looks like this:
void parseManchester()
{
try
{
String line = reader[0].readLine();
if (line == null)
{
}
else
{
String [] bits = line.split(",");
float valuesMANCHESTER = float(bits[0]);
float MANCHESTERnormalised;
MANCHESTERnormalised = norm(valuesMANCHESTER, minNorm, maxNorm);
MANCHESTERlist.add(MANCHESTERnormalised); }
int numCities = 10;
String cityNames = ("MANCHESTER,LONDON,WASHINGTON,DAKAR,CHICAGO,SHANGAI,TOKYO,ATLANTA,
LUTON,RIO,NAIROBI");
Works fine to here. This is where I am getting stuck, trying to use the parsed names to create variables inside the function:
void matrixParse()
{
for (int i = 0; i < numCities; ++i)
{
try
{
String line = reader[0].readLine();
if (line == null)
{
}
else
{
String [] bits = line.split(",");
//println ("values"+nameList[i]); // comes out fine: valuesMANCHESTER, valuesLONDON etc
String valCity = "values" + nameList[i]; // comes out fine: valuesMANCHESTER, valuesLONDON etc
float valCity = float(bits[0]); // PROBLEM HERE: can't use valCity again because the
float MANCHESTERnormalised;
MANCHESTERnormalised = norm(valuesMANCHESTER, minNorm, maxNorm);
MANCHESTERlist.add(MANCHESTERnormalised);
}
}
Might someone have an idea how to overcome this problem? Thanks in advance.
void train(int i, ArrayList w)
{
for (int i = w.size()-1; i > 0; --i) //counting backwards through the ArrayList
{
// error in this line: ClassCastException: java.lang.Float cannot be cast to java.util.ArrayList:
}
int ndxComposite = findBMU(tempList);
// (etc ...)
}
I have tried substituting the problem line with:
float tempList = (Float) w.get(i);
however, this is casting the outcome as floats, whereas the function is expecting an ArrayList, so I get an error further down in the function. I realise that I can convert the ArrayLists inside the Arraylist to arrays beforehand but would prefer not to, in this case. The code becomes unwieldy.
Any suggestions will be greatly appreciated.
Hi,
I am parsing floating point numbers from 5 .csv files through Processing and ultimately end up with 5 nos. arrays that contain the parsed data for each file. Each array consists of 199 elements. So far so good.
Now, what I need to do is to get Processing to grab one of the arrays, at random, so it knows ‘ok, use item3Array’, together with its associated contents list. I was thinking to list the arrays as a 1D array and to call a random index from the 1D array:
float[] myOneDimensionalArrayofArrays = { item1Array, item2Array, item3Array, item4Array, item5Array };
int randomChoice = myOneDimensionalArrayofArrays [(int)(random(5))];
However, the syntax doesn’t work in the manner I tried – I guess I need to find another way of listing the ‘array of arrays’. I looked at a number of proposals posted on the Forum previously. Concatenating the arrays or creating an ArrayList, as I understand it, just creates a long list of data, rather than a list from which I can grab a subgroup from, unless I somehow looped through every 199th element to get the randomly chosen subgroup.
Might anyone have an idea how I could approach this matter?
Repel [] repeller;
PVector attractVec1 = new PVector(width/2, height/2, width/2);
PVector attractVec2 = new PVector(width, height, width);
PVector attractVec3 = new PVector(width/4, height/4, width/4);
PVector attractVec4 = new PVector(width/8, height/8, width/8);
PVector [] vecPosArray = {attractVec1, attractVec2, attractVec3, attractVec4};
void setup()
{
repeller = new Repel[vecPosArray.length];
//repeller = new Repel[4];
for (int i = 0; i < repeller.length; ++i)
{
//vecPosRepel = new PVector (random(width), random(height), random(height));
//repeller[i] = new Repel(vecPosRepel);
repeller[i] = new Repel(vecPosArray[i]);
}
}
void draw()
{
for (int i = 0; i < repeller.length; ++i)
{
repeller[i].display();
}
}