Final
This commit is contained in:
parent
17db4dc996
commit
4c25bc17af
@ -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,26 +12,30 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +47,24 @@ namespace FractalTreeGtk
|
|||||||
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)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
foreach (CairoObjective.DrawObjects.Line line in lines) {
|
foreach (CairoObjective.DrawObjects.Line line in lines) {
|
||||||
branches++;
|
branches++;
|
||||||
Line.Make(line);
|
Line.Make(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text.Make($"Total Branches: {branches}", -(AllocatedWidth / 2), -30, new Cairo.Color(1, 1, 1));
|
catch (NullReferenceException)
|
||||||
Text.Make($"Levels: {fractallevels}", -(AllocatedWidth / 2), -5, new Cairo.Color(1,1,1));
|
{
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,17 @@ namespace FractalTreeGtk.Draw
|
|||||||
{
|
{
|
||||||
internal class Fractal
|
internal class Fractal
|
||||||
{
|
{
|
||||||
|
public bool Drawing = true;
|
||||||
|
CairoWindow window;
|
||||||
double Length = 100;
|
double Length = 100;
|
||||||
double MainDegree = 0.4;
|
double MainDegree = 0.4;
|
||||||
int levels;
|
int levels;
|
||||||
int level = 0;
|
int level = 0;
|
||||||
double deltaLength = 5;
|
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();
|
||||||
@ -31,7 +34,9 @@ namespace FractalTreeGtk.Draw
|
|||||||
}
|
}
|
||||||
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++)
|
||||||
@ -82,6 +87,7 @@ namespace FractalTreeGtk.Draw
|
|||||||
{
|
{
|
||||||
NextLevel();
|
NextLevel();
|
||||||
}
|
}
|
||||||
|
else Drawing = false;
|
||||||
}
|
}
|
||||||
//private int SumOfBranches()
|
//private int SumOfBranches()
|
||||||
//{
|
//{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user