Thứ Tư, 17 tháng 12, 2014

vẽ hình vành khăn trên code block


#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
struct Diem
{
    int x;
    int y;
};
Diem tddt(Diem tam, int R, int g)
{
    Diem kq;
    kq.x=tam.x + R *cos(g*3.141516/360);
    kq.y=tam.y + R *sin(g*3.141516/360);
    return kq;
}
void vehinhvanhkhan(Diem tam,int R, int gbd, int m)
{
    setcolor(m);
    for(int i=1;i<=5;i++)
    {
        Diem d1= tddt(tam, R, gbd+i*144);
        Diem d2= tddt(tam, R, gbd+(i+1)*144);
        line(d1.x,d1.y,d2.x,d2.y);
    }
}
int main()
{
    initwindow(800,600);
    Diem tam;
    tam.x=400;
    tam.y=300;
    int R=200;
    int gbd=270;
    int m=144;
    while(1)
    {
        vehinhvanhkhan()(tam,R,gbd,m);
        gbd=gbd+5;
        m=m+1;
        if(m>15)
        m=1;
        delay(100);
    }
    getch();
    return 0;
}

Không có nhận xét nào: