-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheart.js
95 lines (81 loc) · 1.92 KB
/
heart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
float angle = 0;
float px = 0, py = 0;
float amplitude = 30;
float frequency = 0;
float fillGap = 2.5;
color c;
void setup() {
size(640, 360);
background(200);
noLoop();
}
void draw() {
for (int i =- 75; i < height+75; i++){
// Reset angle to 0, so waves stack properly
angle = 0;
// Increasing frequency causes more gaps
frequency+=.002;
for (float j = 0; j < width+75; j++){
py = i + sin(radians(angle)) * amplitude;
angle += frequency;
c = color(abs(py-i)*255/amplitude, 255-abs(py-i)*255/amplitude, j*(255.0/(width+50)));
// Hack to fill gaps. Raise value of fillGap if you increase frequency
for (int filler = 0; filler < fillGap; filler++){
set(int(j-filler), int(py)-filler, c);
set(int(j), int(py), c);
set(int(j+filler), int(py)+filler, c);
}
}
}
}
window.onload = function() {
var myCanvas = document.createElement('canvas');
}
/*
ARDUINO test code:
// Pulse Monitor Test Script
int ledPin = 13;
int sensorPin = 0;
double alpha = 0.75;
int period = 20;
double change = 0.0;
void setup ()
{
pinMode (ledPin, OUTPUT);
Serial.begin (115200);
}
void loop ()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead (sensorPin);
double value = alpha * oldValue + (1 - alpha) * rawValue;
Serial.print (rawValue);
Serial.print (",");
Serial.println (value);
oldValue = value;
delay (period);
}
*/
var ledPin = 13;
var sensorPin = 0;
//double alpha = 0.75;
var period = 20;
//double change = 0.0;
function setup ()
{
pinMode (ledPin, OUTPUT);
Serial.begin (115200);
}
function loop ()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead (sensorPin);
double value = alpha * oldValue + (1 - alpha) * rawValue;
console.log (rawValue);
console.log (",");
console.log (value);
oldValue = value;
delay (period);
}