Язык программирования:
C#
Среда программирования:
Microsoft Visual Studio 2015
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Windows.Forms; namespace WindowsFormsApplication7 { public partial class Form1 : Form { //Инициализация bitmap и графики Graphics g; Bitmap bmp; double da = (Math.PI) * 2 / 10;//угол на который сдвигаем центр круга double ang; int x, y; //координаты центра круга int r = 0;//радиус bool Out = true;//определяет направление движения public Form1() { InitializeComponent(); } //круг с центром в точке (x,y) радиуса r void Circle(int x,int y,int r,Color col) { g.FillEllipse(new SolidBrush(col), x - r, y - r, 2 * r, 2 * r); } //функция прорисовки void Draw() { //Создаем bitmap и графику из bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height); g = Graphics.FromImage(bmp); ang = 0; //10 кругов на расстоянии r от центра for (int i = 0; i < 10; i++)//сначала голубые круги { //(x,y)-координаты центра круга x = (int)(Math.Cos(ang) * r + pictureBox1.Width / 2); y = (int)(Math.Sin(ang) * r + pictureBox1.Height / 2); Circle(x, y, 140,Color.FromArgb(150,Color.Cyan)); ang += da; } for (int i = 0; i < 10; i++)//теперь черные круги { x = (int)(Math.Cos(ang) * r + pictureBox1.Width / 2); y = (int)(Math.Sin(ang) * r + pictureBox1.Height / 2); Circle(x, y, 140, Color.FromArgb(50, Color.Black)); ang += da; } } private void timer1_Tick(object sender, EventArgs e) { //если радиус равен нулю ,то то двигаться нужно от центра if (r == 0) { Out = true; Thread.Sleep(800); } //если радиус 70 ,то двигаться нужно к центру if (r == 70) { Out = false; Thread.Sleep(800); } if (Out) r += 5; else r -= 5; Draw();//рисуем круги pictureBox1.Image = bmp;//отображаем bitmap на PictureBox } } }
Прикрепленный файл | Размер |
---|---|
Sherfedinova_circles.zip | 5.42 кб |