Newbie:Actualization of canvas only in draw()?
in
Programming Questions
•
2 years ago
Hello,
sending information to the canvas from the next lower level of draw(), how can I get an actualization of the canvas immediately?
I try to visualize data from the iterations of a bubble-sort. When actualizing from draw(), everything is fine, but when I try the same from inside the Bubble-routine whch is called in draw(), I only get an actualization returning to the draw()-function. What can I do?
Here is my code:
int[] vec = {10,2, 28,29,4,19,7,88,1,0};
void setup()
{
size(300, 300);
frameRate(150);
noLoop();
}
void draw() {
fill(0,0,0);
//paintEl(vec, 20,100); // canvas actualization
bubbleSort(vec);
//paintEl(vec, 150,200); // canvas actualization
}
void bubbleSort(int array[])
{
boolean swapped = true;
for ( int i=array.length-1; i>0 && swapped; i--)
{
swapped=false;
for (int j=0; j<i; j++)
{
paintEl(vec, j+150,j+200); // NO canvas actualization
delay(100);
if (array[j] > array[j+1]) {
int temp =array[j];
array[j] = array[j+1];
array[j+1] = temp;
swapped=true;
}
}
}
}
void paintEl(int [] array, int startrow, int startcol) {
ellipse( startrow, startcol, 5,5);
}
Thanks for help in advance!!
Carlos
sending information to the canvas from the next lower level of draw(), how can I get an actualization of the canvas immediately?
I try to visualize data from the iterations of a bubble-sort. When actualizing from draw(), everything is fine, but when I try the same from inside the Bubble-routine whch is called in draw(), I only get an actualization returning to the draw()-function. What can I do?
Here is my code:
int[] vec = {10,2, 28,29,4,19,7,88,1,0};
void setup()
{
size(300, 300);
frameRate(150);
noLoop();
}
void draw() {
fill(0,0,0);
//paintEl(vec, 20,100); // canvas actualization
bubbleSort(vec);
//paintEl(vec, 150,200); // canvas actualization
}
void bubbleSort(int array[])
{
boolean swapped = true;
for ( int i=array.length-1; i>0 && swapped; i--)
{
swapped=false;
for (int j=0; j<i; j++)
{
paintEl(vec, j+150,j+200); // NO canvas actualization
delay(100);
if (array[j] > array[j+1]) {
int temp =array[j];
array[j] = array[j+1];
array[j+1] = temp;
swapped=true;
}
}
}
}
void paintEl(int [] array, int startrow, int startcol) {
ellipse( startrow, startcol, 5,5);
}
Thanks for help in advance!!
Carlos
1