Skip to content
Browse files

Added random bobbing to floaters, and opacity now directly proportion…

…al to ratio.
  • Loading branch information...
1 parent d660838 commit 29bf33431d47d1aaabcb523fd00539c484f5b04a @spacemunkay spacemunkay committed
Showing with 12 additions and 4 deletions.
  1. +12 −4 js/application.js
View
16 js/application.js
@@ -17,16 +17,19 @@ function create_floater(file, klass, x, y, delta)
{
var ratio = Math.random();
var spd = Math.ceil(ratio*delta);
+ var amp = 5 * Math.random() + .1;
+ var shift = 2 * Math.PI * Math.random();
+
var image = $('<img/>', {
src: 'images/' + file,
style: 'width: ' + Math.floor(ratio*100) + '%;'
}).appendTo($('<div/>', {
'class': klass,
- style: 'position: absolute; z-index: 100; left: ' + x + 'px; top: ' + y + 'px; width: 60px; height: 60px;'
+ style: 'position: absolute; z-index: 100; opacity: ' + ratio + '; left: ' + x + 'px; top: ' + y + 'px; width: 60px; height: 60px;'
}).appendTo('#container'));
var elem = image.parent();
- var t = setInterval(function(){move_right(elem, spd)}, refresh);
+ var t = setInterval(function(){move_right(elem, spd); bob(elem, y, .1, amp, shift)}, refresh);
elem.attr('spd', spd);
elem.attr('int', t);
return elem;
@@ -39,7 +42,7 @@ function clouds()
var y = iHeight - Math.floor(Math.random()*height);
var x = Math.floor(Math.random()*iWidth);
- create_floater(cloud_files[idx], 'cloud', x, y, 3);
+ create_floater(cloud_files[idx], 'cloud', x, y, 1);
}
function dirigibles()
@@ -49,7 +52,7 @@ function dirigibles()
var y = iHeight - Math.floor(Math.random()*height);
var x = Math.floor(Math.random()*iWidth);
- var dirig = create_floater(files[idx], 'dirig', x, y, 5);
+ var dirig = create_floater(files[idx], 'dirig', x, y, 2);
var image = dirig.find('img').first();
dirig.css('width', image.clientWidth);
@@ -80,6 +83,11 @@ function move_right(elem, spd)
elem.css('left', '-100px');
}
+function bob(elem, y, feq, amp, shift)
+{
+ elem.css('top', y + amp * Math.sin(feq * elem.position().left + shift) + 'px');
+}
+
// $('#second-hackathon').eventbrite_attendees({
// app_key: 'MWUwZjRlZjk4MDk3',
// event_id: '943934333'

0 comments on commit 29bf334

Please sign in to comment.
Something went wrong with that request. Please try again.