Skip to content

Instantly share code, notes, and snippets.

@DarrenCattle
Last active August 29, 2015 14:04
Show Gist options
  • Save DarrenCattle/c151dde00cba853b23d1 to your computer and use it in GitHub Desktop.
Save DarrenCattle/c151dde00cba853b23d1 to your computer and use it in GitHub Desktop.
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
var spiral = (function () {
var sp = {};
sp.draw = function() {
console.log('hi dcat');
//place matrix single click in the grid
var self = this;
this.post = [];
var delay = 400;
for(var a = 0; a < this.list.length; a++) {
setTimeout(
(function(a) {
return function() {
if($('.col_' + self.list[a].y + '_' + self.list[a].x).style.backgroundColor) {
self.post.push({"x": self.list[a].x, "y": self.list[a].y});
$('.col_' + self.list[a].y + '_' + self.list[a].x).click();}
$('.col_' + self.list[a].y + '_' + self.list[a].x).click();
console.log("coordinates: " + self.list[a].x + " , " + self.list[a].y);
}
})(a), delay);
delay += 400;
}
};
sp.finish = function () {
//run separately to fill spaces of array
var delay=400;
var self = this;
for(var a = this.post.length-1; a >= 0; a--) {
setTimeout(
(function(a) {
return function() {
$('.col_' + self.post[a].y + '_' + self.post[a].x).click();
console.log("coordinates: " + self.post[a].x + " , " + self.post[a].y);
}
})(a), delay);
delay += 400;
}
};
sp.init = function(ix,iy,len) {
this.ix = ix; this.iy = iy; this.len = len;
var lastx = this.ix; var lasty = this.iy;
var multx = 1; var multy = 0;
var counter = 0;
var add = 0;
this.list = [];
//matrix calculation of spiral
for (var k = len; k > 0; k--) {
for (var i = 0; i < k; i++) {
lastx = lastx+multx;
lasty = lasty+multy;
this.list.push({"x": lastx,"y": lasty});
add++;
}
if((counter+4)%4 == 0) {multx=0; multy=1;}
if((counter+4)%4 == 1) {multx=-1; multy=0;}
if((counter+4)%4 == 2) {multx=0; multy=-1;}
if((counter+4)%4 == 3) {multx=1; multy=0;}
counter++;
}
this.draw();
};
return sp;
})();
//usage
//spiral.init(x,y,size);
//spiral.finish();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment