Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- namespace IMJunior
- {
- class Program
- {
- static Bitmap Canvas = new Bitmap(100, 100);
- static Graphics Drawer;
- static void Main(string[] args)
- {
- Drawer = Graphics.FromImage(Canvas);
- Drawer.FillRectangle(Brushes.White, new Rectangle(0, 0, 100, 100));
- PyramidCreator creator = new PyramidCreator();
- IDrawMesh[] meshes = creator.CreatePyramid(4, 98, 100, Color.Blue);
- for (int i = 0; i < meshes.Length; i++)
- {
- meshes[i].Draw(Drawer);
- }
- Canvas.Save("canvas.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- }
- public interface IDrawLine
- {
- void Draw(Point startPoint, Point endPoint, Graphics drawer);
- }
- public interface IDrawMesh
- {
- void Draw(Graphics drawer);
- }
- public class Point
- {
- public int coordX;
- public int coordY;
- public Color color;
- public Point(int coordX, int coordY, Color color)
- {
- this.coordX = coordX;
- this.coordY = coordY;
- this.color = color;
- }
- }
- public class Line : IDrawLine
- {
- public void Draw(Point startPoint, Point endPoint, Graphics drawer)
- {
- Pen pen = new Pen(startPoint.color, 2);
- drawer.DrawLine(pen, startPoint.coordX, startPoint.coordY, endPoint.coordX, endPoint.coordY);
- }
- }
- public class Triangle : IDrawMesh
- {
- Point[] points = new Point[3];
- public Triangle(Point[] points)
- {
- this.points = points;
- }
- public void Draw(Graphics drawer)
- {
- throw new NotImplementedException();
- }
- }
- public class Circle : IDrawMesh
- {
- Point center;
- int radius;
- Color color;
- public Circle(Point center, int radius, Color color)
- {
- this.center = center;
- this.radius = radius;
- this.color = color;
- }
- public void Draw(Graphics drawer)
- {
- throw new NotImplementedException();
- }
- }
- public class Square : IDrawMesh
- {
- Point[] points = new Point[4];
- public Square(Point pointFirst, Point pointSecond, Point pointThird, Point pointFourth)
- {
- points[0] = pointFirst;
- points[1] = pointSecond;
- points[2] = pointThird;
- points[3] = pointFourth;
- }
- public void Draw(Graphics drawer)
- {
- Line line = new Line();
- for (int i = 0; i < points.Length - 1; i++)
- {
- line.Draw(points[i], points[i + 1], drawer);
- }
- line.Draw(points[points.Length - 1], points[0], drawer);
- }
- }
- public class PyramidCreator
- {
- public IDrawMesh[] CreatePyramid(int cubsCount, int height, int canvWidth, Color color)
- {
- int posY = 0;
- int cubHeight = height / cubsCount;
- int summ = (cubsCount*(cubsCount + 1)) / 2;
- int canvCenter = canvWidth / 2;
- IDrawMesh[] meshes = new Square[cubsCount];
- for (int i = 1; i <= cubsCount; i++)
- {
- int cubWidth = (height / summ) * i;
- meshes[i - 1] = new Square
- (
- new Point((canvCenter - (cubWidth/2)), posY, color),
- new Point((canvCenter + (cubWidth / 2)), posY, color),
- new Point((canvCenter - (cubWidth / 2)), (posY+ cubWidth), color),
- new Point((canvCenter + (cubWidth / 2)), (posY + cubWidth), color)
- );
- posY += cubWidth * i;
- }
- return meshes;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement