please format code with </> button * homework policy * asking questions
I am trying to import my p5js code to processing, its almost working, but when i try to load the program it cames this error:
StringIndexOutOfBoundsException: String index out of range: -1907998
The code if you want:
import processing.video.*;
String density = "BadAppleBadAppleBadAppleBadAppleBadAppleBadApple";
Movie badapple;
void setup() {
size(128,72);
badapple = new Movie(this,"BadApple.mp4");
badapple.play();
}
void draw() {
badapple.loadPixels();
String asciiImage = "";
for (int j = 0; j < badapple.height; j++) {
for (int i = 0; i < badapple.width; i++) {
int pixelIndex = (i + j * badapple.width) * 4;
int r = badapple.pixels[pixelIndex + 0];
int g = badapple.pixels[pixelIndex + 1];
int b = badapple.pixels[pixelIndex + 2];
int avg = (r + g + b) / 3;
int len = density.length();
int charIndex = floor(map(avg,0,255,0,29));
int c = density.charAt(charIndex);
if (c == ' ') asciiImage += " ";
else asciiImage += c;
}
asciiImage += "\n";
}
text(asciiImage,0,0);
}
void movieEvent(Movie m) {
m.read();
}