Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IDATT2003 Mappevurdering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Håvard Johannes Versto Daleng
IDATT2003 Mappevurdering
Commits
5a1a3311
Commit
5a1a3311
authored
1 year ago
by
Håvard Daleng
Browse files
Options
Downloads
Patches
Plain Diff
Created basic ChaosGame-class
parent
42235b57
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/edu/ntnu/stud/chaosgame/Main.java
+10
-3
10 additions, 3 deletions
src/main/java/edu/ntnu/stud/chaosgame/Main.java
src/main/java/edu/ntnu/stud/chaosgame/model/handling/ChaosGame.java
+29
-1
29 additions, 1 deletion
...ava/edu/ntnu/stud/chaosgame/model/handling/ChaosGame.java
with
39 additions
and
4 deletions
src/main/java/edu/ntnu/stud/chaosgame/Main.java
+
10
−
3
View file @
5a1a3311
...
@@ -4,6 +4,8 @@ import edu.ntnu.stud.chaosgame.game.ChaosGameDescription;
...
@@ -4,6 +4,8 @@ import edu.ntnu.stud.chaosgame.game.ChaosGameDescription;
import
edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler
;
import
edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler
;
import
edu.ntnu.stud.chaosgame.model.Matrix2x2
;
import
edu.ntnu.stud.chaosgame.model.Matrix2x2
;
import
edu.ntnu.stud.chaosgame.model.Vector2D
;
import
edu.ntnu.stud.chaosgame.model.Vector2D
;
import
edu.ntnu.stud.chaosgame.model.handling.ChaosCanvas
;
import
edu.ntnu.stud.chaosgame.model.handling.ChaosGame
;
import
edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D
;
import
edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D
;
import
edu.ntnu.stud.chaosgame.model.transformations.Transform2D
;
import
edu.ntnu.stud.chaosgame.model.transformations.Transform2D
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -27,15 +29,20 @@ public class Main {
...
@@ -27,15 +29,20 @@ public class Main {
List
<
Transform2D
>
transforms
=
new
ArrayList
<>();
List
<
Transform2D
>
transforms
=
new
ArrayList
<>();
transforms
.
add
(
affineTransform
);
transforms
.
add
(
affineTransform
);
ChaosGameDescription
description
=
null
;
// Declare description
ChaosGame
game
=
null
;
try
{
try
{
//ChaosGameDescription description = new ChaosGameFileHandler().readFromFile(path);
//ChaosGameDescription description = new ChaosGameFileHandler().readFromFile(path);
ChaosGameDescription
description
=
new
ChaosGameDescription
(
minCoords
,
maxCoords
,
transforms
);
description
=
new
ChaosGameDescription
(
minCoords
,
maxCoords
,
transforms
);
System
.
out
.
println
(
"MaxCoords-object of description: "
+
description
.
getMaxCoords
());
System
.
out
.
println
(
"MaxCoords-object of description: "
+
description
.
getMaxCoords
());
ChaosCanvas
canvas
=
new
ChaosCanvas
(
100
,
100
,
minCoords
,
maxCoords
);
// Create canvas
game
=
new
ChaosGame
(
description
,
canvas
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
// TODO: Alter error handling
System
.
out
.
println
(
e
.
getMessage
());
// TODO: Alter error handling
}
}
game
.
runSteps
(
100
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/edu/ntnu/stud/chaosgame/model/handling/ChaosGame.java
+
29
−
1
View file @
5a1a3311
...
@@ -32,11 +32,39 @@ public class ChaosGame {
...
@@ -32,11 +32,39 @@ public class ChaosGame {
/**
/**
* The random number generator for the chaos game.
* The random number generator for the chaos game.
*/
*/
public
Random
random
;
private
Random
random
;
/**
* Number of transforms
*/
private
int
numOfTransforms
;
public
ChaosGame
(
ChaosGameDescription
description
,
ChaosCanvas
canvas
)
{
public
ChaosGame
(
ChaosGameDescription
description
,
ChaosCanvas
canvas
)
{
this
.
canvas
=
canvas
;
this
.
canvas
=
canvas
;
this
.
description
=
description
;
this
.
description
=
description
;
this
.
random
=
new
Random
();
this
.
numOfTransforms
=
description
.
getTransforms
().
size
();
this
.
currentPoint
=
new
Vector2D
(
0
,
0
);
}
/**
* Get the canvas of this chaos game.
* @return the canvas.
*/
public
ChaosCanvas
getCanvas
()
{
return
this
.
canvas
;
}
/**
* Run the chaos game for n iterations.
*
* @param n the number of iterations
*/
public
void
runSteps
(
int
n
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
int
j
=
this
.
random
.
nextInt
(
0
,
this
.
numOfTransforms
);
j
=
0
;
this
.
currentPoint
=
this
.
description
.
getTransforms
().
get
(
j
).
transform
(
currentPoint
);
this
.
canvas
.
putPixel
(
currentPoint
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment