Merge branch 'Commit'
This commit is contained in:
commit
b395030cc7
@ -4,7 +4,7 @@
|
||||
public class Text
|
||||
{
|
||||
public static double DefaultFontSize = 20;//Default Font Size
|
||||
|
||||
public static bool CenterText = true;
|
||||
public static void Make(string text, int pointX, int pointY, double size, Cairo.Color color)
|
||||
{
|
||||
Set.CheckContext();
|
||||
@ -12,7 +12,10 @@
|
||||
context.SetSourceColor(color);
|
||||
context.SetFontSize(size);
|
||||
Cairo.TextExtents extents = context.TextExtents(text);
|
||||
if(CenterText)
|
||||
context.MoveTo(pointX - extents.Width / 2, pointY + extents.Height / 2);
|
||||
else
|
||||
context.MoveTo(pointX, pointY);
|
||||
context.ShowText(text);
|
||||
}
|
||||
public static void Make(string text, int pointX, int pointY, Cairo.Color color)
|
||||
@ -22,7 +25,10 @@
|
||||
context.SetSourceColor(color);
|
||||
context.SetFontSize(DefaultFontSize);
|
||||
Cairo.TextExtents extents = context.TextExtents(text);
|
||||
if (CenterText)
|
||||
context.MoveTo(pointX - extents.Width / 2, pointY + extents.Height / 2);
|
||||
else
|
||||
context.MoveTo(pointX, pointY);
|
||||
context.ShowText(text);
|
||||
}
|
||||
public static void Make(string text, int pointX, int pointY, double size)
|
||||
@ -32,7 +38,10 @@
|
||||
context.SetSourceColor(Set.Color);
|
||||
context.SetFontSize(size);
|
||||
Cairo.TextExtents extents = context.TextExtents(text);
|
||||
if (CenterText)
|
||||
context.MoveTo(pointX - extents.Width / 2, pointY + extents.Height / 2);
|
||||
else
|
||||
context.MoveTo(pointX, pointY);
|
||||
context.ShowText(text);
|
||||
}
|
||||
public static void Make(string text, int pointX, int pointY)
|
||||
@ -42,7 +51,10 @@
|
||||
context.SetSourceColor(Set.Color);
|
||||
context.SetFontSize(DefaultFontSize);
|
||||
Cairo.TextExtents extents = context.TextExtents(text);
|
||||
if (CenterText)
|
||||
context.MoveTo(pointX - extents.Width / 2, pointY + extents.Height / 2);
|
||||
else
|
||||
context.MoveTo(pointX, pointY);
|
||||
context.ShowText(text);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
using Gtk;
|
||||
using CairoObjective;
|
||||
using GLib;
|
||||
using FractalTreeGtk.Draw;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FractalTreeGtk
|
||||
{
|
||||
@ -9,40 +12,59 @@ namespace FractalTreeGtk
|
||||
{
|
||||
static int fractallevels = 2;
|
||||
DrawingArea drawing = new DrawingArea();
|
||||
Fractal fractal = new Fractal(fractallevels);
|
||||
Fractal fractal;
|
||||
public CairoWindow(string title) : base(title) {
|
||||
Fullscreen();
|
||||
drawing.Drawn += Drawing_Drawn;
|
||||
Add(drawing);
|
||||
ShowAll();
|
||||
KeyPressEvent += CairoWindow_KeyPressEvent;
|
||||
CreateNewFractal();
|
||||
}
|
||||
public void CreateNewFractal()
|
||||
{
|
||||
fractal = new Fractal(fractallevels, this);
|
||||
}
|
||||
|
||||
private void CairoWindow_KeyPressEvent(object o, KeyPressEventArgs args)
|
||||
{
|
||||
if(args.Event.Key == Gdk.Key.equal)
|
||||
{
|
||||
fractal = new Fractal(++fractallevels);
|
||||
QueueDraw();
|
||||
++fractallevels;
|
||||
CreateNewFractal();
|
||||
}
|
||||
if (args.Event.Key == Gdk.Key.minus && fractallevels > 1)
|
||||
{
|
||||
fractal = new Fractal(--fractallevels);
|
||||
QueueDraw();
|
||||
--fractallevels;
|
||||
CreateNewFractal();
|
||||
}
|
||||
}
|
||||
|
||||
private void Drawing_Drawn(object o, DrawnArgs args)
|
||||
{
|
||||
long branches = 0;
|
||||
Text.CenterText = false;
|
||||
args.Cr.Translate(AllocatedWidth / 2, AllocatedHeight);
|
||||
Set.Context = args.Cr;
|
||||
Set.Background(new Cairo.Color(0, 0, 0));
|
||||
foreach(CairoObjective.DrawObjects.Line[] lines in (CairoObjective.DrawObjects.Line[][])fractal.Fractallines)
|
||||
foreach (CairoObjective.DrawObjects.Line[] lines in (CairoObjective.DrawObjects.Line[][])fractal.Fractallines)
|
||||
{
|
||||
foreach(CairoObjective.DrawObjects.Line line in lines)
|
||||
try
|
||||
{
|
||||
foreach (CairoObjective.DrawObjects.Line line in lines) {
|
||||
branches++;
|
||||
Line.Make(line);
|
||||
}
|
||||
Text.Make($"Levels: {fractallevels}", -(AllocatedWidth / 2) + 50, -20, new Cairo.Color(1,1,1));
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Trace.WriteLine("Hello Null");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Text.Make($"Total Branches: {branches}", -(AllocatedWidth / 2) + 1, -29, 21, new Cairo.Color(0, 0, 0));
|
||||
Text.Make($"Levels: {fractallevels}", -(AllocatedWidth / 2) + 1, -4, 21, new Cairo.Color(0, 0, 0));
|
||||
Text.Make($"Total Branches: {branches}", -(AllocatedWidth / 2), -30, new Cairo.Color(0.1, 1, 0.1));
|
||||
Text.Make($"Levels: {fractallevels}", -(AllocatedWidth / 2), -5, new Cairo.Color(0.1,1,0.1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,11 @@ namespace FractalTreeGtk.Draw
|
||||
internal class Branch : CairoObjective.DrawObjects.Line
|
||||
{
|
||||
public bool left;
|
||||
public Branch(double x1, double y1, double x2, double y2, bool left) : base(x1, y1, x2, y2)
|
||||
public double degree;
|
||||
public Branch(double x1, double y1, double x2, double y2, bool left, double degree) : base(x1, y1, x2, y2)
|
||||
{
|
||||
this.left = left;
|
||||
this.degree = degree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -7,14 +7,17 @@ namespace FractalTreeGtk.Draw
|
||||
{
|
||||
internal class Fractal
|
||||
{
|
||||
double Length = 50;
|
||||
double deg = 0.3;
|
||||
public bool Drawing = true;
|
||||
CairoWindow window;
|
||||
double Length = 100;
|
||||
double MainDegree = 0.4;
|
||||
int levels;
|
||||
int level = 0;
|
||||
double deltaLength = 2;
|
||||
double deltaLength = 5;
|
||||
public Branch[][] Fractallines;
|
||||
public Fractal(int levels)
|
||||
public Fractal(int levels, CairoWindow window)
|
||||
{
|
||||
this.window = window;
|
||||
this.levels = levels;
|
||||
Fractallines = new Branch[levels + 1][];
|
||||
CreateBranch();
|
||||
@ -24,43 +27,58 @@ namespace FractalTreeGtk.Draw
|
||||
Fractallines[level] = new Branch[Convert.ToInt32(Math.Pow(2, level))];
|
||||
for (int i = 0; i < Fractallines[level].Length; i++)
|
||||
{
|
||||
Fractallines[level][i] = new Branch(0, 0, 0, -Length, true);
|
||||
Fractallines[level][i] = new Branch(0, 0, 0, -Length, true, 0);
|
||||
}
|
||||
level++;
|
||||
NextLevel();
|
||||
}
|
||||
private void NextLevel()
|
||||
{
|
||||
window.QueueDraw();
|
||||
Length -= deltaLength;
|
||||
|
||||
window.QueueDraw();
|
||||
Fractallines[level] = new Branch[Convert.ToInt32(Math.Pow(2, level))];
|
||||
int x = 0;
|
||||
for (int i = 0; i < Fractallines[level - 1].Length; i++)
|
||||
{
|
||||
Trace.WriteLine("level: " + level);
|
||||
double Degree = Fractallines[level - 1][i].degree;
|
||||
if (Fractallines[level - 1][i].left)
|
||||
{
|
||||
Trace.WriteLine("x: " + x);
|
||||
double leftdegree = MainDegree + Degree;
|
||||
double rightdegree = -MainDegree + Degree;
|
||||
Fractallines[level][x] = new Branch(
|
||||
Fractallines[level - 1][i].X2, Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(deg + deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].X2, -(Math.Cos(deg + deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].Y2
|
||||
, true);
|
||||
Fractallines[level - 1][i].X2,
|
||||
Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(leftdegree) * Length) + Fractallines[level - 1][i].X2,
|
||||
-(Math.Cos(leftdegree) * Length) + Fractallines[level - 1][i].Y2,
|
||||
true,
|
||||
leftdegree);
|
||||
Fractallines[level][++x] = new Branch(
|
||||
Fractallines[level - 1][i].X2, Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(-deg + deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].X2, -(Math.Cos(-deg + deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].Y2
|
||||
, false);
|
||||
Fractallines[level - 1][i].X2,
|
||||
Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(rightdegree) * Length) + Fractallines[level - 1][i].X2,
|
||||
-(Math.Cos(rightdegree) * Length) + Fractallines[level - 1][i].Y2,
|
||||
false,
|
||||
rightdegree);
|
||||
}
|
||||
else
|
||||
{
|
||||
Trace.WriteLine("x: " + x);
|
||||
double leftdegree = -(MainDegree - Degree);
|
||||
double rightdegree = -(-MainDegree - Degree);
|
||||
Fractallines[level][x] = new Branch(
|
||||
Fractallines[level - 1][i].X2, Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(deg - deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].X2, -(Math.Cos(deg - deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].Y2
|
||||
, true);
|
||||
Fractallines[level - 1][i].X2,
|
||||
Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(leftdegree) * Length) + Fractallines[level - 1][i].X2,
|
||||
-(Math.Cos(leftdegree) * Length) + Fractallines[level - 1][i].Y2,
|
||||
true,
|
||||
leftdegree);
|
||||
Fractallines[level][++x] = new Branch(
|
||||
Fractallines[level - 1][i].X2, Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(-deg - deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].X2, -(Math.Cos(-deg - deg * (level - Modificator(x, level))) * Length) + Fractallines[level - 1][i].Y2
|
||||
, false);
|
||||
|
||||
-(Math.Sin(rightdegree) * Length) + Fractallines[level - 1][i].X2,
|
||||
-(Math.Cos(rightdegree) * Length) + Fractallines[level - 1][i].Y2,
|
||||
false,
|
||||
rightdegree);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
@ -69,10 +87,7 @@ namespace FractalTreeGtk.Draw
|
||||
{
|
||||
NextLevel();
|
||||
}
|
||||
}
|
||||
private int Modificator(int x, int level)
|
||||
{
|
||||
return 1;
|
||||
else Drawing = false;
|
||||
}
|
||||
//private int SumOfBranches()
|
||||
//{
|
||||
|
Loading…
x
Reference in New Issue
Block a user