Добавьте файлы проекта.
This commit is contained in:
31
FractalTreeGtk/CairoWindow.cs
Normal file
31
FractalTreeGtk/CairoWindow.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Gtk;
|
||||
using CairoObjective;
|
||||
using GLib;
|
||||
using FractalTreeGtk.Draw;
|
||||
|
||||
namespace FractalTreeGtk
|
||||
{
|
||||
internal class CairoWindow : Window
|
||||
{
|
||||
DrawingArea drawing = new DrawingArea();
|
||||
Fractal fractal = new Fractal();
|
||||
public CairoWindow(string title) : base(title) {
|
||||
Fullscreen();
|
||||
drawing.Drawn += Drawing_Drawn;
|
||||
Add(drawing);
|
||||
ShowAll();
|
||||
}
|
||||
|
||||
private void Drawing_Drawn(object o, DrawnArgs args)
|
||||
{
|
||||
args.Cr.Translate(AllocatedWidth / 2, AllocatedHeight);
|
||||
Set.Context = args.Cr;
|
||||
Set.Background(new Cairo.Color(0, 0, 0));
|
||||
foreach(CairoObjective.DrawObjects.Line[] lines in fractal.Fractallines)
|
||||
{
|
||||
foreach(CairoObjective.DrawObjects.Line line in lines)
|
||||
Line.Make(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
FractalTreeGtk/Draw/Fractal.cs
Normal file
87
FractalTreeGtk/Draw/Fractal.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using CairoObjective.DrawObjects;
|
||||
using System;
|
||||
namespace FractalTreeGtk.Draw
|
||||
{
|
||||
internal class Fractal
|
||||
{
|
||||
double Length = 50;
|
||||
double deg = 0.2;
|
||||
int levels = 14;
|
||||
int level = 0;
|
||||
double deltaLength = 2;
|
||||
double deltaDeg = 0;
|
||||
public Line[][] Fractallines;
|
||||
public Fractal()
|
||||
{
|
||||
Fractallines = new Line[levels + 1][];
|
||||
CreateBranch();
|
||||
}
|
||||
private void CreateBranch()
|
||||
{
|
||||
Fractallines[level] = new Line[Convert.ToInt32(Math.Pow(2, level))];
|
||||
for (int i = 0; i < Fractallines[level].Length; i++)
|
||||
{
|
||||
Fractallines[level][i] = new Line(0, 0, 0, -Length);
|
||||
}
|
||||
level++;
|
||||
NextLevel();
|
||||
}
|
||||
private void NextLevel()
|
||||
{
|
||||
Length -= deltaLength;
|
||||
//deg += Math.Sin(deg) + deltadeg;
|
||||
Fractallines[level] = new Line[Convert.ToInt32(Math.Pow(2, level))];
|
||||
int x = 0;
|
||||
for (int i = 0; i < Fractallines[level - 1].Length; i++)
|
||||
{
|
||||
Fractallines[level][x] = new Line(
|
||||
Fractallines[level - 1][i].X2, Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(deg) * Length) + Fractallines[level - 1][i].X2, -(Math.Cos(deg) * Length) + Fractallines[level - 1][i].Y2
|
||||
);
|
||||
Fractallines[level][++x] = new Line(
|
||||
Fractallines[level - 1][i].X2, Fractallines[level - 1][i].Y2,
|
||||
-(Math.Sin(-deg) * Length) + Fractallines[level - 1][i].X2, -(Math.Cos(-deg) * Length) + Fractallines[level - 1][i].Y2
|
||||
);
|
||||
x++;
|
||||
}
|
||||
deltaDeg += deg + 0.1;
|
||||
level++;
|
||||
if(level <= levels)
|
||||
{
|
||||
NextLevel();
|
||||
}
|
||||
}
|
||||
//private int SumOfBranches()
|
||||
//{
|
||||
// double sum = 0;
|
||||
// for (int i = 0; i <= levels; i++)
|
||||
// {
|
||||
// sum += Math.Pow(2, i);
|
||||
// }
|
||||
// return (int)sum;
|
||||
//}
|
||||
|
||||
//private void Branch()
|
||||
//{
|
||||
// for(int i = 0; i < Convert.ToInt32(Math.Pow(2, level)); i+=2)
|
||||
// {
|
||||
// int z = i;
|
||||
// if(i == 0)
|
||||
// {
|
||||
// z = 1;
|
||||
// }
|
||||
// Lines[iter + i] = new Line(
|
||||
// Lines[iter - z].X2, Lines[iter - z].Y2,
|
||||
// -(Math.Sin(deg) * Length) + Lines[iter - z].X2, -(Math.Cos(deg) * Length) + Lines[iter - z].Y2
|
||||
// );
|
||||
// Lines[iter + i + 1] = new Line(
|
||||
// Lines[iter - z].X2, Lines[iter - z].Y2,
|
||||
// -(Math.Sin(-deg) * Length) + Lines[iter - z].X2, -(Math.Cos(-deg) * Length) + Lines[iter - z].Y2
|
||||
// );
|
||||
// deg += 0.05;
|
||||
// }
|
||||
// iter += Convert.ToInt32(Math.Pow(2, level));
|
||||
// level++;
|
||||
//}
|
||||
}
|
||||
}
|
||||
19
FractalTreeGtk/FractalTreeGtk.csproj
Normal file
19
FractalTreeGtk/FractalTreeGtk.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CairoSharp" Version="3.24.24.38" />
|
||||
<PackageReference Include="GtkSharp" Version="3.24.24.38" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CairoObjective\CairoObjective.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
FractalTreeGtk/Program.cs
Normal file
18
FractalTreeGtk/Program.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Gtk;
|
||||
|
||||
namespace FractalTreeGtk
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Application.Init();
|
||||
|
||||
//Create the Window
|
||||
|
||||
Window myWin = new CairoWindow("My first GTK# Application! ");
|
||||
|
||||
Application.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user