PDA

View Full Version : سوال: توضیح متد



ms-ninja
سه شنبه 22 آذر 1390, 10:38 صبح
با سلام

استاد یک برنامه داده ازمون خواسته متد ها رو توضیح بدیم براش

مثلا کد های هر قطعه از برنامه چی کار میکنه

برنامه من ساعت آنلاوگه



#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <math.h>

#define _BGIPATH "c:\\mclock"
#define _PI 3.141596
#define _NUM_COLOR 1
#define _PNT_COLOR 8
#define _BK_COLOR 15

int center_x = 320 , center_y = 240;
int gdriver = VGA, gmode = VGAHI;

struct _hand {
int value;
int max;
int x,y,color,r;
int line_style, line_width;
};

struct _hand hour,minute,second;

void update_pos(struct _hand *hand, int brother_value,float sections){
double cur_value = (float) (*hand).value;
double max = (float) (*hand).max;
double por = cur_value / max;
double theta = por * 2 * _PI;

if (brother_value != -1 ) {
double b_por = (brother_value / 60.0);
double b_theta = ((b_por) * 2.0 * _PI) / sections;
theta += b_theta;
}

theta -= ( _PI/2 );
(*hand).x = (int) (center_x + ((*hand).r * cos(theta)));
(*hand).y = (int) (center_y + ((*hand).r * sin(theta)));
}

void update(){
struct time timep;
gettime(&timep);

hour.value = timep.ti_hour % 12;
minute.value = timep.ti_min;
second.value = timep.ti_sec;

update_pos(&hour,minute.value,12.0);
update_pos(&minute,second.value,60.0);
update_pos(&second,-1,0.0);

}

void init(){
int errorcode;
initgraph(&gdriver, &gmode, _BGIPATH);
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit;
}

hour.max = 12;
hour.r = 100;
hour.color = 7;
hour.line_style = 0;
hour.line_width = 3;
hour.value = -1;

minute.max = 60;
minute.r = 170;
minute.color = 7;
minute.line_style = 0;
minute.line_width = 1;
minute.value = -1;

second.max = 60;
second.r = 180;
second.color = 4;
second.line_style = 0;
second.line_width = 1;
second.value = -1;

}

void draw_frame() {
int deg, val = 1 , rx, ry;
double theta;
char* nums[] = {"0","1","2","3","4","5","6","7","8","9","10","11","12"};

setbkcolor(_BK_COLOR);
cleardevice();
setcolor(_PNT_COLOR);

for (deg = 6; deg <= 360; deg+=6) {
theta = (deg/ 180.0) * _PI;
rx = (int) (center_x + ( 210 * cos(theta)));
ry = (int) (center_y + ( 210 * sin(theta)));
if (deg % 30 != 0 ) {
circle(rx,ry,1);
}
}

settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(_NUM_COLOR);

for (deg = 30; deg <= 360; deg+=30) {
theta = ((deg-90.) / 180.0) * _PI;
rx = (int) (center_x + ( 213 * cos(theta)));
ry = (int) (center_y + ( 213 * sin(theta)));
if (val % 3 == 0) {
settextstyle(GOTHIC_FONT, HORIZ_DIR, 4);
} else {
settextstyle(SIMPLEX_FONT, HORIZ_DIR, 1);
}
outtextxy(rx,ry, nums[val]);
val++;
}
}

void draw_hand(struct _hand *hand, int c) {
if (c == 0) {
setcolor((*hand).color);
} else {
setcolor(_BK_COLOR);
}
setlinestyle((*hand).line_style,0,(*hand).line_wid th);
line(center_x,center_y, (*hand).x, (*hand).y);
}


void main(void)
{
init();
draw_frame();
while (!kbhit()){
update();

draw_hand(&hour,0);
draw_hand(&minute,0);
draw_hand(&second,0);
delay(100);

draw_hand(&hour,1);
draw_hand(&minute,1);
draw_hand(&second,1);

}

getch();

}

ms-ninja
سه شنبه 22 آذر 1390, 16:42 عصر
کسی اینجا نیست جواب ما رو بده؟