Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fadecandy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scanlime
Fadecandy
Commits
e1041cd6
Commit
e1041cd6
authored
11 years ago
by
Micah Elizabeth Scott
Browse files
Options
Downloads
Patches
Plain Diff
Temporal smoothing for triangle16_snake
parent
c73542d3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/processing/triangle16_snake/triangle16_snake.pde
+17
-6
17 additions, 6 deletions
examples/processing/triangle16_snake/triangle16_snake.pde
with
17 additions
and
6 deletions
examples/processing/triangle16_snake/triangle16_snake.pde
+
17
−
6
View file @
e1041cd6
// Parameters!
int
stepsPerSecond
=
30
;
float
maxEnergy
=
20
;
float
minEnergy
=
8
;
float
minEnergy
=
4
;
float
minSaturation
=
10
;
float
maxSaturation
=
100
;
float
energyChangeRate
=
0.01
;
float
hueShift
=
(
100.0
/
2
)
+
2.0
;
float
hueShift
=
(
100.0
/
2
)
+
1.2
;
float
alpha
=
10
;
float
energyExp
=
3.5
;
OPC
opc
;
TriangleGrid
triangle
;
...
...
@@ -22,6 +26,7 @@ int stepNumber = 0;
void
setup
()
{
size
(
200
,
200
);
background
(
0
);
// Pacing
frameRate
(
stepsPerSecond
);
...
...
@@ -45,6 +50,10 @@ void setup()
currentHue
=
random
(
100
);
currentCell
=
int
(
random
(
triangle
.
cells
.
length
));
// Hide LED location dots, so we can alpha blend against the previous frame without
// these dots stomping on the pixel data we care about.
opc
.
showLocations
(
false
);
colorMode
(
HSB
,
100
);
}
...
...
@@ -107,12 +116,13 @@ int chooseEmpty()
void
draw
()
{
background
(
0
);
stepNumber
++
;
// Cell energies vary in sinusoidal epochs, causing the shape of the snakes
// to shift accordingly as the space becomes more or less fragmented.
int
currentEnergy
=
int
(
map
(
cos
(
stepNumber
*
energyChangeRate
),
1
,
-
1
,
minEnergy
,
maxEnergy
));
float
e
=
map
(
cos
(
stepNumber
*
energyChangeRate
),
1
,
-
1
,
0
,
1
);
e
=
pow
(
e
,
energyExp
);
int
currentEnergy
=
int
(
map
(
e
,
0
,
1
,
minEnergy
,
maxEnergy
));
// Each live cell decays by one step, no cells can live longer than currentEnergy.
// This creates a cadence to the life of each snake, and periodic waves of extinction.
...
...
@@ -144,12 +154,13 @@ void draw()
// Overall saturation shows the current energy level. Extinction periods (low currentEnergy)
// correspond with flashes of white.
float
saturation
=
map
(
currentEnergy
,
minEnergy
,
maxEnergy
,
0
,
100
);
float
saturation
=
map
(
currentEnergy
,
minEnergy
,
maxEnergy
,
minSaturation
,
maxSaturation
);
// Draw the current state of each cell
for
(
int
i
=
0
;
i
<
triangle
.
cells
.
length
;
i
++
)
{
float
size
=
height
*
0.1
;
fill
(
cellHues
[
i
],
saturation
,
map
(
cellEnergies
[
i
],
0
,
currentEnergy
,
0
,
100
));
fill
(
cellHues
[
i
],
saturation
,
map
(
cellEnergies
[
i
],
0
,
currentEnergy
,
0
,
100
)
,
alpha
);
ellipse
(
triangle
.
cells
[
i
].
center
.
x
,
triangle
.
cells
[
i
].
center
.
y
,
size
,
size
);
}
}
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