February 10, 2014

Polar Graphs - Part 6

Updated my code so you can specify an offset in the position.

In drawAngle method in main.cpp:
std::tuple<float, float> positions = valueOfOffsets(a);
float x = r * cos(angle) + std::get<0>(positions);
float y = r * sin(angle) + std::get<1>(positions);

Added this function declaration in Parser.h:
std::tuple<float, float> valueOfOffsets(char source[]);

And added this code in Parser.cpp, although it could use a little refactoring:
float GetDecimal(char source[], int i) {
float value = 0;
bool isNeg = source[i] == '-';

if (isNeg) i++;

while (source[i] >= '0' && source[i] <= '9') {
value *= 10;
value += (float)(source[i] - '0');
i++;
}

float trailing = 0.0;
int placeHolder = 10;
if (source[i] == '.') {
remove(source, 1);
while (source[i] >= '0' && source[i] <= '9') {
float digit = (float)(source[i] - '0') / placeHolder;
placeHolder *= 10;
trailing += digit;
i++;
}
}
return isNeg ? -1 * (value + trailing) : value + trailing;
}

float GetX(char source[], int i) {
while (source[i] != '\0' && source[i] != 'x') {
i++;
}
i += 2;

return GetDecimal(source, i);
}

float GetY(char source[], int i) {
while (source[i] != '\0' && source[i] != 'y') {
i++;
}
i += 2;

return GetDecimal(source, i);
}

std::tuple<float, float> valueOfOffsets(char source[]) {
int i = 0;
float x = GetX(source, i);
float y = GetY(source, i);

std::tuple<float, float> positions (x, y);
return positions;
}

So I'm getting to the main point of this project, I wanna start making images with polar coordinates because why not

Unfortunately I haven't made the ranges parameterizable so I can't draw eyebrows or smiley faces yet or anything

Here's Guy Whistling: