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