int main(void) { printf("Ë®ÏÉ»¨ÊýÊÇ£º\n"); Flower(); getch(); return 0; }
// Constructor for the Rose derived class. // Sets up the Flower, reads in the image, and sets the original color of the Rose // Returns: Nothing // Parameters: None Rose::Rose() { Flower(); flowerImage->ReadFromFile("rose.bmp"); originColor = getRoseOriginal(); }
Tree::Branch* Tree::branchFractal(GLfloat cur_angle, GLfloat prev_angle, Vertex2d initPoint, GLfloat height, unsigned char depth, Floor* floor, bool behindLog) { Vertex2d finalPoint = Vertex2d( initPoint.x + height * cosf(prev_angle + cur_angle + M_PI_2), initPoint.y + height * sinf(prev_angle + cur_angle + M_PI_2) ); // Crea un ramo vuoto, direzionato Tree::Branch* fractal = new Branch(); fractal->angle = cur_angle; // Scegli un numero di foglie e creale int foglie = (depth > 4) ? 0 : rand() % (depth + 20) + 1; for (int i=0; i<foglie; i++) { GLfloat perc = std::max(rand() % 100, rand() % 100) / 100.0; Vertex2d position( initPoint.x * (1 - perc) + finalPoint.x * perc, initPoint.y * (1 - perc) + finalPoint.y * perc ); Vertex2d fallPoint( position.x, (float) (((behindLog) ? rand() % (int)(floor->height / 4) + floor->height / 4: rand() % (int)floor->height / 2)) ); position.x += rand() % 20 - 10.0f; GLfloat size = 5.0f; GLfloat leaf_angle = (cur_angle + prev_angle) * 180 / M_PI + rand() % 90 - 45.0f; RGBColor color((rand() % 4) / 10.0f, 1.0f - (rand() % 3) / 10.0f, (rand() % 3) / 10.0f, 1); int age = rand() % 256; fractal->leaves.push_back(Leaf(position, fallPoint, size, leaf_angle, color, age, behindLog)); } // Scegli un numero di fiori e frutti e creali int flowers = (depth > 4) ? 0 : rand() % 4; for (int i=0; i<flowers; i++) { GLfloat perc = std::max(rand() % 100, rand() % 100) / 100.0; Vertex2d position( initPoint.x * (1 - perc) + finalPoint.x * perc, initPoint.y * (1 - perc) + finalPoint.y * perc ); Vertex2d fallPointFruit( position.x, (float) (rand() % (int)(floor->height / 2)) ); GLfloat size = rand() % 3 + 2; GLfloat sizeFruit = 8; RGBColor centerColor(0.96, 0.76, 0.1, 1); RGBColor petalColor(0.9, 0.1, 0.6, 1); RGBColor fruitColor(1 + ((rand()%10 - 5.0f) / 100.0f), 0.6f + ((rand()%10 - 5.0f) / 100.0f), 0, 1); int age = rand() % 256; fractal->flowers.push_back(Flower(position, size, centerColor, petalColor)); fractal->fruits.push_back(Fruit(position, fallPointFruit, sizeFruit, fruitColor, age)); } // Se non ci sono rami "figli" ho finito if (depth == 0) { return fractal; } // Scegli le direzioni per i figli e creali int angles[] = {0, 45, 315}; std::random_shuffle(angles, angles+3); int children = (depth > 2) ? 3 : rand() % 2 + 1; for (int i=0; i<children; i++) { GLfloat new_angle = (angles[i] + rand() % 20 - 10) / 180.0 * M_PI; fractal->child[i] = branchFractal(new_angle, cur_angle + prev_angle, finalPoint, height * 0.7, depth - 1, floor, behindLog); } return fractal; }
// Copy Constuctor for Rose. // Sets up a new Flower, then copies the Image, originalColor and newColor to the new carnation object // Returns: Nothing // Parameters: Rose& Rose::Rose(Rose & source) { Flower(); *flowerImage = *(source.flowerImage); originColor = getRoseOriginal(); setNewColor(source.getNewColor()); }