-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
roger.alsing
committed
Dec 11, 2008
1 parent
704ca8b
commit a5c7311
Showing
42 changed files
with
5,267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using GenArt.Classes; | ||
|
||
namespace GenArt.AST | ||
{ | ||
public class DnaBrush | ||
{ | ||
public int Red { get; set; } | ||
public int Green { get; set; } | ||
public int Blue { get; set; } | ||
public int Alpha { get; set; } | ||
|
||
public void Init() | ||
{ | ||
Red = Tools.GetRandomNumber(0, 255); | ||
Green = Tools.GetRandomNumber(0, 255); | ||
Blue = Tools.GetRandomNumber(0, 255); | ||
Alpha = Tools.GetRandomNumber(10, 60); | ||
} | ||
|
||
public DnaBrush Clone() | ||
{ | ||
return new DnaBrush | ||
{ | ||
Alpha = Alpha, | ||
Blue = Blue, | ||
Green = Green, | ||
Red = Red, | ||
}; | ||
} | ||
|
||
public void Mutate(DnaDrawing drawing) | ||
{ | ||
if (Tools.WillMutate(Settings.ActiveRedMutationRate)) | ||
{ | ||
Red = Tools.GetRandomNumber(Settings.ActiveRedRangeMin, Settings.ActiveRedRangeMax); | ||
drawing.SetDirty(); | ||
} | ||
|
||
if (Tools.WillMutate(Settings.ActiveGreenMutationRate)) | ||
{ | ||
Green = Tools.GetRandomNumber(Settings.ActiveGreenRangeMin, Settings.ActiveGreenRangeMax); | ||
drawing.SetDirty(); | ||
} | ||
|
||
if (Tools.WillMutate(Settings.ActiveBlueMutationRate)) | ||
{ | ||
Blue = Tools.GetRandomNumber(Settings.ActiveBlueRangeMin, Settings.ActiveBlueRangeMax); | ||
drawing.SetDirty(); | ||
} | ||
|
||
if (Tools.WillMutate(Settings.ActiveAlphaMutationRate)) | ||
{ | ||
Alpha = Tools.GetRandomNumber(Settings.ActiveAlphaRangeMin, Settings.ActiveAlphaRangeMax); | ||
drawing.SetDirty(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.Collections.Generic; | ||
using System.Xml.Serialization; | ||
using GenArt.Classes; | ||
|
||
namespace GenArt.AST | ||
{ | ||
public class DnaDrawing | ||
{ | ||
public List<DnaPolygon> Polygons { get; set; } | ||
|
||
[XmlIgnore] | ||
public bool IsDirty { get; private set; } | ||
|
||
public int PointCount | ||
{ | ||
get | ||
{ | ||
int pointCount = 0; | ||
foreach (DnaPolygon polygon in Polygons) | ||
pointCount += polygon.Points.Count; | ||
|
||
return pointCount; | ||
} | ||
} | ||
|
||
public void SetDirty() | ||
{ | ||
IsDirty = true; | ||
} | ||
|
||
public void Init() | ||
{ | ||
Polygons = new List<DnaPolygon>(); | ||
|
||
for (int i = 0; i < Settings.ActivePolygonsMin; i++) | ||
AddPolygon(); | ||
|
||
SetDirty(); | ||
} | ||
|
||
public DnaDrawing Clone() | ||
{ | ||
var drawing = new DnaDrawing(); | ||
drawing.Polygons = new List<DnaPolygon>(); | ||
foreach (DnaPolygon polygon in Polygons) | ||
drawing.Polygons.Add(polygon.Clone()); | ||
|
||
return drawing; | ||
} | ||
|
||
|
||
public void Mutate() | ||
{ | ||
if (Tools.WillMutate(Settings.ActiveAddPolygonMutationRate)) | ||
AddPolygon(); | ||
|
||
if (Tools.WillMutate(Settings.ActiveRemovePolygonMutationRate)) | ||
RemovePolygon(); | ||
|
||
if (Tools.WillMutate(Settings.ActiveMovePolygonMutationRate)) | ||
MovePolygon(); | ||
|
||
foreach (DnaPolygon polygon in Polygons) | ||
polygon.Mutate(this); | ||
} | ||
|
||
public void MovePolygon() | ||
{ | ||
if (Polygons.Count < 1) | ||
return; | ||
|
||
int index = Tools.GetRandomNumber(0, Polygons.Count); | ||
DnaPolygon poly = Polygons[index]; | ||
Polygons.RemoveAt(index); | ||
index = Tools.GetRandomNumber(0, Polygons.Count); | ||
Polygons.Insert(index, poly); | ||
SetDirty(); | ||
} | ||
|
||
public void RemovePolygon() | ||
{ | ||
if (Polygons.Count > Settings.ActivePolygonsMin) | ||
{ | ||
int index = Tools.GetRandomNumber(0, Polygons.Count); | ||
Polygons.RemoveAt(index); | ||
SetDirty(); | ||
} | ||
} | ||
|
||
public void AddPolygon() | ||
{ | ||
if (Polygons.Count < Settings.ActivePolygonsMax) | ||
{ | ||
var newPolygon = new DnaPolygon(); | ||
newPolygon.Init(); | ||
|
||
int index = Tools.GetRandomNumber(0, Polygons.Count); | ||
|
||
Polygons.Insert(index, newPolygon); | ||
SetDirty(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using GenArt.Classes; | ||
|
||
namespace GenArt.AST | ||
{ | ||
public class DnaPoint | ||
{ | ||
public int X { get; set; } | ||
public int Y { get; set; } | ||
|
||
public void Init() | ||
{ | ||
X = Tools.GetRandomNumber(0, Tools.MaxWidth); | ||
Y = Tools.GetRandomNumber(0, Tools.MaxHeight); | ||
} | ||
|
||
public DnaPoint Clone() | ||
{ | ||
return new DnaPoint | ||
{ | ||
X = X, | ||
Y = Y, | ||
}; | ||
} | ||
|
||
public void Mutate(DnaDrawing drawing) | ||
{ | ||
if (Tools.WillMutate(Settings.ActiveMovePointMaxMutationRate)) | ||
{ | ||
X = Tools.GetRandomNumber(0, Tools.MaxWidth); | ||
Y = Tools.GetRandomNumber(0, Tools.MaxHeight); | ||
drawing.SetDirty(); | ||
} | ||
|
||
if (Tools.WillMutate(Settings.ActiveMovePointMidMutationRate)) | ||
{ | ||
X = | ||
Math.Min( | ||
Math.Max(0, | ||
X + | ||
Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMid, | ||
Settings.ActiveMovePointRangeMid)), Tools.MaxWidth); | ||
Y = | ||
Math.Min( | ||
Math.Max(0, | ||
Y + | ||
Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMid, | ||
Settings.ActiveMovePointRangeMid)), Tools.MaxHeight); | ||
drawing.SetDirty(); | ||
} | ||
|
||
if (Tools.WillMutate(Settings.ActiveMovePointMinMutationRate)) | ||
{ | ||
X = | ||
Math.Min( | ||
Math.Max(0, | ||
X + | ||
Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMin, | ||
Settings.ActiveMovePointRangeMin)), Tools.MaxWidth); | ||
Y = | ||
Math.Min( | ||
Math.Max(0, | ||
Y + | ||
Tools.GetRandomNumber(-Settings.ActiveMovePointRangeMin, | ||
Settings.ActiveMovePointRangeMin)), Tools.MaxHeight); | ||
drawing.SetDirty(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using GenArt.Classes; | ||
|
||
namespace GenArt.AST | ||
{ | ||
public class DnaPolygon | ||
{ | ||
public List<DnaPoint> Points { get; set; } | ||
public DnaBrush Brush { get; set; } | ||
|
||
public void Init() | ||
{ | ||
Points = new List<DnaPoint>(); | ||
|
||
//int count = Tools.GetRandomNumber(3, 3); | ||
var origin = new DnaPoint(); | ||
origin.Init(); | ||
|
||
for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++) | ||
{ | ||
var point = new DnaPoint(); | ||
point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth); | ||
point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight); | ||
|
||
Points.Add(point); | ||
} | ||
|
||
Brush = new DnaBrush(); | ||
Brush.Init(); | ||
} | ||
|
||
public DnaPolygon Clone() | ||
{ | ||
var newPolygon = new DnaPolygon(); | ||
newPolygon.Points = new List<DnaPoint>(); | ||
newPolygon.Brush = Brush.Clone(); | ||
foreach (DnaPoint point in Points) | ||
newPolygon.Points.Add(point.Clone()); | ||
|
||
return newPolygon; | ||
} | ||
|
||
public void Mutate(DnaDrawing drawing) | ||
{ | ||
if (Tools.WillMutate(Settings.ActiveAddPointMutationRate)) | ||
AddPoint(drawing); | ||
|
||
if (Tools.WillMutate(Settings.ActiveRemovePointMutationRate)) | ||
RemovePoint(drawing); | ||
|
||
Brush.Mutate(drawing); | ||
Points.ForEach(p => p.Mutate(drawing)); | ||
} | ||
|
||
private void RemovePoint(DnaDrawing drawing) | ||
{ | ||
if (Points.Count > Settings.ActivePointsPerPolygonMin) | ||
{ | ||
if (drawing.PointCount > Settings.ActivePointsMin) | ||
{ | ||
int index = Tools.GetRandomNumber(0, Points.Count); | ||
Points.RemoveAt(index); | ||
|
||
drawing.SetDirty(); | ||
} | ||
} | ||
} | ||
|
||
private void AddPoint(DnaDrawing drawing) | ||
{ | ||
if (Points.Count < Settings.ActivePointsPerPolygonMax) | ||
{ | ||
if (drawing.PointCount < Settings.ActivePointsMax) | ||
{ | ||
var newPoint = new DnaPoint(); | ||
|
||
int index = Tools.GetRandomNumber(1, Points.Count - 1); | ||
|
||
DnaPoint prev = Points[index - 1]; | ||
DnaPoint next = Points[index]; | ||
|
||
newPoint.X = (prev.X + next.X)/2; | ||
newPoint.Y = (prev.Y + next.Y)/2; | ||
|
||
|
||
Points.Insert(index, newPoint); | ||
|
||
drawing.SetDirty(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using System.Text; | ||
using System.Windows.Forms; | ||
|
||
namespace GenArt.Classes | ||
{ | ||
public static class FileUtil | ||
{ | ||
public static string XmlExtension = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; | ||
public static string DnaExtension = "dna files (*.dna)|*.dna|All files (*.*)|*.*"; | ||
public static string ImgExtension = "gif files (*.gif)|*.gif|bmp files (*.bmp)|*.bmp|jpg files (*.jpg)|*.jpg|jpeg files (*.jpeg)|*.jpeg|All files (*.*)|*.*"; | ||
|
||
public static string GetSaveFileName(string filter) | ||
{ | ||
SaveFileDialog dialog = new SaveFileDialog(); | ||
dialog.Filter = filter; | ||
if (!dialog.ShowDialog().Equals(DialogResult.Cancel)) | ||
return dialog.FileName; | ||
return null; | ||
} | ||
|
||
public static string GetOpenFileName(string filter) | ||
{ | ||
OpenFileDialog dialog = new OpenFileDialog(); | ||
dialog.Filter = filter; | ||
if (!dialog.ShowDialog().Equals(DialogResult.Cancel)) | ||
return dialog.FileName; | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.