i am trying to write nested for loops to iterate through combinatorial number sequences, nCr. so far, i have gotten 4C2 to work:
1, 2
1, 3
1, 4
2, 3
2, 4
however, i am struggling with 4C3.
the loop iterates through:
1, 2, 3
1, 2, 4
1, 3, 4
and then stops and (l) instead of going to:
2, 3, 4
also my control loop doesn't decrease even though i have (i --) as the last condition.
this seems like a terrible way to do this; is there another type of data structure to do this. i would like to have these loops automated to work with whatever combinatorial number sequence it is given. however, i realized that the number of nests has to be equal to n, so that seems it would be difficult to add nests within a loop through iteration.
here's my code so far:
int n = 4;
int digit = 3;
int counter2 = 2;
int counter3 = 3;
// my output for the following loop works except for (l). the sequence i get is (jkl) 123, 124, 134, 23.... it never goes back to l, which should be 4. instead j remains iterating between the values of 1 and 2.
void draw()
{
// for(int i = combN(n, digit); i > 0; i --)
// { println("i" + ", " + i);
for(int j = 1; j <= n - 2; j ++)
{ println("j" + ", " + j);
for(int k = counter2; k <= n - 1; k ++)
{ println("k" + ", " + k);
for(int l = counter3; l < n + 1; l ++)
{
println("l" + ", " + l);
// println(i + ", " + j + ", " + k + ", " + l + ", " + counter3);
}
counter3 ++;
}
counter2 ++;
}
// }
}
int factN(int n)
{
if (n <= 1) return 1;
else return n * factN(n - 1);
}
int combN(int n, int digit)
{
if (digit == n) return 1;
else return factN(n)/(factN(digit) * factN(n - digit));
}
void combTwo()
{
for(int i = combN(n, digit); i > 0; i --)
{
for(int j = 1; j <= n - 1; j ++)
{
for(int k = counter2; k < n + 1; k ++)
{
println(j + ", " + k);
}
counter2 ++;
}
}
}
i have a sketch for which pausing is user-controlled. i have figured out the pausing, however when pause = true, the image disappears. is there a way to pause my sketch an keep the current frame visible?
i am trying to read brightness values from a buffer. there is data in the image, but when i try to print the values, i get 0.0 for all pixels. i have a second buffer for which the values are reading. (i have found that there is a much better and shorter way to do this, but i am curious as to why the values aren't registering.)
as a part of a project i've written a return type function to return a minimum number from a continuing string of numbers received. the function should return a minimum value for each collection of numbers it is sent (per frameNum). it seems like it should be straight forward, but i am getting nothing but '0' as my return value. i've checked to see if the numbers are being appended to array; they are. but, i noticed that my counter, which keeps track of that process never exceeds 1. while that is a problem in itself, even though the counter never exceeds '1,' the program seems to enter the following conditional statement; it shouldn't. if my counter never exceeds 1, i don't see how it can be >= my maxNum value. however, when i use println statements to check what's going on within the conditional, it's printing my queries.
the two days i've spent seems way too long to write min value function. maybe i've been looking at it too long.
does anyone see what's going on with this function?:
//declared variables
int minNumCounter = 0
int frameNum = 0;
int numFrames = 8;
int maxNums = 200;
//function call
minReturnFunc(streamOfValues);
//function
int minReturnFunc(int sentValue)
{
Array[minNumCounter] = sentValue;
i am drawing to a buffer for a project, but realized that the screen wouldn't redraw. i moved my background(0); from draw() to within beginDraw() and endDraw(). however, it doesn't work. i could do without the buffer, but i am curious as to why this is an issue. here is some sample code that replicates the problem:
i am creating an image viewer by counting frames. when the frameCounter hits a defined threshold, i would like it to fade the image for the rest of the duration, however, the condition, although met, is never interpreted. an extra pair of eyes would be greatly appreciated. why does the program never enter the embedded conditional for frameCounter <= 150?
thanks much.
my code:
int numImages = 4;
int numFrames = 3000;
int imageCounter = 0;
int frameCounter = (int)(numFrames/numImages);
i have a running program for which i would like to implement a controlp5 interface. i have created the interface, but the values i am controlling are not being passed to my objects. i am using 2 sliders, 2 sliders with tickmarks and 2 check boxes.
does controlp5 not work with variables passed to classes and variables that are not directly accessed in draw()? do i need to implement event listeners for the sliders and check boxes?
i've mapped an image to a cylinder in processing. the texture is mapped to the xyzuv coordinates, however, the texture overlaps. if i double the number of sides, there's an extra space between the beginning and end of the texture.
// draw top of the tube
beginShape();
for (int i = 0; i < sides; i++) {
float x = cos( radians( i * angle ) ) * r;
float z = sin( radians( i * angle ) ) * r;
vertex( x, -halfHeight, z);
}
endShape(CLOSE);
// draw bottom of the tube
beginShape();
for (int i = 0; i < sides; i++) {
float x = cos( radians( i * angle ) ) * r;
float z = sin( radians( i * angle ) ) * r;
vertex( x, halfHeight, z);
}
endShape(CLOSE);
// first texture
beginShape(QUAD_STRIP);
texture(img);
for (int i = 0; i <= sides; i++) {
float x = cos( radians( i * angle ) ) * r;
float z = sin( radians( i * angle ) ) * r;
vertex( x, -halfHeight, z, img.width/sides * i, 0);
vertex( x, halfHeight, z, img.width/sides * i, img.height);
}
endShape(CLOSE);
}