Advice needed please, I don't understand why I keep getting nullpointer exception in
void draw for this array called "numbers", the exception crops up in line 17, as soon as I reference
numbers.length. And
here's the data file that's loaded into
loadStrings, for testing.
thanks,
Scott
String[] lines;
float[] numbers;
void setup() {
size(1000,500);
lines = loadStrings("conduct-small.txt");
float[] numbers = new float[lines.length];
for (int k = 0; k < lines.length; k++){
String[] pieces = split(lines[k], ',');
numbers[k] = float(pieces[5]);
println(numbers[k]);
}
}
void draw(){
println(numbers.length);
int test = int(random(numbers.length));
float num = numbers[test] * -0.5; //roughly scaling the data so that it's relative to the middle of the sketch
ellipse(width/2,height/2, num, num); // line from bottom of sketch up to "num" (scaled "pieces[5]") value
I just can't see where I'm going wrong here, sure this code should give me five differently colored, independently moving ellipses :( Any help appreciated.
- code is modified from Shiffman's Nature of Code ex1.5
I've never seen this before, this sketch is capturing chunks of screen when it renders (see image below), anyone know what's causing it? We should be seeing only the coloured triangles that appear top-left of sketch, oddly we also see the triangles before colouring but displaced (it seems) to bottom-right...
I'm on OSX 10.6.8, Processing 2.0b.5
float angle=0;
int numPoints = 100;
float[] triX, triY, triZ;
float rx, ry, rz;
color[] col;
void setup() {
size(800,800,P3D);
frameRate(12);
background(255);
smooth();
//noLoop();
colorMode(HSB,1000);
triX = new float[numPoints];
triY = new float[numPoints];
triZ = new float[numPoints];
col = new color[numPoints];
for (int i = 0; i < numPoints-2; i++){
float circ = 400 + ((1+sin(angle))*(600/2)); //sin(angle) = -1 to +1, so add one to get range 1 to 2, then multiply by colour range 255 divided by 2
float circ1 = 400 + ((1+sin(angle/3))*(600/2)); //add HSB offset of 400 to avoid low register