diff --git a/src/main/java/edu/ntnu/idatt2003/model/ChaosGameDescriptionFactory.java b/src/main/java/edu/ntnu/idatt2003/model/ChaosGameDescriptionFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..d8c5a6f8fefc9c3583b51808c1ec34f43f82896b --- /dev/null +++ b/src/main/java/edu/ntnu/idatt2003/model/ChaosGameDescriptionFactory.java @@ -0,0 +1,56 @@ +package edu.ntnu.idatt2003.model; + +import java.util.Arrays; + +/** + * This class is a factory for creating different standard fractals as ChaosGameDescriptions. + */ +public class ChaosGameDescriptionFactory { + /** + * Creates a ChaosGameDescription for the Sierpinski triangle. + * @return a ChaosGameDescription for the Sierpinski triangle + */ + public static ChaosGameDescription createSierpinskiTriangle() { + AffineTransform2D[] transforms = new AffineTransform2D[3]; + transforms[0] = new AffineTransform2D(new Matrix2x2(0.5, 0.0, 0.0, 0.5), new Vector2D(0.0, 0.0)); + transforms[1] = new AffineTransform2D(new Matrix2x2(0.5, 0.0, 0.0, 0.5), new Vector2D(0.5, 0.0)); + transforms[2] = new AffineTransform2D(new Matrix2x2(0.5, 0.0, 0.0, 0.5), new Vector2D(0.25, 0.5)); + + Vector2D lowerLeft = new Vector2D(0.0, 0.0); + Vector2D lowerRight = new Vector2D(1.0, 1.0); + + return new ChaosGameDescription(Arrays.asList(transforms), lowerLeft, lowerRight); + } + + /** + * Creates a ChaosGameDescription for the Barnsley fern. + * @return a ChaosGameDescription for the Barnsley fern + */ + public static ChaosGameDescription createBarnsleyFern() { + AffineTransform2D[] transforms = new AffineTransform2D[4]; + transforms[0] = new AffineTransform2D(new Matrix2x2(0.0, 0.0, 0.0, 0.16), new Vector2D(0.0, 0.0)); + transforms[1] = new AffineTransform2D(new Matrix2x2(0.85, 0.04, -0.04, 0.85), new Vector2D(0.0, 1.6)); + transforms[2] = new AffineTransform2D(new Matrix2x2(0.2, -0.26, 0.23, 0.22), new Vector2D(0.0, 1.6)); + transforms[3] = new AffineTransform2D(new Matrix2x2(-0.15, 0.28, 0.26, 0.24), new Vector2D(0.0, 0.44)); + + Vector2D lowerLeft = new Vector2D(-2.1820, 0.0); + Vector2D upperRight = new Vector2D(2.6558, 9.9983); + + return new ChaosGameDescription(Arrays.asList(transforms), lowerLeft, upperRight); + } + + /** + * Creates a ChaosGameDescription for the Julia set with the given complex number. + * @param c the complex number + * @param sign the sign of the imaginary part of the complex number + * @return a ChaosGameDescription for the Julia set + */ + public static ChaosGameDescription createJuliaSet(Complex c, int sign) { + JuliaTransform[] transforms = new JuliaTransform[1]; + transforms[0] = new JuliaTransform(c, sign); + Vector2D lowerLeft = new Vector2D(-2.0, -2.0); + Vector2D upperRight = new Vector2D(2.0, 2.0); + + return new ChaosGameDescription(Arrays.asList(transforms), lowerLeft, upperRight); + } +} diff --git a/src/main/resources/Affine2d.txt b/src/main/resources/Affine2d.txt new file mode 100644 index 0000000000000000000000000000000000000000..8219677e73239dac2cc0f0ce9eedc637144966f5 --- /dev/null +++ b/src/main/resources/Affine2d.txt @@ -0,0 +1,6 @@ +Affine2D # Type of transform +0, 0 # Lower left +1, 1 # Upper right +.5, 0, 0, .5, 0, 0 # 1st transform +.5, 0, 0, .5, .25, .5 # 2nd transform +.5, 0, 0, .5, .5, 0 # 3rd transform