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
d5b99f53
Commit
d5b99f53
authored
11 years ago
by
Micah Elizabeth Scott
Browse files
Options
Downloads
Patches
Plain Diff
HSV color for opc.js
parent
940e7b13
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/node/opc.js
+50
-6
50 additions, 6 deletions
examples/node/opc.js
examples/node/particle_trail.js
+9
-7
9 additions, 7 deletions
examples/node/particle_trail.js
with
59 additions
and
13 deletions
examples/node/opc.js
+
50
−
6
View file @
d5b99f53
...
...
@@ -8,6 +8,11 @@
var
net
=
require
(
'
net
'
);
var
fs
=
require
(
'
fs
'
);
/********************************************************************************
* Core OPC Client
*/
var
OPC
=
function
(
host
,
port
)
{
this
.
host
=
host
;
...
...
@@ -15,12 +20,6 @@ var OPC = function(host, port)
this
.
pixelBuffer
=
null
;
};
OPC
.
loadModel
=
function
(
filename
)
{
// Synchronously load a JSON model from a file on disk
return
JSON
.
parse
(
fs
.
readFileSync
(
filename
))
}
OPC
.
prototype
.
_reconnect
=
function
()
{
var
_this
=
this
;
...
...
@@ -105,6 +104,11 @@ OPC.prototype.mapPixels = function(fn, model)
this
.
writePixels
();
}
/********************************************************************************
* Client convenience methods
*/
OPC
.
prototype
.
mapParticles
=
function
(
particles
,
model
)
{
// Set all pixels, by mapping a particle system to each element of "model".
...
...
@@ -140,4 +144,44 @@ OPC.prototype.mapParticles = function(particles, model)
this
.
mapPixels
(
shader
,
model
);
}
/********************************************************************************
* Global convenience methods
*/
OPC
.
loadModel
=
function
(
filename
)
{
// Synchronously load a JSON model from a file on disk
return
JSON
.
parse
(
fs
.
readFileSync
(
filename
))
}
OPC
.
hsv
=
function
(
h
,
s
,
v
)
{
/*
* Converts an HSV color value to RGB.
*
* Normal hsv range is in [0, 1], RGB range is [0, 255].
* Colors may extend outside these bounds. Hue values will wrap.
*
* Based on tinycolor:
* https://github.com/bgrins/TinyColor/blob/master/tinycolor.js
* 2013-08-10, Brian Grinstead, MIT License
*/
h
*=
6
;
var
i
=
h
|
0
,
f
=
h
-
i
,
p
=
v
*
(
1
-
s
),
q
=
v
*
(
1
-
f
*
s
),
t
=
v
*
(
1
-
(
1
-
f
)
*
s
),
mod
=
i
%
6
,
r
=
[
v
,
q
,
p
,
p
,
t
,
v
][
mod
],
g
=
[
t
,
v
,
v
,
q
,
p
,
p
][
mod
],
b
=
[
p
,
p
,
t
,
v
,
v
,
q
][
mod
];
return
[
r
*
255
,
g
*
255
,
b
*
255
];
}
module
.
exports
=
OPC
;
This diff is collapsed.
Click to expand it.
examples/node/particle_trail.js
+
9
−
7
View file @
d5b99f53
...
...
@@ -9,23 +9,25 @@ var client = new OPC('localhost', 7890);
function
draw
()
{
var
t
=
0.009
*
new
Date
().
getTime
();
var
t
ime
=
0.009
*
new
Date
().
getTime
();
var
numParticles
=
200
;
var
particles
=
[];
for
(
var
i
=
0
;
i
<
numParticles
;
i
++
)
{
var
s
=
i
/
numParticles
;
var
r
=
0.2
+
1.5
*
i
/
numParticles
;
var
x
=
r
*
Math
.
cos
(
t
);
var
y
=
r
*
Math
.
sin
(
t
+
10.0
*
Math
.
sin
(
t
*
0.15
));
var
radius
=
0.2
+
1.5
*
s
;
var
theta
=
time
+
0.04
*
i
;
var
x
=
radius
*
Math
.
cos
(
theta
);
var
y
=
radius
*
Math
.
sin
(
theta
+
10.0
*
Math
.
sin
(
theta
*
0.15
));
var
hue
=
time
*
0.01
+
s
*
0.2
;
particles
[
i
]
=
{
point
:
[
0
,
x
,
y
],
intensity
:
40
*
i
/
numParticle
s
,
intensity
:
0.2
*
s
,
falloff
:
60
,
color
:
[
0.9
,
0.
2
,
i
*
0.01
]
color
:
OPC
.
hsv
(
hue
,
0.
5
,
0.8
)
};
t
+=
0.04
;
}
client
.
mapParticles
(
particles
,
model
);
...
...
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