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
2885bfde
Commit
2885bfde
authored
May 17, 2017
by
Jens-Christian Fischer
Browse files
Bouncing instead of wrapping & cut back on psychedelics
parent
bfba927a
Changes
2
Hide whitespace changes
Inline
Side-by-side
mix.exs
View file @
2885bfde
...
...
@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def
project
do
[
app:
:grains
,
version:
"0.0.6
4
"
,
version:
"0.0.6
5
"
,
elixir:
"~> 1.2"
,
elixirc_paths:
elixirc_paths
(
Mix
.
env
),
compilers:
[
:phoenix
,
:gettext
]
++
Mix
.
compilers
,
...
...
web/static/js/presencesketch.js
View file @
2885bfde
...
...
@@ -23,6 +23,9 @@ function Boid(p, x, y, type) {
this
.
separation_f
=
2.5
;
this
.
alignment_f
=
1.0
;
this
.
cohesion_f
=
2.0
;
this
.
spin
=
parseInt
(
this
.
p
.
random
(
-
50
,
50
));
this
.
saturation
=
this
.
p
.
random
(
50
,
100
);
this
.
color
=
this
.
p
.
color
(
this
.
p
.
random
(
359
),
100
,
100
);
};
...
...
@@ -108,10 +111,11 @@ Boid.prototype.render = function() {
// Wraparound
Boid
.
prototype
.
borders
=
function
()
{
if
(
this
.
position
.
x
<
-
this
.
r
)
this
.
position
.
x
=
PresenceSketch
.
width
+
this
.
r
;
if
(
this
.
position
.
y
<
-
this
.
r
)
this
.
position
.
y
=
PresenceSketch
.
height
+
this
.
r
;
if
(
this
.
position
.
x
>
PresenceSketch
.
width
+
this
.
r
)
this
.
position
.
x
=
-
this
.
r
;
if
(
this
.
position
.
y
>
PresenceSketch
.
height
+
this
.
r
)
this
.
position
.
y
=
-
this
.
r
;
let
jitter
=
this
.
p
.
random
(
0.9
,
1.1
);
if
(
this
.
position
.
x
<
-
this
.
r
)
this
.
velocity
.
x
=
-
this
.
velocity
.
x
*
jitter
;
if
(
this
.
position
.
y
<
-
this
.
r
)
this
.
velocity
.
y
=
-
this
.
velocity
.
y
*
jitter
;
if
(
this
.
position
.
x
>
PresenceSketch
.
width
+
this
.
r
)
this
.
velocity
.
x
=
-
this
.
velocity
.
x
*
jitter
;
if
(
this
.
position
.
y
>
PresenceSketch
.
height
+
this
.
r
)
this
.
velocity
.
y
=
-
this
.
velocity
.
y
*
jitter
;
};
// Separation
...
...
@@ -299,7 +303,7 @@ Master.prototype.send_osc = function() {
}
Boid
.
prototype
.
adjust_radius
=
function
()
{
if
(
this
.
radius
>
this
.
norm_radius
)
{
this
.
radius
=
this
.
radius
-
1
;
};
if
(
this
.
radius
>
this
.
norm_radius
&&
(
this
.
p
.
frameCount
%
3
==
0
)
)
{
this
.
radius
=
this
.
radius
-
1
;
};
}
Master
.
prototype
.
adjust_radius
=
function
()
{
...
...
@@ -310,26 +314,26 @@ Boid.prototype.fillColor = function() {
let
color
;
switch
(
this
.
type
)
{
case
'
square
'
:
color
=
this
.
p
.
color
(
0
,
80
+
Math
.
random
()
*
20
,
(
this
.
radius
*
3
));
case
'
square
'
:
color
=
this
.
p
.
color
(
0
,
this
.
saturation
,
(
this
.
radius
*
3
));
break
;
case
'
circle
'
:
color
=
this
.
p
.
color
(
90
,
80
+
Math
.
random
()
*
20
,
(
this
.
radius
*
3
));
case
'
circle
'
:
color
=
this
.
p
.
color
(
90
,
this
.
saturation
,
(
this
.
radius
*
3
));
break
;
case
'
triangle
'
:
color
=
this
.
p
.
color
(
1
8
0
,
80
+
Math
.
random
()
*
20
,
(
this
.
radius
*
3
));
case
'
triangle
'
:
color
=
this
.
p
.
color
(
2
10
,
this
.
saturation
,
(
this
.
radius
*
3
));
break
;
case
'
star
'
:
color
=
this
.
p
.
color
(
270
,
80
+
Math
.
random
()
*
20
,
(
this
.
radius
*
3
));
case
'
star
'
:
color
=
this
.
p
.
color
(
270
,
this
.
saturation
,
(
this
.
radius
*
3
));
break
;
}
return
color
;
}
Boid
.
prototype
.
render
=
function
()
{
this
.
p
.
fill
(
this
.
fillC
olor
()
);
this
.
p
.
fill
(
this
.
c
olor
);
this
.
p
.
stroke
(
200
);
this
.
p
.
push
();
this
.
p
.
translate
(
this
.
position
.
x
,
this
.
position
.
y
);
this
.
p
.
rotate
(
this
.
p
.
frameCount
/
50.0
);
this
.
p
.
rotate
(
this
.
p
.
frameCount
/
this
.
spin
);
switch
(
this
.
type
)
{
case
'
square
'
:
this
.
render_square
();
break
;
...
...
@@ -471,7 +475,7 @@ let PresenceSketch = {
};
s
.
draw
=
function
()
{
//
s.background(88, 131, 120);
s
.
background
(
88
,
131
,
120
);
// Run all the boids
_
.
each
(
PresenceSketch
.
boids
,
function
(
boid
,
key
,
list
)
{
...
...
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