the galaxy?
==================================
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
float ix1,iy1,ix2,iy2,xy,t;
int i,j;
static int tick=0;
typedef struct{
float x;
float y;
} object;
typedef struct{
float r;
float g;
float b;
} color;
void setcolor(color col)
{
glColor3f(col.r, col.g, col.b);
}
void setcolor(float r,float g,float b)
{
glColor3f(r,g,b);
}
void update(int value)
{
t=3.14/180;
if(xy<360)
{
xy++;
}
else xy=0;
ix1=320+100*cos(xy*t);
iy1=240+100*sin(xy*t);
ix2=ix1+25*cos(-xy*t);
iy2=iy1+25*sin(-xy*t);
glutPostRedisplay();
glutTimerFunc(50,update,0);
}
void circle(float r,float x,float y,color col){
glBegin(GL_POLYGON);
setcolor(col);
t=3.14/180;
object obj[360];
for(i=0;i<360;i++)
{
obj[i].x=x+r*cos(i*t);
obj[i].y=y+r*sin(i*t);
glVertex2f(obj[i].x,obj[i].y);
}
glEnd();
}
void drawdot(int x,int y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void write(float x, float y, float z, void *font, char *string)
{
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(font, *c);
}
}
void title()
{
glColor3f(1,1,1);
write(20, 440, 0, GLUT_BITMAP_HELVETICA_12 , "Muhammad Ridwan");
write(20, 420, 0, GLUT_BITMAP_HELVETICA_12 , "7609040003") ;
}
color sun={0.9,0.4,0};
color earth={0,0,1};
color moon={0.5,0.5,0.5};
void star()
{
static object star[20];
glPointSize(1);
setcolor(1,1,1);
for(i=0;i<20;i++)
{
drawdot(star[i].x,star[i].y);
}
if(tick==0)
{
for(i=0;i<20;i++)
{
star[i].x=rand()%640;
star[i].y=rand()%480;
}
}
tick++;
j=rand()%10;
glPointSize(2);
drawdot(star[j].x,star[j].y);
}
void userdraw()
{
circle(30,320,240,sun);
circle(15,ix1,iy1,earth);
circle(5,ix2,iy2,moon);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
star();
title();
userdraw();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(640,480);
glutCreateWindow("7609040003");
glClearColor(0,0,0,0);
gluOrtho2D(0.,640.,0.,480.);
glutTimerFunc(50,update,0);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
thanks..
No comments:
Post a Comment