/// <summary> /// When pictureBox redraws. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pictureBox_Paint(object sender, PaintEventArgs e) { switch (pickedFractal) { case 0: koch = new KochCurve(depth, sender, e, p); koch.DrawFractal(p); break; case 1: triangle = new TriangleSerpinsky(depth, sender, e, p); triangle.DrawFractal(p); break; case 2: tree = new FractalTree(depth, sender, e, p); tree.LengthCoef = coef; tree.LeftAngle = leftAngle; tree.RightAngle = rightAngle; tree.DrawFractal(p); break; case 3: carpet = new CarpetSerpinskiy(depth, sender, e, p); carpet.DrawFractal(p); break; case 4: cantor = new CantorSet(depth, sender, e, p); cantor.SetDist(cantorDist); cantor.DrawFractal(p); break; } }
private void CreatePoints() { var pointA = new Vector2(0, -Diameter); var pointB = pointA + new Vector2(0, Diameter * 2).Rotated(Mathf.Deg2Rad(30)); var pointC = pointA + new Vector2(0, Diameter * 2).Rotated(-Mathf.Deg2Rad(30)); _curveA = new KochCurve(pointB, pointA, Generations); _curveB = new KochCurve(pointC, pointB, Generations); _curveC = new KochCurve(pointA, pointC, Generations); _curveA.GenerateAll(); _curveB.GenerateAll(); _curveC.GenerateAll(); }
/// <summary> /// Render koch curve. /// </summary> /// <param name="target"> Target of the rendering. </param> public override void Render(Graphics target) { Pen pen = new Pen(GetColor()); int dx = (int)(Length * Math.Cos(angle)); int dy = (int)(Length * Math.Sin(angle)); // Render next recursion level. if (depth < MaxDepth) { // Stop if fractal is too small. if (Length / 3 == 0) { return; } // Triangle part. int upperPointX = (int)(X + dx / 3 + Length / 3 * Math.Cos(angle + Math.PI / 3)); int upperPointY = (int)(Y + dy / 3 + Length / 3 * Math.Sin(angle + Math.PI / 3)); KochCurve kc1 = new KochCurve(depth + 1, MaxDepth, Length / 3, X + dx / 3, Y + dy / 3, angle + Math.PI / 3); KochCurve kc2 = new KochCurve(depth + 1, MaxDepth, Length / 3, upperPointX, upperPointY, angle - Math.PI / 3); kc1.Render(target); kc2.Render(target); // Lines on the left and right side. KochCurve kc3 = new KochCurve(depth + 1, MaxDepth, Length / 3, X, Y, angle); KochCurve kc4 = new KochCurve(depth + 1, MaxDepth, Length / 3, X + dx * 2 / 3, Y + dy * 2 / 3, angle); kc3.Render(target); kc4.Render(target); } else { // Draw line on the last recursion level. target.DrawLine(pen, X, Y, X + dx, Y + dy); } }
public void Drawing() { switch (fractalSelection.SelectedItem) { case "Дерево Пифагора": pythagoreanTree = new PythagoreanTree((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value, (flowLayoutPanel1.Height - 20) * trackBarZoom.Value, (int)segmentLength.Value * trackBarZoom.Value, (int)angleFirst.Value, (int)angleSecond.Value); pictureBox.Image = pythagoreanTree.Map; break; case "Кривая Коха": kochCurve = new KochCurve((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value, (flowLayoutPanel1.Height - 20) * trackBarZoom.Value); pictureBox.Image = kochCurve.Map; break; case "Ковёр Серпинского": carpet = new SierpinskiCarpet((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value, (flowLayoutPanel1.Height - 20) * trackBarZoom.Value); pictureBox.Image = carpet.Map; break; case "Треугольник Серпинского": triangle = new SierpinskiTriangle((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value, (flowLayoutPanel1.Height - 20) * trackBarZoom.Value); pictureBox.Image = triangle.Map; break; case "Множество Кантора": cantorSet = new CantorSet((int)recursionDepth.Value, (flowLayoutPanel1.Width - 20) * trackBarZoom.Value, (flowLayoutPanel1.Height - 20) * trackBarZoom.Value, (int)segmentLength.Value * trackBarZoom.Value); pictureBox.Image = cantorSet.Map; break; } }