Skip to content

Instantly share code, notes, and snippets.

@repeatingbeats
Last active December 20, 2015 12:08
Show Gist options
  • Save repeatingbeats/6128287 to your computer and use it in GitHub Desktop.
Save repeatingbeats/6128287 to your computer and use it in GitHub Desktop.
Let's try to make a bl.ock

A bl.ock

That does nothing.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>some bl.ock</title>
</head>
<body>
<h1>just a bl.ock</h1>
<div id="chart"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="my-block.js"></script>
</body>
</html>
var signal = (function () {
function square(time, options) {
var i, len = time.length, wave = [], hi, lo;
options = options ? _.clone(options) : {};
options = _.defaults(options, { period: 1, amplitude: 1, offset: 0 });
hi = offset + amplitude;
lo = offset - amplitude;
for (i = 0; i < len; i++) {
wave[i] = Math.sin(2 * Math.PI * options.period * time[i]) >= 0 ? 1 : -1;
}
return wave;
}
return {
square: square
};
}());
var sq = (function() {
console.log('it works');
var time = d3.range(0, 100, 0.2)
, squareWave = signal.square(time);
return squareWave;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment