刚工作没多久的时候,业余学习了OGL的知识(这是写不好的借口吧),

在某个异性生日的时候写了这个程序。

编译平台: MinGW GCC

gcc -o happOK happyOK.c -lglut32 -lglu32 -lopengl32

效果图(不太会转gif,好粗糙……):

代码、exe、glut32.dll opengl32.dll打包

http://files.cnblogs.com/paktc/HappyBirthday%E5%B0%8F%E6%95%88%E6%9E%9C.rar

代码:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h> #define winwidth 500
#define winheight 500
#define ww winwidth/2
#define wh winheight/2
#define nbox 150
#define SLP 300 int winid;
float anga=0.0;
float boxsize=12.0;
static struct {
float x,y,z;
float xmax,ymax,zmax;
float xadd,yadd,zadd;
float delta;
} ang={,,, ,,, ,,, 0.5}; static struct {
float x,xnext,xadd;
float y,ynext,yadd;
float z,znext,zadd;
float ang,angnext;
} box[nbox]; int arr[]={,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,
,,,,};
int brr[]={,,,,,,,,,,,,,,,,
,,,,,,,,,,};
int crr[]={,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,};
int drr[]={,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,};
int err[]={,,,,,,,,,,,,,}; void drawbox(float px,float py,float pz,float ang) {
glPushMatrix();
glTranslatef(px,py,pz);
glRotatef(ang,1.0,0.0,0.0);
glColor3f(px/winwidth,py/winwidth,0.5);
glBegin(GL_POLYGON);
glVertex3f(-boxsize,-boxsize,0.0);
glVertex3f(-boxsize,boxsize,0.0);
glVertex3f(boxsize,boxsize,0.0);
glVertex3f(boxsize,-boxsize,0.0);
glEnd();
/*
glBegin(GL_POLYGON);
glVertex3f(px-boxsize,py-boxsize,0.0);
glVertex3f(px-boxsize,py+boxsize,0.0);
glVertex3f(px+boxsize,py+boxsize,0.0);
glVertex3f(px+boxsize,py-boxsize,0.0);
glEnd();
*/
glPopMatrix();
} void display(void) {
int i;
glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glPolygonMode(GL_BACK,GL_LINE);
//glRotatef(0.05,1.0,1.0,0.0); if (ang.ymax>0.0) {glRotatef(ang.delta,1.0,0.0,0.0);ang.ymax-=ang.delta;}
if (ang.xmax>0.0) {glRotatef(ang.delta,0.0,1.0,0.0);ang.xmax-=ang.delta;}
glPushMatrix(); glTranslatef(-125.0,-200.0,0.0); for (i=;i<;i++) {
if (box[i].ang<box[i].angnext) {box[i].ang+=2.0;}
if (box[i].z<box[i].znext) {box[i].z+=box[i].zadd;}
if (box[i].z>box[i].znext) {box[i].z+=box[i].zadd;}
drawbox(box[i].x,box[i].y,box[i].z,box[i].ang);
}
glPopMatrix();
glutSwapBuffers();
} void empty(void) {
static int here=;
int steper(int level);
int steper1(int level);
int steper2(int level);
int steper3(int level);
int steper4(int level); if (here==) {here=steper();}
if (here==) {here=changeall();}
if (here==) {here=steper1();}
if (here==) {here=changeall();}
if (here==) {here=steper2();}
if (here==) {here=changeall();}
if (here==) {here=steper3();}
if (here==) {here=changeall();}
if (here==) {here=steper4();}
glutPostRedisplay();
} void sometest(int whoi) {
float i,tempx;
tempx=box[whoi].ang;
for (i=tempx;i<=tempx+;i+=0.4) {
box[whoi].ang=i;
display();
}
} void mouse(int button,int state,int mousex,int mousey) {
printf("button=%d state=%d mousex=%d mousey=%d\n",
button,state,mousex,mousey);
int whoi;
if (button==) {
if (state==) {
whoi=who(mousex,winheight-mousey);
if (whoi != -) {
printf("ang=%f\n",box[whoi].ang);
sometest(whoi);
// beep -> system("nircmd beep 2340" " 300");
}
}
}
} void reshape(int x,int y) {
printf("%d %d\n",x,y);
glViewport(,,x,y);
/* GLint startx, GLint starty, GLsizei width, GLsizei height */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0.0,500.0, 0.0,500.0, 100.0,200.0);
gluPerspective(80.0,1.0,,);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,300.0, 0.0,0.0,0.0, 0.0,1.0,300.0);
} void hitkey(unsigned char key,int mousex,int mousey) {
switch (key) {
case 'q':
glutDestroyWindow(winid);
exit();
break;
case 'a':
ang.yadd=ang.delta;
ang.ymax=90.0;
glutPostRedisplay();
break;
case 'd':
ang.yadd=-ang.delta;
ang.ymax=90.0;
glutPostRedisplay();
break;
case 'w':
ang.xadd=ang.delta;
ang.xmax=90.0;
glutPostRedisplay();
break;
case 's':
ang.xadd=-ang.delta;
ang.xmax=90.0;
glutPostRedisplay();
break;
}
} void init(void) {
int i;
srand(time(NULL));
for (i=;i<nbox;i++) {
box[i].x=(int)(i/)*30.0+10.0;
box[i].y=(i%)*30.0+10.0;
box[i].z=0.0;
box[i].ang=180.0;
printf("%f %f %f\n",box[i].x,box[i].y,box[i].ang);
}
} int main(int argc,char *argv[]) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowPosition(,);
glutInitWindowSize(,);
winid=glutCreateWindow("test");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(hitkey);
glutMouseFunc(mouse);
glutIdleFunc(empty);
glutMainLoop();
return ;
} /*===================================================*/
int who(int x,int y) {
int i,result=-;
float left,right;
float up,down;
for (i=;i<nbox;i++) {
left=box[i].x-boxsize;
right=box[i].x+boxsize;
up=box[i].y+boxsize;
down=box[i].y-boxsize;
if (left<x && x<right) {
if (down<y && y<up) {
result=i;
}
}
}
return result;
} /*=====================================================*/
int steper(int level) {
static int i;
static float j;
int fo,no=;
usleep(SLP);
if (i==) {ang.xmax=ang.x+20.0;}
j+=0.5;
if (j==1.0) {
j=0.0;
for (fo=;fo<;fo++) {
if (arr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].ang+180.0;}
i++;
}
if (i==nbox) {i=;return level+;} else {return level;}
} int steper1(int level) {
static int i;
static float j;
int fo,no=;
usleep(SLP);
if (i==) {
ang.xmax=180.0;
}
j+=0.5;
if (j==1.0) {
j=0.0;
for (fo=;fo<;fo++) {
if (arr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].ang+180.0;}
no=;
for (fo=;fo<;fo++) {
if (brr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].angnext+180.0;}
box[i].znext=box[i].z+80.0;
box[i].zadd=1.0;
i++;
}
if (i==nbox) {i=;return level+;} else {return level;}
} int steper2(int level) {
static int i;
static float j;
int fo,no=;
usleep(SLP);
if (i==) {
ang.xmax=150.0;
}
j+=0.5;
if (j==1.0) {
j=0.0;
for (fo=;fo<;fo++) {
if (brr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].ang+180.0;}
no=;
for (fo=;fo<;fo++) {
if (crr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].angnext+180.0;}
box[i].znext=box[i].z-80.0;
box[i].zadd=-1.0;
i++;
}
if (i==nbox) {i=;return level+;} else {return level;}
} int steper3(int level) {
static int i;
static float j;
int fo,no=;
usleep(SLP);
if (i==) {
ang.xmax=30.0;
}
j+=0.5;
if (j==1.0) {
j=0.0;
for (fo=;fo<;fo++) {
if (crr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].ang+180.0;}
no=;
for (fo=;fo<;fo++) {
if (drr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].angnext+180.0;}
i++;
}
if (i==nbox) {i=;return level+;} else {return level;}
} int steper4(int level) {
static int i;
static float j;
int fo,no=;
usleep(SLP);
j+=0.5;
if (j==1.0) {
j=0.0;
for (fo=;fo<;fo++) {
if (drr[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].ang+180.0;}
no=;
for (fo=;fo<;fo++) {
if (err[fo] == i) {no=;}
}
if (no==) {box[i].angnext=box[i].angnext+180.0;}
if (no==) {box[i].z=1000.0;}
i++;
}
if (i==nbox) {i=;return level+;} else {return level;}
} int changeall(int level) {
static int i;
usleep(SLP);
box[i].angnext=box[i].ang+180.0;
i++;
if (i==nbox) {i=;return level+;} else {return level;}
}

[OpenGL]点阵显示生日快乐小程序的更多相关文章

  1. 微信小程序基础入门

    准备 Demo 项目地址 https://github.com/zce/weapp-demo Clone or Download(需准备GIT环境) $ cd path/to/project/root ...

  2. 微信小程序之生命周期(三)

    [未经作者本人同意,请勿以任何形式转载] 上一篇介绍微信小程序开发工具使用和项目目录结构. 这一章节介绍微信小程序的生命周期,什么是生命周期呢? 通俗的讲,生命周期就是指一个对象的生老病死. 从软件的 ...

  3. 微信小程序学习

    官方网站 https://mp.weixin.qq.com/debug/wxadoc/dev/index.html 项目结构介绍 -- MINA框架 https://mp.weixin.qq.com/ ...

  4. 微信小程序教程(第四篇)

    小程序开发基本框架及其限制与优化 开发基本框架(MINA框架) └─ Project-folder/ ·································· 项目所在目录 ├─ page ...

  5. 微信小程序,前端大梦想(三)

    微信小程序的事件及生命周期   继续下节课,今天我们还是从四个方面来了解小程序:     ●常用事件和事件冒泡   ●配置   ●app生命周期及app对象的使用   ●页面的生命周期   一.事件的 ...

  6. 微信小程序--图片相关问题合辑

    图片上传相关文章 微信小程序多张图片上传功能 微信小程序开发(二)图片上传 微信小程序上传一或多张图片 微信小程序实现选择图片九宫格带预览 ETL:微信小程序之图片上传 微信小程序wx.preview ...

  7. 小程序web-view组件

    不久前微信小程序发布了web-view组件,这个消息在各个圈里引起不小的涟漪.近期正好在做小程序的项目,便研究了一下这个让大家充满期待的组件.   1,web-view这个组件是什么鬼? 官网的介绍: ...

  8. 微信小程序开发之详解生命周期方法

    生命周期是指一个小程序从创建到销毁的一系列过程 在小程序中 ,通过App()来注册一个小程序 ,通过Page()来注册一个页面 先来看一张小程序项目结构 从上图可以看出,根目录下面有包含了app.js ...

  9. 微信小程序个人心得

    尊重原创:http://blog.csdn.net/qq_28832135/article/details/52796048 昨天看了一下微信小程序官方文档,总结一下自己学习的个人心得. 首先从官方文 ...

随机推荐

  1. bzoj 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头——枚举倍数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1607 #include<iostream> #include<cstdio ...

  2. Python 函数之lambda、map、filter和reduce

    1.lambda函数 lambda()是Python里的匿名函数,其语法如下: lambda [arg1[, arg2, ... argN]]: expression 学习条件运算时,对于简单的 if ...

  3. Spark on yarn的两种模式 yarn-cluster 和 yarn-client

    从深层次的含义讲,yarn-cluster和yarn-client模式的区别其实就是Application Master进程的区别,yarn-cluster模式下,driver运行在AM(Applic ...

  4. [IIS] 不能加载类型System.ServiceModel.Activation.HttpModule

    Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, ...

  5. 机器学习:PCA(使用梯度上升法求解数据主成分 Ⅰ )

    一.目标函数的梯度求解公式 PCA 降维的具体实现,转变为: 方案:梯度上升法优化效用函数,找到其最大值时对应的主成分 w : 效用函数中,向量 w 是变量: 在最终要求取降维后的数据集时,w 是参数 ...

  6. Spring学习八

    1: Tomcat容器四个等级? Container, Engine,  Servlet容器, Context 真正管理Servlet的容器是Context容器:一个context对应一个web工程. ...

  7. 一张图看懂------left join;right join;inner join

  8. 智能提示框---bai

    input.jsp <%@ page language="java" import="java.util.*" pageEncoding="UT ...

  9. 2015.3.12Arinc424 Tools中SiniArincCls.csParserFile(string sFile)函数正则表达式理解

    原文: string RegEx1 = @"(\[ITEM\]\s*=[\S\s]*?(?=\[ITEM\])|\[ITEM\]\s*=[\S\s]*)";//用来识别主记录和后续 ...

  10. hibernate 单元测试

     单元测试 测试 dao service action package com.kaishengit.test; import org.hibernate.Session; import com.ka ...