William's profileWilliamBlogListsGuestbookMore Tools Help

William

William

Occupation
Location
Interests
just a college student
No list items have been added yet.
March 05

Sierpinski gasket

I am learning computer graphics through reading <Computer Graphics Using OpenGL Second Edition>.

And I generated the Sierpinski gasket using OpenGL and VC++ 2005. There is the result:

sierpinski

There is the source code which can be compiled in visual studio 2005:

// Draw sierpinski gasket
//P49 in <Computer Graphics Using OpenGL>

#include "GLintPoint.h"
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

// Create a number between 0 and m(a number which will be given)
// the input m must be less than 32767 according to P49 in <Computer Graphics Using OpenGL>
int random(int m)
{
    if(m<0||m>32767)
    {
        cout<<"There is something wrong in random."<<endl;
    }
    int rand();
    return rand()%m;
}

void drawDot (GLint x, GLint y)
{
    glBegin(GL_POINTS);
        glVertex2i(x,y);
    glEnd();
}

// Draw sierpinski gasket
void sierpinski()
{
    GLint random(GLint);
    glClear(GL_COLOR_BUFFER_BIT);       //clear the screen

    GLintPoint T[3]={{10,10},{300,30},{200,300}};
    int index=random(3);       //0,1 or 2 equally likely
    GLintPoint point = T[index]; // initial point
    drawDot(point.x,point.y);     //draw initial point

    drawDot(T[0].x,T[0].y);
    drawDot(T[1].x,T[1].y);
    drawDot(T[2].x,T[2].y);

    // Draw 10000 Dots
    for( int i=0;i<10000;i++)
    {
        index = random(3);
        point.x = (point.x+T[index].x)/2;
        point.y = (point.y+T[index].y)/2;
        drawDot(point.x,point.y);
    }
    glFlush();       // Send all output to display   
}

// Initialization
void Init(void)    
{
    glClearColor(1.0,1.0,1.0,0.0); // Set white background color
    glColor3f(0.0f,0.0f,0.0f);    // Set the drawing color
    glPointSize(4.0);             // a 'dot' is 4 by 4 pixels
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,640.0,0.0,480.0);
}

void main(int argc,char *argv[])
{
    glutInit(&argc, argv);  // Initialize the toolkit
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);  // Set display mode
    glutInitWindowPosition(100, 150);  // Set window pozition on screen
    glutInitWindowSize(640, 480);      // Set window size
    glutCreateWindow("sierpinski gasket"); // Open the screen window
    glutDisplayFunc(sierpinski); // Register redraw function
    Init();
    glutMainLoop();  // Go into a perpetual loop
}

January 25

I lose the game

I have took part in a campaign last month, or even more early, which may give the winner a chance to go the the Arctic. But I lose the game at last.

here is an article asked by the Organizing Committee and written by myself(There is also a chinese version of this article. If somebody want it, please contact me):

Dream about Arctic

When I keep up long-distance running and taking a cold shower in the north cold winner, my classmates said that I made a rod for my own back. I joked with them and said that one day I would develop software for polar bear. Then, when I read the piece of news about this activity on a newspaper, I suddenly wake up to that there is a dream of arctic in my heart.

Maybe somebody would ask whether it is meaningful for me, a student of software engineering, to come to Arctic. And let me tell you something as an answer to this question. Once, there is a physical scientist of Peking University came to our school to have a speech. And he mentioned that he have recruited a graduate who graduated with a bachelor of economics, because he want the student to manage the financial affairs of sciences programs. What we can learn from it is that these days, a national research expedition will cover all aspects of knowledge. You see, there is a computer center in Amundsen-Scott South Pole Station of America. And as a student of science department, I will have beneficial effects to this activity.

My sciences program is Software Requirement Analysis and Research in Science Expedition to the Arctic. My program will create two productions. One is a report on software requirement analysis for Polar Research Institute of China (PRIC). This is not a proper document of software requirement analysis, but mainly a suggestion whose contents are the application of computer science, software engineering, data analysis and so on in science expedition to the arctic. And the other is the experience and harvest of this expedition. Its contents include a diary about the activity and straightaway elaboration of science research about the Arctic, which is mainly for college students. After getting the permission from the organizing committee, I will release these two productions on websites to inspire the college of new generation to pay attention to the career of the science expedition to the arctic and make them attracted to take part in this career, which are mainly some forums or social networking websites that are favored by most of the college students. For example, xiaonei (http://xiaonei.com/), facebook (https://www.facebook.com/) and so on.

Why do I choose this sciences program? Because first, I think that it is unpractical and be irresponsible for us to put forward some big sciences programs such as “Atmospheric Science Expedition to the Arctic”. It needs a lot of scientist even countries to cooperate to complete a program which was well-prepared. Our time and activity’s scope is limited our main assignment is intercourse and study. What we should do is use the little to get the big. We will bring the friendship between Norway and China back to our country and show the great work that scientists have done in the Arctic to the rest of the college student, to our country, even to the world. Secondly, it fit me. The fittest is the best. I have taken part in China Undergraduate Mathematical Contest in Modeling (CUMCM), which ask college students to study some difficult problem quickly and use the knowledge they have learned to model and solve it in a short time. From it, I learned the capability of observing and describing the problem and giving Algorithm to solve it quickly, which will help me to do the program better. The last but not the least, it can be easily Extended. To some degree, I’m not a strong person, but I have a good endurance. I can help to do some outdoor research, such as diving into the water to survey the study plot below ice. Under the direction of some scientists, I can use my knowledge in math and computer science to analysis the data that is collected through the trip. Furthermore, I can model the problem, which maybe help scientist to solve some problem.

I always wonder what we would all be doing once we reached the Arctic. In the past, the Arctic was a destination for adventurers, explorers, and seal and caribou hunters. Nowadays, most of the people who spend time on the world's northernmost part are involved, one way or another, with science.

I feel so honored to be a college student in a period of economic prosperity of our country, which makes it possible for some of us to crunch across the snow and gazed with wonder at the northern lights, breathing in the cold, clean air of the Arctic. I hope that my hard-working will made it possible for me to see things, and do things, that most people only dream of.

January 10

Desperate Housewives

I began to watch Desperate Housewives tonight. It is really interesting one. And I hope to learn some Spoken English from it. Or maybe I just want something to spent my time on.

There are some sentences I like best:

This is business. Says the prince as he rides off into the sunset.
The heart wants what it wants.
You see, to live in fear is not to live at all.
There will always be those who face thrir fears...and there will always be those who run away.

January 02

Write comment in English

Tonight, I begun to read <C# Software Solutions>, which was writen by John Lewis and translated into Chinese by Zhu Jianping.

From now on, I will try to code in C# and write comments in English. In the past, I always wrote very little comment in Chinese, which was not normative.

December 28

Try to Protect My Teeth

From now on,I decide to cleaned my teeth within 10 minutes of eating. When possible, I will use the toothbrush. When this was impossible, I will wash my mouth thoroughly with water.

In the past, I merely cleaned my teeth when I went to bed and when I got up in the morning.

 

Guestbook

An error occurred loading this module.

No list items have been added yet.