/*
* Created by SharpDevelop.
* User: Добромир
* Date: 3.3.2021 г.
* Time: 17:55
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Animation_of_apple_tree
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
Random rnd;
Point[] apple;
bool clash;
Timer tmr;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
rnd = new Random();
apple = new Point[5];
LoadApples();
tmr = new Timer();
tmr.Enabled = true;
tmr.Interval = 700;
tmr.Tick += new EventHandler(Falling);
}
void MainFormPaint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Tan, 130, 150, 40, 140);
e.Graphics.DrawRectangle(Pens.Brown, 130, 150, 40, 140);
e.Graphics.FillEllipse(Brushes.LightGreen, 65, 10, 170, 150);
e.Graphics.DrawEllipse(Pens.Brown, 65, 10, 170, 150);
for(byte i = 0; i < 5; i++)
e.Graphics.FillEllipse(Brushes.Red, apple[i].X - 12, apple[i].Y - 12, 24, 24);
}
void MainFormKeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)27) Application.Exit();
}
void LoadApples()
{
for(byte i = 0; i < 5; i++)
{
do
{
double R = 75.0 * rnd.NextDouble(),
angle = 2.0 * Math.PI * rnd.NextDouble();
apple[i] = new Point(150 + (int)(R * Math.Cos(angle)),
85 + (int)(R * Math.Sin(angle)));
clash = false;
for(byte j = 0; j < i; j++)
if((apple[i].X - apple[j].X) * (apple[i].X - apple[j].X) +
(apple[i].Y - apple[j].Y) * (apple[i].Y - apple[j].Y) < 700)
clash = true;
}
while(clash);
}
}
void Falling(object sender, EventArgs e)
{
int i = 0;
while(i < 5 && apple[i].Y > 275) i++;
if(i < 5)
apple[i].Y += 12;
else
LoadApples();
this.Invalidate();
}
}
}
/*
* Created by SharpDevelop.
* User: Добромир
* Date: 3.3.2021 г.
* Time: 17:55
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Animation_of_apple_tree
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
Random rnd;
Point[] apple;
bool clash;
Timer tmr;
byte numberOfFallingApple;
int fallingVelocity;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
rnd = new Random();
apple = new Point[5];
LoadApples();
tmr = new Timer();
tmr.Enabled = true;
tmr.Interval = 700;
tmr.Tick += new EventHandler(Falling);
numberOfFallingApple = 0;
fallingVelocity = 0;
}
void MainFormPaint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Tan, 130, 150, 40, 140);
e.Graphics.DrawRectangle(Pens.Brown, 130, 150, 40, 140);
e.Graphics.FillEllipse(Brushes.LightGreen, 65, 10, 170, 150);
e.Graphics.DrawEllipse(Pens.Brown, 65, 10, 170, 150);
for(byte i = 0; i < 5; i++)
e.Graphics.FillEllipse(Brushes.Red, apple[i].X - 12, apple[i].Y - 12, 24, 24);
}
void MainFormKeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)27) Application.Exit();
}
void LoadApples()
{
for(byte i = 0; i < 5; i++)
{
do
{
double R = 75.0 * rnd.NextDouble(),
angle = 2.0 * Math.PI * rnd.NextDouble();
apple[i] = new Point(150 + (int)(R * Math.Cos(angle)),
85 + (int)(R * Math.Sin(angle)));
clash = false;
for(byte j = 0; j < i; j++)
if((apple[i].X - apple[j].X) * (apple[i].X - apple[j].X) +
(apple[i].Y - apple[j].Y) * (apple[i].Y - apple[j].Y) < 700)
clash = true;
}
while(clash);
}
}
void Falling(object sender, EventArgs e)
{
apple[numberOfFallingApple].Y += fallingVelocity;
fallingVelocity++;
if(apple[numberOfFallingApple].Y > 260)
{
numberOfFallingApple++;
fallingVelocity = 0;
if(numberOfFallingApple > 4)
{
numberOfFallingApple = 0;
LoadApples();
}
}
this.Invalidate();
}
}
}
Регистрирани потребители: Google [Bot]