1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include "algorithm.h"
#include <math.h>
int xStart; // the variable that represent the starting x-position
int xStop; // the variable that represents the finishing x-position
float xLength = 900; // the length of the "mother-line"
int a = 6; // the "input-variale" that tells the program how many rows shall be built
int yPos; // the y variable, that is a multiplier of the "mother-loop-variable"
int denominator; // the denominator that will be used to divide the x-coordinate in the inner-loop
void algorithm()
{
for (int y = 1; y <= a ; y++)
{
denominator = pow((float)(3),(y-1)); //for y = 1, denominator is 1, next time 3, 9, 27...
for (int i = 0; i < 2 * (pow ((double)(2),(y - 1))) ; i++) // i mindre än antal punkter på linjen
{
if (i == 0)
{
xStart = 0;
xStop = xLength/denominator;
yPos = y * 10; //this is just to make the y-distance 10 times bigger
point p1 = {xStart,yPos}; //the yPos is constant in both points
point p2 = {xStop,yPos};
drawLine(p1,p2); //Draws a line between p1 and p2
}
else
{
xStart = i / denominator;
xStop = xStart + (xLength / denominator);
yPos = y * 10;
point p1 = {xStart,yPos};
point p2 = {xStop,yPos};
drawLine(p1,p2);
}
}
}
}
|