/* Star */
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#define VIDEO_INT 0x10
#define MAX 100
typedef unsigned char BYTE;
BYTE far *video = (BYTE far*)MK_FP(0xA000, 0); //gan dia chi thuc cua man hinh cho con tro video .
struct tagstar { //ta can khai bao con tro far do ta can tro den vung nho cua man
int status; //hinh ( da thay doi dia chi segment ) .
int row, col; //dia chi man hinh o mode 0x13 co dia chi segment la A000:0
int tanggiam;
int color;
} STAR[MAX]; //khai bao 1 mang STAR
void setmode(int mode) //ham setmode cho man hinh . su dung cu phap assembly , o day ta su dung ngat 0x10
{ //la ngat quan ly man hinh may tinh
asm {
mov ax, mode
int VIDEO_INT
}
}
void setpixel(int row, int col, BYTE color) //ham nay dung de to mau pixel tai vi tri row , col
{
video[row*320+col] = color;
}
void draw(struct tagstar s, BYTE color) //ham nay dung de ve mot ngoi sao
{
int i, j;
switch (s.status) //mot ngoi sao co the co 7 trang thai hien hinh , ta can lua chon
{
case 0 : for (i=-3; i<=3; i++)
{
setpixel(s.row + i, s.col + i, color);
setpixel(s.row + i, s.col - i, color);
setpixel(s.row, s.col + i, color);
setpixel(s.row + i, s.col, color);
}
break;
case 1 : for (i=-2; i<=2; i++)
{
setpixel(s.row + i, s.col + i, color);
setpixel(s.row + i, s.col - i, color);
setpixel(s.row, s.col + i, color);
setpixel(s.row + i, s.col, color);
}
break;
case 2 : for (i=-2; i<=2; i++)
{
setpixel(s.row, s.col + i, color);
setpixel(s.row + i, s.col, color);
}
for (i=-1; i<=1; i++)
{ setpixel(s.row + i, s.col + i, color);
setpixel(s.row + i, s.col - i, color);
}
case 3 : for (i=-2; i<=2; i++)
{
setpixel(s.row, s.col + i, color);
setpixel(s.row + i, s.col, color);
}
case 4 : for (i=-1; i<=1; i++)
{
setpixel(s.row, s.col + i, color);
setpixel(s.row + i, s.col, color);
}
break;
case 5 : setpixel(s.row, s.col, color);
break;
case 6 : setpixel(s.row, s.col, 8);
break;
case 7 : setpixel(s.row, s.col, 7);
break;
}
}
void star() //ham nay dung de ve 1 bau troi day sao
{
int i;
do {
for (i=0; i<MAX; i++)
draw(STAR[i], STAR[i].color);
delay(100);
for (i=0; i<MAX; i++)
{
draw(STAR[i], 0);
if (STAR[i].tanggiam)
{
if (STAR[i].status < 7)
STAR[i].status++;
else
STAR[i].tanggiam = 0;
}
else
{
if (STAR[i].status > 0)
STAR[i].status--;
else
STAR[i].tanggiam = 1;
}
}
} while (!kbhit());
}
void main()
{
int i;
randomize();
for (i=0; i<MAX; i++)
{
STAR[i].status = random(8);
STAR[i].row = random(200);
STAR[i].col = random(320);
STAR[i].tanggiam = random(2);
STAR[i].color = random(255)+1;
}
setmode(0x13);
star();
getch();
setmode(3); //tro ve man hinh van ban
}