/** * int main() * * Descricao: * Funcao principal do programa que contem um loop (do-while) contendo a chamada * das funcoes que calculam as variaveis utilizadas pelo algoritmo Gauss-Legendre * a cada iteracao. * * Parametros de entrada: * - * * Parametros de retorno: * - * */ int main(){ /* Variaveis utilizadas para calcular o tempo de execucao do programa */ time_t begin, end; double time_spent; time(&begin); /* Inicialicazao das variaveis globais utilizadas no algoritmo */ initAttributes(); /* Loop principal que calcula o valor do "pi" */ do{ //printf("Iteracao: %ld\n", n_count); calculate_a(); calculate_b(); calculate_t(); calculate_p(); calculate_pi(); filePrint(); n_count++; } while(mpf_cmp(pi[n_count-2], pi[n_count-1])!=0); /* Condicao de parada: o "pi" recem calculado deve ser igual ao seu antecessor, garantindo assim a sua convergencia com 10 milhoes de casas decimais */ time(&end); time_spent = difftime(end, begin); printf("Tempo de execucao: %lf segundos\nIteracoes: %ld\n", time_spent, n_count); return 0; }
// Given the coordinates of two endpoints, finds the y = mx + b equation for the // line and draws dots for every pixel in the relatively less constrained // dimmension void draw_line(unsigned char pixelArray[PIXEL_DIMMENSION][PIXEL_DIMMENSION], double brushRadius, int startY, int startX, int endY, int endX) { double slope = (double)(endY - startY) / (endX - startX); double b = calculate_b(startX, startY, slope); // if abs(slope) is less than 1, do operations on x, more than 1, y // if start of point is less that end, increment, otherwise decrement int i; if (abs(slope) < 1) { if (startX >= endX) { for (i = startX; i >= endX; --i) { double y = calculate_other_coordinate('y', i, slope, b); if (startY == endY) { double y = startY; } draw_circle(pixelArray, PIXEL_DIMMENSION - i, round(y), brushRadius); } } else { for (i = startX; i <= endX; ++i) { double y = calculate_other_coordinate('y', i, slope, b); if (startY == endY) { double y = startY; } draw_circle(pixelArray, PIXEL_DIMMENSION - i, round(y), brushRadius); } } } else { if (startY >= endY) { for (i = startY; i >= endY; --i) { double x; if (startX == endX) { x = startX; } else { x = calculate_other_coordinate('x', i, slope, b); } draw_circle(pixelArray, PIXEL_DIMMENSION - round(x), i, brushRadius); } } else { for (i = startY; i <= endY; ++i) { double x; if (startX == endX) { x = startX; } else { x = calculate_other_coordinate('x', i, slope, b); } draw_circle(pixelArray, PIXEL_DIMMENSION - round(x), i, brushRadius); } } } }
int share_secret(int k, int n, simple_8bits_BMP_t * secret, simple_8bits_BMP_t ** shadows) { int i =0; int j = 0; int status = 0; img_with_state_t *sec; unsigned char ** bytes = my_malloc(n * sizeof(char*)); unsigned char b = 0x00; if(k > n) { return ERROR; } img_with_state_t ** shads = my_malloc(sizeof(img_with_state_t*) * n); sec = new_one_step_in_img(secret, k); for(i =0 ; i < n ; ++i) { shads[i] = new_one_step_in_img(shadows[i], k); } for(i = 0 ; i < (secret->dib_header->height * secret->dib_header->width / k) + 1 ; ++i) { status = one_step_in_img(sec); status = one_step_in_imgs(shads, n); for(j = 0; j < n ; ++j) { bytes[j] = shads[j]->current_bytes; get_k_coefficients_no_cero(bytes[j], k, bytes[j]); } check_coefficients(bytes, k, n); make_linear_independent(bytes, k, n); for(j = 0; j< n ; ++j) { b = calculate_b(bytes[j], sec->current_bytes, k); save_b_to_coefficients(b, k,bytes[j]); } } my_free(bytes); return OK; }