How to draw a (or two) million lines fast?
992315Feb 20 2013 — edited Mar 4 2013Hello,
I have tried various ways to draw a million lines with JavaFX with little or no success. Can someone help me? What is the best way to accomplish this in JavaFX? The performance is extremely poor (47 seconds) compared to less than 2 sec using Java2D and the memory is huge 14 billion bytes.
I included two functions attempting this in 2 different ways (the scaling is just to write the lines over each other for a window of 1200)
private void drawWaveform(GraphicsContext gc) {
gc.setStroke(Color.FIREBRICK);
byte[] signal = new byte[1000000];
int width = 4;
for(int i = 1; i < signal.length-1; i+=2) {
signal[i] = 100;
}
int factor;
int length = signal.length;
int scalefactor = 1200;
for(int j = 1; j < length; j++){
factor = scalefactor*(j-1)/length;
gc.strokeLine(factor, signal[j-1], factor, signal[j]);
}
}
private void drawWaveform2(GraphicsContext gc) {
byte[] signal = new byte[1000000];
int width = 4;
for(int i = 1; i < signal.length-1; i+=2) {
signal[i] = 100;
}
int factor;
int length = signal.length;
int scalefactor = 1200;
gc.setStroke(Color.FIREBRICK);
for(int j = 1; j < length; j++){
factor = scalefactor*(j-1)/length;
gc.beginPath();
gc.moveTo(factor,signal[j-1]);
gc.lineTo(factor, signal[j]);
gc.stroke();
}
gc.closePath();
}
Thanks for help-- this is fundamental for me and I cannot use JavaFX until I get past it.