Learn how to use C++ code to create basic animated graphics in this chapter from Beginning Game Programming by Michael Morrison. Caterpillar et factory passwords change keygen generator golf. This chapter is from the book A computer game consists of many different pieces, all of which must come together to form a unique entertainment experience for the. C Graphics programming is very easy and interesting. You can use graphics programming for developing your games, in making projects, for animation etc. It's not like traditional C programming in which you have to apply complex logic in your program and then you end up with a. Yggdra unison ds english patch.
#include <stdio.h>
#include <conio.h> #include <graphics.h> #include <dos.h> #include <math.h> /* manipulates the position of planets on the orbit */ void planetMotion(int xrad, int yrad, int midx, int midy, int x[60], int y[60]) { int i, j = 0; /* positions of planets in their corresponding orbits */ for (i = 360; i > 0; i = i - 6) { x[j] = midx - (xrad * cos((i * 3.14) / 180)); y[j++] = midy - (yrad * sin((i * 3.14) / 180)); } return; } int main() { /* request auto detection */ int gdriver = DETECT, gmode, err; int i = 0, midx, midy; int xrad[9], yrad[9], x[9][60], y[9][60]; int pos[9], planet[9], tmp; /* initialize graphic mode */ initgraph(&gdriver, &gmode, 'C:/TURBOC3/BGI'); err = graphresult(); if (err != grOk) { /* error occurred */ printf('Graphics Error: %s', grapherrormsg(err)); return 0; }
midx = getmaxx() / 2;
planet[0] = 7;
planet[i] = planet[i - 1] + 1;
/* offset position for the planets on their corresponding orbit */
pos[i] = i * 6;
xrad[0] = 60, yrad[0] = 30;
xrad[i] = xrad[i - 1] + 30;
}
/* positions of planets on their corresponding orbits */
planetMotion(xrad[i], yrad[i], midx, midy, x[i], y[i]);
Programs In Computer Graphics Using Computers
/* drawing 9 orbits */
for (i = 0; i < 9; i++) {
}
setcolor(YELLOW);
circle(midx, midy, 20);
setcolor(CYAN);
pieslice(x[0][pos[0]], y[0][pos[0]], 0, 360, planet[0]);
setcolor(GREEN);
pieslice(x[1][pos[1]], y[1][pos[1]], 0, 360, planet[1]);
/* earth in third orbit */
setfillstyle(SOLID_FILL, BLUE);
pieslice(x[2][pos[2]], y[2][pos[2]], 0, 360, planet[2]);
/* mars in fourth orbit */
setfillstyle(SOLID_FILL, RED);
pieslice(x[3][pos[3]], y[3][pos[3]], 0, 360, planet[3]);
/* jupiter in fifth orbit */
setfillstyle(SOLID_FILL, BROWN);
pieslice(x[4][pos[4]], y[4][pos[4]], 0, 360, planet[4]);
/* saturn in sixth orbit */
setfillstyle(SOLID_FILL, LIGHTGRAY);
pieslice(x[5][pos[5]], y[5][pos[5]], 0, 360, planet[5]);
setcolor(BROWN);
C++ Graphics Example
pieslice(x[6][pos[6]], y[6][pos[6]], 0, 360, planet[6]);
/* neptune in eigth orbit */
setfillstyle(SOLID_FILL, LIGHTBLUE);
pieslice(x[7][pos[7]], y[7][pos[7]], 0, 360, planet[7]);
/* pluto in ninth orbit */
setfillstyle(SOLID_FILL, LIGHTRED);
pieslice(x[8][pos[8]], y[8][pos[8]], 0, 360, planet[8]);
/* checking for one complete rotation */
if (pos[i] <= 0) {
} else {
}
delay(100);
/* clears graphic screen */
}
/* deallocate memory allocated for graphic screen */
return 0;
Output: (Solar system animation using C graphics)
« PreviousNext »
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |