summaryrefslogtreecommitdiff
path: root/emoji/okstars.js
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-05-22 02:32:30 -0400
committerJulie Lala <jules@okfoc.us>2014-05-22 02:32:30 -0400
commit38d19cdf951a5e8dbb0a0cddcd9327ae389e2800 (patch)
tree074c06017cddabd8636f744db10e0ae101b5eba2 /emoji/okstars.js
parent852e24f5493615000350c28d953d4a91b1ce05e2 (diff)
stars on the follow demo
Diffstat (limited to 'emoji/okstars.js')
-rw-r--r--emoji/okstars.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/emoji/okstars.js b/emoji/okstars.js
new file mode 100644
index 0000000..4f1cde3
--- /dev/null
+++ b/emoji/okstars.js
@@ -0,0 +1,74 @@
+(function($){
+
+ $.okstars = function(el, options){
+ var base = this;
+ base.$el = $(el);
+ base.el = el;
+ base.$el.data("okstars", base);
+
+ base.init = function () {
+ base.options = $.extend({}, $.okstars.options, options);
+ if (! base.canvas) base.canvas = base.new_canvas();
+ base.context = base.canvas.getContext("2d");
+ base.build();
+ $(window).resize(base.build)
+ };
+
+ base.new_canvas = function () {
+ var canvas = document.createElement("canvas");
+ canvas.style.cssText = "position:fixed;top:0;left:0;z-index:-1;";
+ base.$el.append(canvas);
+ return canvas;
+ };
+ function randrange(a,b){
+ var x = Math.random()
+ return a * (1-x) + b * x
+ }
+ base.build = function () {
+ var w = base.canvas.width = window.innerWidth
+ var h = base.canvas.height = window.innerHeight
+ var context = base.context;
+ var starcount = ~~randrange(base.options.starMin, base.options.starMax)
+ var tt = +new Date()
+ for (var i = 0; i < starcount; i++) {
+ var radius = Math.random() * 2
+ context.fillStyle = base.mottle_gray(base.options.color, base.options.colorrange)
+ context.fillRect( Math.random() * w, Math.random() * h, radius,radius)
+ }
+// console.log("generated", starcount, "stars in", (+new Date() - tt), "ms")
+ };
+
+ base.clamp = function (x, min, max) {
+ return Math.max(min, Math.min(max, x));
+ };
+ base.mottle_gray = function (color, radius) {
+ var rgb = color.split("")
+ var rgbcolor = 'rgb('
+ var offset = Math.floor(Math.random()*radius*2 - radius)
+ rgbcolor += parseInt(rgb[0], 16) * 16 + offset
+ rgbcolor += ","
+ rgbcolor += parseInt(rgb[1], 16) * 16 + offset
+ rgbcolor += ","
+ rgbcolor += parseInt(rgb[2], 16) * 16 + offset
+ rgbcolor += ")"
+ return rgbcolor
+ };
+
+ base.init();
+ };
+
+ $.okstars.options = {
+ transparent: false,
+ starMin: 100,
+ starMax: 1000,
+ color: "888",
+ colorrange: 128
+ };
+
+ $.fn.okstars = function(options){
+ return this.each(function(){
+ (new $.okstars(this, options));
+ });
+ };
+
+})(jQuery);