DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   please help, this is what i have done so far (http://www.daniweb.com/forums/thread158815.html)

bids Nov 21st, 2008 1:38 pm
please help, this is what i have done so far
 
 


#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
void serp(int level, int Ax, int Ay, int Bx, int By)
{
        int poly[4]={Ax,Ay,Bx,By};

        setfillstyle(SOLID_FILL,YELLOW);

        if (level>0)
        {

                serp(level-1, Ax,Ay ,(2*Ax+Bx)/3,(2*Ay+By)/3);
                serp(level-1,(2*Ax+Bx)/3,(2*Ay+By)/3,(Ax+Bx)/2+sqrt(3)*(Ay-By)/6,(Ay+By)/2+sqrt(3)*(Bx-Ax)/6);
                serp(level-1,(Ax+Bx)/2+sqrt(3)*(Ay-By)/6,(Ay+By)/2+sqrt(3)*(Bx-Ax)/6,(Ax+2*Bx)/3,(Ay+2*By)/3);
                serp(level-1,(Ax+2*Bx)/3,(Ay+2*By)/3,Bx,By);
        }
        else fillpoly(2,poly);
}

int main(void)
{
        int graphdriver=DETECT, graphmode;
        initgraph(&graphdriver, &graphmode, "");

        int i, N=8, Bx=0, By=235, Ax=635, Ay=235;

        for (i=0; i<N; i++)
        {

        serp(0,Ax,Ay,Bx,By);

        serp(1,Ax,Ay,Bx,By);
        serp(2,Ax,Ay,Bx,By);
        serp(3,Ax,Ay,Bx,By);
        serp(4,Ax,Ay,Bx,By);
        serp(5,Ax,Ay,Bx,By);
        serp(6,Ax,Ay,Bx,By);
        serp(7,Ax,Ay,Bx,By);

        delay(1000);
        cleardevice();
        }

        getch();
        closegraph();
        return 0;
}

what i could like to know is how do i fill each object with different colours?

cikara21 Nov 22nd, 2008 3:56 am
Re: please help, this is what i have done so far
 
I don't test it yet :)..Try it..
setfillstyle(SOLID_FILL,level);
// or
fillpoly(level,poly);

bids Nov 22nd, 2008 5:30 am
Re: please help, this is what i have done so far
 
thanks for your help


All times are GMT -4. The time now is 8:33 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC