Author Topic: Proper "hill" generation (or rather, half-sphere in this case)  (Read 844 times)

I've tried a lot of things, tinkering around with how it shifts back, but it always justs gives me the first layer of bricks, which is a flat circle, and then does nothing else. The ghost brick simply flies off into the air and far away.

This is the math I've been doing for this:

Code: [Select]
function tryGenerateHill(%diameter)
{
if(getSubStr(%diameter, strLen(%diameter), strLen(%diameter)) != 0 || getSubStr(%diameter, strLen(%diameter), strLen(%diameter)) != 2 || getSubStr(%diameter, strLen(%diameter), strLen(%diameter)) != 4 || getSubStr(%diameter, strLen(%diameter), strLen(%diameter)) != 6 || getSubStr(%diameter, strLen(%diameter), strLen(%diameter)) != 8)
mCeil(%diameter+0.1);
%maxSpace = mFloatLength((3.14*%diameter)*0.125, 0);
%curSpace = %maxSpace;
for(%h = 0; %h < %diameter*(mCeil(%diameter*0.33)); %h++)
{
for(%i = 0; %i < %diameter-1; %i++)
{
if(%curSpace > 0 && !%reachedDiameter)
{
for(%skip = 0; %skip < %curSpace; %skip++)
{
superShiftBrickRight(1);
superShiftBrickRight(0);
}
for(%place = 0; %place < %diameter-(%curSpace*2); %place++)
{
plantBrick(1);
plantBrick(0);
superShiftBrickRight(1);
superShiftBrickRight(0);
}
for(%skip = 0; %skip < %curSpace; %skip++)
{
superShiftBrickRight(1);
superShiftBrickRight(0);
}
%curSpace--;
}
else if(%curSpace <= 0 && !%reachedDiameter)
{
for(%place = 0; %place < %diameter; %place++)
{
plantBrick(1);
plantBrick(0);
superShiftBrickRight(1);
superShiftBrickRight(0);
}
%curSpace++;
%reachedDiameter = 1;
}
else if(%curSpace > 0 && %reachedDiameter)
{
for(%skip = 0; %skip < %curSpace; %skip++)
{
superShiftBrickRight(1);
superShiftBrickRight(0);
}
for(%place = 0; %place < %diameter-(%curSpace*2); %place++)
{
plantBrick(1);
plantBrick(0);
superShiftBrickRight(1);
superShiftBrickRight(0);
}
for(%skip = 0; %skip < %curSpace; %skip++)
{
superShiftBrickRight(1);
superShiftBrickRight(0);
}
%curSpace++;
}
for(%realign = 0; %realign < %diameter; %realign++)
{
superShiftBrickLeft(1);
superShiftBrickLeft(0);
}
superShiftBrickAway(1);
superShiftBrickAway(0);
}
%reachedDiameter = 0;
superShiftBrickUp(1);
superShiftBrickUp(0);
//for(%moveBack = 0; %moveBack < %diameter; %moveBack++)
//{
// superShiftBrickLeft(1);
// superShiftBrickLeft(0);
//}
for(%moveBack = 0; %moveBack < %diameter-1; %moveBack++)
{
superShiftBrickTowards(1);
superShiftBrickTowards(0);
}
superShiftBrickAway(1);
superShiftBrickAway(0);
superShiftBrickRight(1);
superShiftBrickRight(0);
%diameter--;
%curSpace = %maxSpace-%h;
}
}

Based on the concept that if the diameter is even, the "height" of the flat circle will always be one brick less than the diameter, and the maximum amount of bricks you can fit in from the "topmost" part of the circle out to as far as the circle extends from there will be around [(pi*diameter)*0.125] bricks.

Edit:
D'oh, wait, I forgot to set %reachedDiameter back after the loop is over, hold on, let me try that.

Edit2:
Those darned coding habits, I put %i instead of %h.

Edit3:
Also forgot to set %curSpace to a correct value.

Edit4:
Got it, sorta. Not really a half-sphere that I was looking for but I can handle that



If anyone can help me with my math I'd be thankful.
« Last Edit: May 27, 2011, 01:39:56 AM by otto-san »

So you make the first layer of bricks, but then you can't get it to move on to the next layer up, correct?

So you make the first layer of bricks, but then you can't get it to move on to the next layer up, correct?
No, I've fixed that.

Now it makes cliff-like things.

I need to revise my math then...

Ive attempted some stuff like this on my own already.

stuff to watch for:
 bricks may be square.. but they are not a CUBE -- unless you use the 4x cube brick.  make sure you take that into account. 
a 2x2 brick is 0.5x0.5 by 0.6 tall
a 1x1F brick is 0.5x0.5 by 0.2 tall

glacing over your code, I see this:
 %diameter--

decreasing the diameter by a constant value will give you a cone -- not a half sphere

glacing over your code, I see this:
 %diameter--

decreasing the diameter by a constant value will give you a cone -- not a half sphere
I've found this out.

Ive attempted some stuff like this on my own already.

stuff to watch for:
 bricks may be square.. but they are not a CUBE -- unless you use the 4x cube brick.  make sure you take that into account. 
He's using super shift. It doesn't matter.