I am trying to make a spiral centred in (0,0) that you can start form any arbitry point inside it.
In other words: the spiral should have the shape of one that started at 0,0 but starting from an arbitrary point (as if you removed previous positions)
I made the following code but it only works when both initX and initY are 0:
void printSpiralCoords(int32_t initX, int32_t initY, uint32_t steps) {
int8_t dx = 0;
int8_t dy = 0;
uint32_t stepsDone = 0;
uint32_t length = 0;
uint32_t absX = abs(initX);
uint32_t absY = abs(initY);
if (absX > absY) {
if (initX >= 0) {
dy = 1;
}
else {
dy = -1;
}
stepsDone = absY;
length = absX;
}
else {
if (initY >= 0) {
dx = 1;
}
else {
dx = -1;
}
stepsDone = absX;
length = absY;
}
if (length == 0) {
length = 1;
}
for (uint32_t i = 0; i < steps; i++) {
printf("x: %d, z: %d\n", initX, initY);
initX += dx;
initY += dy;
stepsDone++;
if (stepsDone >= length) {
stepsDone = 0;
if (dx == 0) {
dx = -dy;
dy = 0;
length++;
}
else {
dy = dx;
dx = 0;
}
}
}
}
Rules:
- Spiral should always turn left
- You cannot build from 0,0 every time and "ignore" previous blocks
- Sice
stepsvariable can be up to 2^32-1 cannot use lookup table
Here is an example on how it should work: Starting at (0,0):
Starting at (0,1):


At init you can use some statement to know where you are in the spiral :
After you can use that knowledge to step in the spiral.