Drawing with point(x,y) and an array of integers for x,y works only partially
in
Programming Questions
•
1 year ago
Hi,
I'm working on a digital and analog scope application. The code below draws the basic scope screen (works), and then displays an analog and a digial channel with simulated signals (works partially).
The
final for loop generates the correct output in the terminal window, but on the scope display only about the first quarter of the two signals a_signal[] and d_sign[] (arrays of length width) is being drawn.
What am I doing wrong???
int traces = 2; //number of traces = channels, must be even!
int[] base = {200, 600}; // array of channel base line locations
void setup() {
size(1000, 800);
background(0); //scope-like black screen background
noLoop();
noSmooth();
stroke(0,0,255, 255); //strong blue for outer frame
line(0,0,width,0); //frame
line(0,0,0,height); //frame
line(width-1,0,width-1,height); //frame
line(0, height-1, width, height-1); //frame
stroke(0,128,128,128); //transparent green for base lines
line(0,base[0],width-1,base[0]); //analog channel base line
line(0,base[1],width-1,base[1]); //digital channel base line
stroke(0,128,128,64); //weak green for screen middle separation
line(0,height/2,width-1,height/2); //screen middle separator
}
void draw() {
int[] a_signal = new int[width]; //analog data channel content
int[] d_signal = new int[width]; //digital data channel content
int amplitude = height / (traces *4) - 10; //max swing of signal trace
for (int i=0; i<width; i=i+1) {
a_signal[i] = int(amplitude * sin((TWO_PI/width)*i));
}
for (int i=0; i<width; i=i+1) {
if (i< width/2) {
d_signal[i] = amplitude;
} else {
d_signal[i] = 10;
}
}
for (int i=0; i<width; i=i+1) {
point(i, base[0]-a_signal[i]);
point(i, base[1]-d_signal[i]);
print(i + " " + a_signal[i] + " " + d_signal[i]);
println();
}
println (width);
}
1