using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace C__Project_3
{
public partial class Form1 : Form
{
private class Ornament
{
public int X { get; set; }
public int Type { get; set; }
}
private List<Ornament> ornaments = new List<Ornament>();
private int startY = 50;
private int spacing = 50;
public Form1()
{
InitializeComponent();
this.Resize += WindowResized;
}
private void Form1_Load(object sender, EventArgs e)
{
InitializeOrnaments();
}
private void WindowResized(object sender, EventArgs e)
{
AddNewOrnaments();
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = this.CreateGraphics();
Pen bluePen = new Pen(Color.Blue, 3);
Pen redPen = new Pen(Color.Red, 3);
Pen greenPen = new Pen(Color.Green, 3);
Pen pinkPen = new Pen(Color.HotPink, 3);
Pen turquoisePen = new Pen(Color.Turquoise, 3);
Pen purplePen = new Pen(Color.Purple, 3);
Pen goldPen = new Pen(Color.Gold, 3);
g.DrawLine(bluePen, 0, startY, this.ClientSize.Width, startY);
for (int i = 0; i < ornaments.Count; i++)
{
int startX = ornaments[i].X;
g.DrawLine(bluePen, startX, startY, startX, startY + 30);
switch (ornaments[i].Type)
{
case 1:
g.DrawRectangle(pinkPen, startX - 20, startY + 30, 40, 40);
g.DrawEllipse(turquoisePen, startX - 20, startY + 30, 40, 40);
break;
case 2:
Point[] diamondPoints = new Point[4]
{
new Point(startX, startY + 30),
new Point(startX - 20, startY + 50),
new Point(startX, startY + 70),
new Point(startX + 20, startY + 50)
};
g.DrawPolygon(redPen, diamondPoints);
g.DrawEllipse(greenPen, startX - 20, startY + 30, 40, 40);
break;
case 3:
Point[] trianglePoints = new Point[3]
{
new Point(startX, startY + 30),
new Point(startX - 20, startY + 50),
new Point(startX + 20, startY + 50)
};
g.DrawPolygon(purplePen, trianglePoints);
break;
case 4:
g.DrawRectangle(goldPen, startX - 20, startY + 30, 40, 40);
Point[] invertedTrianglePoints = new Point[3]
{
new Point(startX, startY + 30),
new Point(startX - 20, startY + 70),
new Point(startX + 20, startY + 70)
};
g.DrawPolygon(redPen, invertedTrianglePoints);
break;
}
}
}
private void InitializeOrnaments()
{
Random random = new Random();
for (int startX = spacing; startX < this.ClientSize.Width; startX += spacing)
{
int type = random.Next(1, 5);
ornaments.Add(new Ornament { X = startX, Type = type });
}
}
private void AddNewOrnaments()
{
Random random = new Random();
int startX = Math.Max(spacing, ornaments.Count * spacing);
for (int x = startX; x < this.ClientSize.Width; x += spacing)
{
int type = random.Next(1, 5);
ornaments.Add(new Ornament { X = x, Type = type });
}
}
}
}