For most of the year, because of my previous Objective-C/C experience I've been flying through my CS labs but I'm stuck on this particular exercise.
We have to make a program which draws a 5 sided star and eventually change it into a program that draws spiralgraphs. Now the following point of a star is defined as (Where i is the point of a star)
xi + 1 = xi + LineLength * cos(theta)
yi + 1 = yi + LineLength * sin(theta)
I get this little tiny blob in the corner of my window. I have no clue whats wrong with my code.
This is actually C#, but whatever, its similar to Java.
We have to make a program which draws a 5 sided star and eventually change it into a program that draws spiralgraphs. Now the following point of a star is defined as (Where i is the point of a star)
xi + 1 = xi + LineLength * cos(theta)
yi + 1 = yi + LineLength * sin(theta)
I get this little tiny blob in the corner of my window. I have no clue whats wrong with my code.
This is actually C#, but whatever, its similar to Java.
Code:
//Declare Variables
double starLength = numericLength.Value;
double x = 0, y = 0, xi = 0, yi = 0;
const double angle = 4 * Math.PI / 5;
Graphics paper = picStar.CreateGraphics();
Pen pen1 = new Pen(Color.Black, 5);
//Draw the star
for (int i = 1; i <= 5; ++i)
{
//Calculate xi +1, yi + 1
xi = x + (starLength * Math.Cos(angle));
yi = y + (starLength * Math.Sin(angle));
//Draw the line
paper.DrawLine(pen1, (int)x, (int)y, (int)xi, (int)yi);
//Make x, y -> xi, yi
x = xi;
y = yi;
}