Re: I have game idea, please make it for me...
Posted: 31 Mar 2011, 19:53
sqrt(2)/2
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
oops... I didn't notice you post... I worked it out to r.sqrt(3) which was right (my circles have a radius of 50 and the offset of each row is ~86.6 so I've used 87)...Beherith wrote:sqrt(2)/2
Ambigious question.SinbadEV wrote:what is the ratio of vertical offset to radius for the second row in a hexagonal latice?
You asked for a ratio. For the ratio h/r. So there is no r. Ask about h expressed in function of r if that is what you want.SinbadEV wrote:where's the variable?
Code: Select all
function intersects(x, y, cx, cy, r) {
dx = x-cx
dy = y-cy
return dx*dx+dy*dy <= r*r
}
function mouseMove(e)
{
var mouseX=0, mouseY=0;
if(e.offsetX) {
mouseX = e.offsetX;
mouseY = e.offsetY;
}
else if(e.layerX) {
mouseX = e.layerX;
mouseY = e.layerY;
}
/* do something with mouseX/mouseY */
var coords=document.getElementById("coords");
coords.innerHTML = mouseX+", "+mouseY;
var found = false;
for (x=0;x<x_cols;x++) {
for (y=0;y<y_rows;y++) {
cxt.fillStyle="#000000";
coordText = "("+x+","+y+")";
metrics = cxt.measureText(coordText)
wo = Math.floor(metrics.width/2);
if (intersects(mouseX,mouseY,x*2*r+r+(y*r),y*o+r, r) && !found) {
data.innerHTML = x+", "+y;
found = true;
}
}
}
if (!found) {data.innerHTML = "none"};
}
Code: Select all
function intersects(x, y, cx, cy, r) {
dx = x-cx
dy = y-cy
return dx*dx+dy*dy <= r*r
}
function mouseMove(e)
{
var mouseX=0, mouseY=0;
if(e.offsetX) {
mouseX = e.offsetX;
mouseY = e.offsetY;
}
else if(e.layerX) {
mouseX = e.layerX;
mouseY = e.layerY;
}
/* do something with mouseX/mouseY */
coords.innerHTML = mouseX+", "+mouseY;
var found = false;
for (x=0;x<x_cols;x++) {
for (y=0;y<y_rows;y++) {
if (intersects(mouseX,mouseY,x*2*r+r+(y*r),y*o+r, r) && !found) {
data.innerHTML = x+", "+y;
found = true;
}
}
}
if (!found) {data.innerHTML = "none"};
}