retitem.r = r+rr;
return retitem;
}
+ flip(q,r) {
+ // flips about point
+ var ret = this.clone();
+ let dq = q-this.q;
+ let dr = r-this.r;
+ ret.q = q + dq;
+ ret.r = r + dr;
+ return ret;
+ }
}
<span>
<input type="button" id="step" value="step"/>
<input type="button" id="playpause" value="play"/>
- <input type="range" id="tempo" min="20" max="500"/>
+ <input type="range" id="tempo" value="150" min="20" max="500"/>
<input type="button" id="clear" value="clear"/>
<input type="button" id="reset" value="reset"/>
</span>
<span>
- <input type="number" id="rad" value="5" min="1" max="30" step="1"/>
+ <input type="number" id="rad" value="9" min="1" max="30" step="1"/>
<input type="button" id="rot" value="rotate hex"/>
+ <input type="button" id="flp" value="flip hex"/>
<input type="button" id="copy" value="copy hex"/>
<input type="button" id="paste" value="paste hex"/>
</span>
sv.onclick = saveState;
ld = document.getElementById("load");
ld.onclick = loadState;
+ fl = document.getElementById("flp");
+ fl.onclick = flipButtonHandler;
load_demos(document.getElementById('seldemo'));
dl = document.getElementById("dload");
dl.onclick = demoHandler;
}
};
+flipButtonHandler = function(e) {
+ c.onclick = e=>flipThingy(e);
+ c.addEventListener('mousemove', radius_hover);
+
+ // tf are those arguments globals are there for a reason
+}
+flipThingy = function(evt) {
+ c.removeEventListener('mousemove', radius_hover);
+ let coords = getClickCoords(c,scale,xcenter,ycenter,evt);
+ let rad = parseInt(document.getElementById('rad').value);
+ g.flipHex(coords.q,coords.r,rad);
+ drawGrid(g, ctx, xcenter,ycenter,scale);
+ c.onclick = e=>wwonclick(c,ctx,g,xcenter,ycenter,scale,e);
+}
+
rotateButtonHandler = function(e) {
c.onclick = e=>rotateThingy(e);
c.addEventListener('mousemove', radius_hover);
let cells2 = this.cells.map((c)=>c.rotate(q,r,ccw));
this.cells = cells2;
}
+
+ flipHex(q,r,radius) {
+ var rcells = [this.cellAt(q,r)];
+ for(let i=1; i<radius; i++) {
+ var currcell = this.cellAt(q,r+i);
+ for(let j=0; j<6; j++) {
+ let dirv = null;
+ switch(j) {
+ case 0:
+ dirv = {q: 1, r:-1};
+ break;
+ case 1:
+ dirv = {q: 0, r:-1};
+ break;
+ case 2:
+ dirv = {q:-1, r: 0};
+ break;
+ case 3:
+ dirv = {q:-1, r: 1};
+ break;
+ case 4:
+ dirv = {q: 0, r: 1};
+ break;
+ case 5:
+ dirv = {q: 1, r: 0};
+ break;
+ }
+ for(let k=0; k<i; k++) {
+ rcells.push(currcell);
+ currcell = this.cellAt(currcell.q + dirv.q, currcell.r + dirv.r);
+ }
+ }
+ }
+
+ let newcells = rcells.map(x=>x.flip(q,r));
+ //this.cells = newcells;
+ for(let i of newcells) {
+ this.change(i.state, i.q, i.r);
+ }
+ this.clean();
+
+ }
+
rotateHex(q,r,radius,ccw=true) {
var rcells = [this.cellAt(q,r)];
for(let i=1; i<radius; i++) {