Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
grains
grains-web
Commits
121f8746
Commit
121f8746
authored
May 09, 2017
by
Jens-Christian Fischer
Browse files
Grow boid on acceleration
parent
cddfc939
Changes
3
Hide whitespace changes
Inline
Side-by-side
mix.exs
View file @
121f8746
...
...
@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def
project
do
[
app:
:grains
,
version:
"0.0.4
7
"
,
version:
"0.0.4
8
"
,
elixir:
"~> 1.2"
,
elixirc_paths:
elixirc_paths
(
Mix
.
env
),
compilers:
[
:phoenix
,
:gettext
]
++
Mix
.
compilers
,
...
...
web/static/js/app.js
View file @
121f8746
...
...
@@ -110,6 +110,7 @@ visuals.on("velocity", state => {
visuals
.
on
(
"
acceleration
"
,
state
=>
{
console
.
log
(
"
acceleration:
"
,
state
);
PresenceSketch
.
set_acceleration
(
state
.
user
,
state
.
z
);
});
visuals
.
join
().
receive
(
"
ok
"
,
resp
=>
{
...
...
web/static/js/presencesketch.js
View file @
121f8746
...
...
@@ -11,13 +11,18 @@ function Boid(p, x, y) {
this
.
velocity
=
p5
.
Vector
.
random2D
();
this
.
position
=
this
.
p
.
createVector
(
x
,
y
);
this
.
r
=
3.0
;
this
.
radius
=
16
;
this
.
maxspeed
=
3
;
// Maximum speed
this
.
maxforce
=
0.05
;
// Maximum steering force
};
Boid
.
prototype
.
set_velocity
=
function
(
dx
,
dy
)
{
this
.
velocity
=
this
.
p
.
createVector
(
dx
,
dy
);
}
};
Boids
.
prototype
.
set_acceleration
=
function
(
z
)
{
this
.
r
=
32
;
};
Boid
.
prototype
.
run
=
function
(
boids
)
{
...
...
@@ -73,9 +78,10 @@ Boid.prototype.seek = function(target) {
// Draw boid as a circle
Boid
.
prototype
.
render
=
function
()
{
this
.
p
.
fill
(
127
,
127
);
this
.
p
.
fill
(
(
this
.
radius
*
8
)
-
1
);
this
.
p
.
stroke
(
200
);
this
.
p
.
ellipse
(
this
.
position
.
x
,
this
.
position
.
y
,
16
,
16
);
this
.
p
.
ellipse
(
this
.
position
.
x
,
this
.
position
.
y
,
this
.
radius
,
this
.
radius
);
if
(
this
.
radius
>
16
)
{
this
.
radius
=
this
.
radius
-
1
;
}
};
// Wraparound
...
...
@@ -180,6 +186,10 @@ let PresenceSketch = {
PresenceSketch
.
boids
[
name
].
set_velocity
(
dx
,
dy
);
},
set_acceleration
(
name
,
z
)
{
PresenceSketch
.
boids
[
name
].
set_acceleration
(
z
);
},
addBoids
(
joins
)
{
if
(
!
PresenceSketch
.
p5
)
{
return
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment