Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Futures Demo
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
cosc250-2023
Futures Demo
Commits
07fb8243
Commit
07fb8243
authored
4 years ago
by
William Billingsley
Browse files
Options
Downloads
Patches
Plain Diff
Added labels for flock data
parent
b97a5761
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+18
-3
18 additions, 3 deletions
README.md
src/main/scala/cosc250/boids/BoidsApp.scala
+22
-1
22 additions, 1 deletion
src/main/scala/cosc250/boids/BoidsApp.scala
src/main/scala/cosc250/boids/Simulation.scala
+24
-1
24 additions, 1 deletion
src/main/scala/cosc250/boids/Simulation.scala
with
64 additions
and
5 deletions
README.md
+
18
−
3
View file @
07fb8243
...
...
@@ -100,6 +100,7 @@ Partially implemented, you have:
*
The
**Action Replay**
button must take the simulation back to the start of
the memory buffer (typically one second) and let the simulation continue
again from there.
Hint: think about which end you want to insert the frame.
*
The
**wind**
buttons should set the wind strength and direction. As the
boids' velocity is normalised on the next tick, in practice this works as a
...
...
@@ -118,6 +119,20 @@ Partially implemented, you have:
*
Clicking a point on the canvas should add a new boid into the simulation,
heading in a random direction with a velocity of 1
*
There are also three labels at the foot of the simulation, which are intended to show some
data about the flock. (These are drawn from
`Simulation.flockDir`
,
`Simulation.flockSpeed`
, and
`Simulation.flockSep`
which you'll need to implement.)
-
Flock direction: The average direction of the flock. (Sum the velocity vectors and take its theta). You should be
able to see if this is working by seeing how it changes with the wind buttons
-
Flock speed: The average speed of the flock. (Take the average of the magnitude of the velocity vectors). This should
stay more or less constant, because of how boids work
-
Flock separation: The variance of the position of the flock. This one's a little trickier. Find the centroid of the flock
(average the position vectors). Then for each boid, calculate the square of its distance from the centroid. Return the
mean of that. To test this, hit the "explosion of boids" button. It should drop to nearly zero and then grow.
## Note on the provided code
I've provided this code by writing a solution and then cutting back from it.
...
...
@@ -138,8 +153,8 @@ Functionality:
*
Startle works: 1
*
Regenesis works: 1
*
Action replay works: 1
*
Mean direction, separation, and velocity works: 3 (1 each)
Quality:
*
Boid uses functional rather than imperative code: 3
*
Overall quality judgment (readable, tidy, concise): 5
*
Overall quality judgment (functional, readable, tidy, concise): 5
This diff is collapsed.
Click to expand it.
src/main/scala/cosc250/boids/BoidsApp.scala
+
22
−
1
View file @
07fb8243
...
...
@@ -7,6 +7,9 @@ import javax.swing._
import
scala.collection.mutable
import
scala.util.Random
/**
* You shouldn't edit this file
*/
object
BoidsApp
{
/** The main window */
...
...
@@ -32,7 +35,11 @@ object BoidsApp {
val
regenesis
=
new
JButton
(
"Regenesis"
)
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
val
directionLabel
=
new
JLabel
(
"Flock direction: xx radians"
)
val
separationLabel
=
new
JLabel
(
"Flock speed: xx"
)
val
velocityLabel
=
new
JLabel
(
"Flock separation: xx"
)
@main
def
run
=
{
val
container
=
new
JPanel
()
container
.
setLayout
(
new
BorderLayout
())
...
...
@@ -79,6 +86,15 @@ object BoidsApp {
container
.
add
(
controlsContainer
,
BorderLayout
.
EAST
)
val
dataContainer
=
new
JPanel
()
dataContainer
.
setLayout
(
new
GridLayout
(
1
,
3
))
dataContainer
.
add
(
directionLabel
)
dataContainer
.
add
(
velocityLabel
)
dataContainer
.
add
(
separationLabel
)
container
.
add
(
dataContainer
,
BorderLayout
.
SOUTH
)
window
.
setDefaultCloseOperation
(
WindowConstants
.
EXIT_ON_CLOSE
)
window
.
add
(
container
)
window
.
setSize
(
container
.
getPreferredSize
)
...
...
@@ -106,6 +122,11 @@ object BoidsApp {
val
timer
=
new
Timer
(
16
,
(
e
)
=>
{
boidsPanel
.
setBoids
(
Simulation
.
update
())
SwingUtilities
.
invokeLater
(()
=>
directionLabel
.
setText
(
s
"Flock direction: ${Simulation.flockDir} radians"
)
directionLabel
.
setText
(
s
"Flock speed: ${Simulation.flockSpeed} "
)
directionLabel
.
setText
(
s
"Flock separation: ${Simulation.flockSep}"
)
)
})
timer
.
start
()
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/cosc250/boids/Simulation.scala
+
24
−
1
View file @
07fb8243
...
...
@@ -87,6 +87,29 @@ object Simulation {
}
/** The current average direction of the flock. Add up all the boids' velocity vectors, and take the theta. */
def
flockDir
:
Double
=
println
(
"Warning, you haven't implemented flockDir!"
)
0d
/** The current average speed of the flock. Take the mean of all the boids' velocity magnitudes. */
def
flockSpeed
:
Double
=
println
(
"Warning, you haven't implemented flockSpeed!"
)
0d
/**
* The variance of the flock's positions, ignoring the fact we wrap around the screen.
* To get this one:
* * Calculate the centroid of the flock (Add all the position vectors, and divide by the number of boids)
* * Calculate the square of the distance of each boid from this centroid, and sum them.
* i.e., sum Math.pow((b.position - centroid).magnitude, 2)
* * Divide this by the number of boids.
*
* We'll probably eyeball the code for this one, given we're going to find it harder to eyeball whether the number
* on the screen looks right!
*/
def
flockSep
:
Double
=
println
(
"Warning, you haven't implemented flockSep!"
)
0d
}
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