Ejemplo n.º 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);
}
Ejemplo n.º 2
0
void
FallLeaves::Draw(BView* view, int32 frame)
{
	if (fBackBitmap->Lock()) {
		
		// Clear the offscreen buffer
		fBackView->FillRect(fBackView->Bounds());
		
		// Update and draw the leaves
		for (int32 i = fLeaves->CountItems() - 1; ; i--) {
			Leaf* leaf = fLeaves->ItemAt(i);
			if (leaf == NULL)
				break;
			leaf->Update(TICKS_PER_SECOND);
			leaf->Draw(fBackView);
			
			// If the leaf is dead, remove it
			if (leaf->IsDead()) {
				fZUsed[leaf->Z()] = false;
				fLeaves->RemoveItem(leaf);
				delete leaf;
			}
		}
		
		fBackBitmap->Unlock();
	}
	
	bool sort = false;
	
	// Add some new leaves if necessary
	// to replace any dead ones
	while (fLeaves->CountItems() < fAmount) {
		fLeaves->AddItem(_CreateLeaf(view, false));
		sort = true;
	}
	
	// Keep the leaves sorted by Z axis
	if (sort)
		fLeaves->SortItems(cmpz);
	
	view->DrawBitmap(fBackBitmap);
}