Exemple #1
0
void Tree::Divis(const Point* begin, const Point* end, const int& color)
{
    double* dl = new double(begin->Range(end));
    if(*dl < kleafrate*size/33.3)
    {
        delete dl;
        return;
    }

    Point middle;

    double* rnd = new double(RND());

    if(begin->GetX() == end->GetX() || begin->GetY() == end->GetY())
    {
        int krnd = (*rnd <= 0.5) ? 1 : -1;

        if(begin->GetX() == end->GetX())
            middle.SetXY(begin->GetX() + ((begin->GetX() + krnd * *dl/2 > 0.0) ?
                                          krnd : -krnd) * *dl/2, min(begin->GetY(), end->GetY()) + *dl/2);

        if(begin->GetY() == end->GetY())
            middle.SetXY(min(begin->GetX(), end->GetX()) + *dl/2,
                         begin->GetY() + ((begin->GetY() + krnd * *dl/2 > 0.0) ?
                                          krnd : -krnd) * *dl/2);
    }
    else if(*rnd <= 0.5) middle.SetXY(begin->GetX(), end->GetY());
    else middle.SetXY(end->GetX(), begin->GetY());

    delete dl;

    double *chance = new double(center.Range(&sun)/middle.Range(&sun));

    if(sflowers != 0 && *rnd < 0.025 * *chance)
    {
        f = middle;
        f.Draw(color);
    }
    else
    {
        l = middle;
        if(*rnd < Fi / *chance / 0.8) l.Draw(color3);
        else l.Draw(color4);
    }

    delete chance;
    delete rnd;

    Divis(begin, &middle, color);
    Divis(&middle, end, color);
}
Exemple #2
0
void Tree::Stvol(const Point* begin, const Point* end, const int& color)
{
    if(begin->Range(end) < size/6.2) // !!!
    {
        Divis(begin, end, color);
        setcolor(color);
        return;
    }

    Point middle(begin, end, 1-Fi);

    Point* p1 = new Point(begin, begin->Range(end)/55, begin->AngleX(end)+M_PI_2);
    Point* p2 = new Point(begin, begin->Range(end)/55, begin->AngleX(end)-M_PI_2);

    if(middle.Range(&sun) > center.Range(&sun))
    {
        setcolor(color1);
        setfillstyle(1, color1);
    }
    else
    {
        setcolor(color2);
        setfillstyle(1, color2);
    }

    int* mass = new int[6];

    mass[0] = p1->GetX();
    mass[1] = p1->GetY();

    mass[2] = p2->GetX();
    mass[3] = p2->GetY();

    mass[4] = end->GetX();
    mass[5] = end->GetY();

    fillpoly(3, mass);

    delete[] mass;
    delete p2;
    delete p1;

    Stvol(&middle, end, color);

    int krnd = (RND() < 0.5) ? -1 : 1;

    // ranznos vetki 1
    double* temp1 = new double((begin->Range(end) < size/16) ?
                               0 : (1/Fi)*random(16*(int)(begin->Range(end)/size))/begin->Range(end));

    middle.Position(begin, end, 1 - Fi + krnd * *temp1);

    delete temp1;

    // zadanie vetki 1
    double angle = M_PI_2*(random(80)+10)/100 + M_PI_2;
    Point away(&middle, middle.Range(end), angle);

    Stvol(&middle, &away, color);

    // ranznos vetki 2
    double* temp2 = new double((begin->Range(end) < size/16) ?
                               0 : (1/Fi)*random(16*(int)(begin->Range(end)/size))/begin->Range(end));

    middle.Position(begin, end, 1 - Fi - krnd * *temp2);

    delete temp2;

    // zadanie vetki 1
    angle = M_PI_2*(random(80)+10)/100 - M_PI_2;
    away.Position(&middle, middle.Range(end), -angle);

    Stvol(&middle, &away, color);
}