#pragma endregion
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
timer1->Enabled = true;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
timer1->Enabled = false;
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
// static constants
static const int xcenter = 200;
static const int ycenter = 250;
static const int smajor = 150;
static const int sminor = 50;
// instance variable
// drawing objects
Drawing::Graphics^ g;
Drawing::Brush^ yellowBrush; //Yellow for the sun
Drawing::Brush^ cyanBrush; // Cyan for planet
// construct drawing objects
g = pictureBox1->CreateGraphics();
yellowBrush = gcnew Drawing::SolidBrush(Color::Yellow);
cyanBrush = gcnew Drawing::SolidBrush(Color::Cyan);
// declare the local variables
int x,y; //x and y coordinates of the planet
double angle_radians; //angle measured in radians
double angle_degrees;
// Refreshing the picture box
pictureBox1->Refresh();
// drawing the sun with rectangle as guide
System::Drawing::Rectangle
sunRect(xcenter,ycenter, 16,16);
g->FillEllipse(yellowBrush,sunRect); //draw sun
//draw the planet
if (angle_degrees >=360) angle_degrees = 0;
angle_radians = angle_degrees * Math::PI / 180;
// calculate new x and y
x = xcenter + smajor * Math::Cos(angle_radians);
y = ycenter - sminor * Math::Sin(angle_radians);
// draw planet
System::Drawing::Rectangle planetRect(x,y,10,10);
g->FillEllipse(cyanBrush,planetRect);
// increasing angle by 5 degrees
angle_degrees += 5;
}
};
}
This post has been edited by GunnerInc: 03 August 2012 - 09:41 AM
Reason for edit:: Fixed code tags, removed email

New Topic/Question
Reply


MultiQuote




|