老師讓我用c語言畫一個(gè)小球平拋軌跡圖#include <winbgim.h>#include <conio2.h>#include <math.h>#include <time.h>#define PI 3.1415926int main(){time_t now;int x,y;initwindow(1000,700); //open a 640x480 graphics windowsetcolor(WHITE); circle(100,50,10); //Draw a circlefloodfill(100,50,WHITE);//在圓內(nèi)填充白色; bar(0,60,100,65);//上面板 bar(100,565,850,570);//下面板setcolor(WHITE);now=time(NULL); setwritemode(1);while(now==1000){x=100+100*now;y=50+(1/2)*10*now*now;setcolor(WHITE);cricle(x,y,10);delay(1000/24);cricle(x,y,10); }getch(); //wait for user to press a keyclosegraph(); //close graphics windowreturn 0;}
1 回答

蠱毒傳說
TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
circle函數(shù)是TURBO C提供的圖形接口,用來畫圓。不屬于標(biāo)準(zhǔn)庫函數(shù),不具備可移植性。
函數(shù)名:circle
功 能: 在給定半徑以(x, y)為圓心畫圓
用 法:void far circle(int x, int y, int radius)
隨時(shí)間變化,可以用cleardevice函數(shù)清除屏幕,不斷畫半徑不同的圓??雌饋砭拖袷且粋€(gè)隨時(shí)間變化的圓形。
函數(shù)名: cleardevice
功 能: 清除圖形屏幕
用 法: void far cleardevice(void);
例程:
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main( void ) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int midx, midy; int radius = 100; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "" ); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf ( "Graphics error: %s\n" , grapherrormsg(errorcode)); printf ( "Press any key to halt:" ); getch(); exit (1); /* terminate with an error code */ } midx = getmaxx() / 2; midy = getmaxy() / 2; setcolor(getmaxcolor()); for (i=0;i<1000000;i++) if (i%50000==0){ cleardevice(); /* clean the screen */ circle(midx, midy, radius--); /* draw the circle */ } getch(); closegraph(); return 0; } |
- 1 回答
- 0 關(guān)注
- 203 瀏覽
添加回答
舉報(bào)
0/150
提交
取消