Jean Poutine
December 10th, 2008, 05:37 AM
I've got a little problem...I've got something to do where a user has to select 2 colors, a form, enter a number and it draws squares that fill up the shape while alternating colors.
I've got that all right, my problem is that it alternates them TOO well.
So far I've got this code for the brush colours :
switch (cboCouleur1.SelectedIndex)
{
case 0 :
d1 = rouge;
break;
case 1 :
d1 = bleu;
break;
case 2 :
d1 = jaune;
break;
case 3 :
default :
d1 = orange;
break;
}
switch (cboCouleur2.SelectedIndex)
{
case 0:
d2 = rouge;
break;
case 1:
d2 = bleu;
break;
case 2:
d2 = jaune;
break;
case 3:
default:
d2 = orange;
break;
}
This works. Now the code for a square, which works perfectly :
if (rdoCarre.Checked)
for (cy = 0; cy != nombre; cy++) //calculates the number of squares following y axis
{
x = 0;
for (cx = 0; cx != nombre; cx++) //does the same for x axis, fills 'em up then...
{
if (brosse) //that's a boolean
utilise = d1;
else
utilise = d2;
wtf.FillRectangle(utilise, x, y, 10, 10);
x = x + 15;
brosse = !brosse;
}
y += 15; //changes lines once the loop has been executes n times
}
My problem comes with the inverted triangle...
if (rdoTriangleInverse.Checked)
for (cy = nombre; cy != 0; cy = cy -1) //same as square
{
x = 0;
for (cx = 0; cx != nombre; cx++) //same as square
{
if (brosse)
utilise = d1;
else
utilise = d2;
wtf.FillRectangle(utilise, x, y, 10, 10);
x = x + 15;
brosse = !brosse;
}
y += 15; //switches line...
nombre = nombre - 1; //substract from the number to get that super triangle sensation!
}
Except on the example program it's supposed to be :
(1)(2)(1)(2)(1)
(2)(1)(2)(1)
(1)(2)(1)
(2)(1)
(1)
And on mine it does :
(1)(2)(1)(2)(1)
(2)(1)(2)(1)
(2)(1)(2)
(1)(2)
(1)
I was wondering if there was something I'm doing wrong. The square works perfectly...the triangles, not.
Note that I must turn this in tomorrow morning so I just want to know for amusement's sake. I got farther into this than most in my class would be able to alone, anyway.
Thanks!
I've got that all right, my problem is that it alternates them TOO well.
So far I've got this code for the brush colours :
switch (cboCouleur1.SelectedIndex)
{
case 0 :
d1 = rouge;
break;
case 1 :
d1 = bleu;
break;
case 2 :
d1 = jaune;
break;
case 3 :
default :
d1 = orange;
break;
}
switch (cboCouleur2.SelectedIndex)
{
case 0:
d2 = rouge;
break;
case 1:
d2 = bleu;
break;
case 2:
d2 = jaune;
break;
case 3:
default:
d2 = orange;
break;
}
This works. Now the code for a square, which works perfectly :
if (rdoCarre.Checked)
for (cy = 0; cy != nombre; cy++) //calculates the number of squares following y axis
{
x = 0;
for (cx = 0; cx != nombre; cx++) //does the same for x axis, fills 'em up then...
{
if (brosse) //that's a boolean
utilise = d1;
else
utilise = d2;
wtf.FillRectangle(utilise, x, y, 10, 10);
x = x + 15;
brosse = !brosse;
}
y += 15; //changes lines once the loop has been executes n times
}
My problem comes with the inverted triangle...
if (rdoTriangleInverse.Checked)
for (cy = nombre; cy != 0; cy = cy -1) //same as square
{
x = 0;
for (cx = 0; cx != nombre; cx++) //same as square
{
if (brosse)
utilise = d1;
else
utilise = d2;
wtf.FillRectangle(utilise, x, y, 10, 10);
x = x + 15;
brosse = !brosse;
}
y += 15; //switches line...
nombre = nombre - 1; //substract from the number to get that super triangle sensation!
}
Except on the example program it's supposed to be :
(1)(2)(1)(2)(1)
(2)(1)(2)(1)
(1)(2)(1)
(2)(1)
(1)
And on mine it does :
(1)(2)(1)(2)(1)
(2)(1)(2)(1)
(2)(1)(2)
(1)(2)
(1)
I was wondering if there was something I'm doing wrong. The square works perfectly...the triangles, not.
Note that I must turn this in tomorrow morning so I just want to know for amusement's sake. I got farther into this than most in my class would be able to alone, anyway.
Thanks!