Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ChaosGame
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
idatt2003-19
ChaosGame
Commits
c70c6d4c
Commit
c70c6d4c
authored
11 months ago
by
Edvard Berdal Eek
Browse files
Options
Downloads
Patches
Plain Diff
Fix bug when making own Affine fractals and change color factor in game page
parent
d3c39191
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Fix bug when making own Affine fractals and change color factor in game page
Pipeline
#287924
passed
11 months ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/example/chaosgame/controller/ChaosGameController.java
+36
-20
36 additions, 20 deletions
...org/example/chaosgame/controller/ChaosGameController.java
src/main/java/org/example/chaosgame/view/GamePage.java
+1
-1
1 addition, 1 deletion
src/main/java/org/example/chaosgame/view/GamePage.java
with
37 additions
and
21 deletions
src/main/java/org/example/chaosgame/controller/ChaosGameController.java
+
36
−
20
View file @
c70c6d4c
...
...
@@ -73,6 +73,14 @@ public class ChaosGameController implements Observer, Subject, GameController {
if
(
steps
<
1
||
steps
>
10000000
)
{
throw
new
NumberFormatException
();
}
if
(
chaosGame
.
getDescription
().
getTransforms
().
getFirst
()
instanceof
JuliaTransform
&&
steps
>
250000
)
{
AlertUtility
.
showErrorDialog
(
"Invalid input"
,
"Please enter a lower amount of steps for Julia transformations."
);
return
;
}
if
(
chaosGame
.
getTotalSteps
()
>
Math
.
pow
(
10
,
8
))
{
AlertUtility
.
showErrorDialog
(
"Invalid input"
,
"The total number of steps is too high. Please reset the game."
);
return
;
}
chaosGame
.
setSteps
(
steps
);
chaosGame
.
addTotalSteps
(
steps
);
chaosGame
.
runSteps
();
...
...
@@ -153,14 +161,33 @@ public class ChaosGameController implements Observer, Subject, GameController {
if
(
result
.
isPresent
())
{
Object
fractalData
=
result
.
get
();
List
<
Transform2D
>
transforms
=
new
ArrayList
<>();
if
(
fractalData
instanceof
List
)
{
List
<
AffineTransform2D
>
transformations
=
(
List
<
AffineTransform2D
>)
fractalData
;
List
<
Transform2D
>
transforms
=
new
ArrayList
<>(
transformations
);
updateChaosGame
(
new
ChaosGameDescription
(
new
Vector2D
(
0
,
0
),
new
Vector2D
(
1.0
,
1.0
),
transforms
));
List
<
List
<
String
>>
userInput
=
(
List
<
List
<
String
>>)
fractalData
;
for
(
List
<
String
>
input
:
userInput
)
{
try
{
double
a
=
Double
.
parseDouble
(
input
.
get
(
0
));
double
b
=
Double
.
parseDouble
(
input
.
get
(
1
));
double
c
=
Double
.
parseDouble
(
input
.
get
(
2
));
double
d
=
Double
.
parseDouble
(
input
.
get
(
3
));
double
x
=
Double
.
parseDouble
(
input
.
get
(
4
));
double
y
=
Double
.
parseDouble
(
input
.
get
(
5
));
if
(
a
<
-
5
||
a
>
5
||
b
<
-
5
||
b
>
5
||
c
<
-
5
||
c
>
5
||
d
<
-
5
||
d
>
5
||
x
<
-
5
||
x
>
5
||
y
<
-
5
||
y
>
5
)
{
throw
new
NumberFormatException
();
}
else
{
transforms
.
add
(
new
AffineTransform2D
(
new
Matrix2x2
(
a
,
b
,
c
,
d
),
new
Vector2D
(
x
,
y
)));
}
updateChaosGame
(
new
ChaosGameDescription
(
chaosGame
.
getDescription
().
getMinCoords
(),
chaosGame
.
getDescription
().
getMaxCoords
(),
transforms
));
}
catch
(
NumberFormatException
e
)
{
AlertUtility
.
showErrorDialog
(
"Invalid input"
,
"Please enter a valid number."
);
}
}
// List<Transform2D> transforms = new ArrayList<>(transformations);
}
else
if
(
fractalData
instanceof
Pair
)
{
Pair
<
String
,
String
>
userInput
=
(
Pair
<
String
,
String
>)
fractalData
;
try
{
// Check if the input is a valid number
...
...
@@ -171,24 +198,13 @@ public class ChaosGameController implements Observer, Subject, GameController {
AlertUtility
.
showErrorDialog
(
"Invalid input"
,
"Please enter a double between -1 and 1. No letters are allowed."
);
}
else
{
updateChaosGame
(
new
ChaosGameDescription
(
new
Vector2D
(-
1.6
,
-
1
),
new
Vector2D
(
1.6
,
1.0
),
chaosGame
.
getDescription
().
getMinCoords
(
),
chaosGame
.
getDescription
().
getMaxCoords
(
),
List
.
of
(
new
JuliaTransform
(
new
Complex
(
real
,
imaginary
),
1
))));
}
}
catch
(
NumberFormatException
e
)
{
AlertUtility
.
showErrorDialog
(
"Invalid input"
,
"Please enter a valid number."
);
}
double
real
=
Double
.
parseDouble
(
userInput
.
getKey
());
double
imaginary
=
Double
.
parseDouble
(
userInput
.
getValue
());
if
(
real
<
-
1
||
real
>
1
||
imaginary
<
-
1
||
imaginary
>
1
)
{
AlertUtility
.
showErrorDialog
(
"Invalid input"
,
"Please enter a double between -1 and 1. No letters are allowed."
);
}
else
{
updateChaosGame
(
new
ChaosGameDescription
(
new
Vector2D
(-
1.6
,
-
1
),
new
Vector2D
(
1.6
,
1.0
),
List
.
of
(
new
JuliaTransform
(
new
Complex
(
real
,
imaginary
),
1
))));
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/example/chaosgame/view/GamePage.java
+
1
−
1
View file @
c70c6d4c
...
...
@@ -19,7 +19,7 @@ import java.util.Objects;
public
abstract
class
GamePage
extends
BorderPane
{
protected
final
GraphicsContext
gc
;
private
static
final
int
COLOR_FACTOR
=
6
;
private
static
final
int
COLOR_FACTOR
=
3
;
private
static
final
int
CANVAS_WIDTH
=
1250
;
private
static
final
int
CANVAS_HEIGHT
=
805
;
private
static
final
int
MAX_COLOR_VALUE
=
255
;
...
...
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