Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mappevurderingprog2
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
Tam Minh Le
mappevurderingprog2
Commits
b7ebfb24
Commit
b7ebfb24
authored
1 year ago
by
Tam Le
Browse files
Options
Downloads
Patches
Plain Diff
Docs: Added javadoc to ChaosCanvas class
parent
f4fc190d
No related branches found
No related tags found
3 merge requests
!54
Final release
,
!17
Part 2
,
!8
Docs: Added javadoc to ChaosCanvas class
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/models/chaos/ChaosCanvas.java
+45
-0
45 additions, 0 deletions
...att2003/mappevurderingprog2/models/chaos/ChaosCanvas.java
with
45 additions
and
0 deletions
src/main/java/edu/ntnu/idatt2003/mappevurderingprog2/models/chaos/ChaosCanvas.java
+
45
−
0
View file @
b7ebfb24
...
...
@@ -3,14 +3,38 @@ package edu.ntnu.idatt2003.mappevurderingprog2.models.chaos;
import
edu.ntnu.idatt2003.mappevurderingprog2.models.AffineTransform2D
;
import
edu.ntnu.idatt2003.mappevurderingprog2.models.Vector2D
;
/**
* The ChaosCanvas class represent a 2D canvas with the ability to store and retrieve pixels.
* The class can apply transformations to obtain pixel values from a given point.
*/
public
class
ChaosCanvas
{
//The canvas is represented as a 2D array of integers, where each integer represents a color.
private
int
[][]
canvas
;
// The width of the canvas
private
int
width
;
// The height of the canvas
private
int
height
;
// The minimum coordinates of the canvas
private
Vector2D
minCoords
;
// The maximum coordinates of the canvas
private
Vector2D
maxCoords
;
// The transformation from coordinates to indices
private
AffineTransform2D
transformCoordsToIndices
;
/**
* Constructs a ChaosCanvas object with the given width, height, minimum coordinates, and maximum coordinates.
* @param width the width of the canvas
* @param height the height of the canvas
* @param minCoords the minimum coordinates of the canvas
* @param maxCoords the maximum coordinates of the canvas
*/
public
ChaosCanvas
(
int
width
,
int
height
,
Vector2D
minCoords
,
Vector2D
maxCoords
)
{
this
.
width
=
width
;
this
.
height
=
height
;
...
...
@@ -19,6 +43,12 @@ public class ChaosCanvas{
this
.
canvas
=
new
int
[
width
][
height
];
}
/**
* Gets the color of the pixel at the given point.
* @param transformCoordsToIndices the transformation from coordinates to indices
* @return the color of the pixel at the given point
*/
public
int
getPixel
(
Vector2D
point
){
Vector2D
indices
=
transformCoordsToIndices
.
transform
(
point
);
int
x
=
(
int
)
indices
.
getX0
();
...
...
@@ -26,6 +56,13 @@ public class ChaosCanvas{
return
canvas
[
x
][
y
];
}
/**
* Sets the color of the pixel at the given point.
* @param point the point to set the color of
* @param color the color to set
* @return the color of the pixel after setting
*/
public
int
usePixel
(
Vector2D
point
,
int
color
){
Vector2D
indices
=
transformCoordsToIndices
.
transform
(
point
);
int
x
=
(
int
)
indices
.
getX0
();
...
...
@@ -34,10 +71,18 @@ public class ChaosCanvas{
return
canvas
[
x
][
y
];
}
/**
* Gets the canvas.
* @return the canvas
*/
public
int
[][]
getCanvas
(){
return
canvas
;
}
/**
* Clears the canvas.
*/
public
void
clear
(){
for
(
int
i
=
0
;
i
<
canvas
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
canvas
[
i
].
length
;
j
++){
...
...
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