Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "glut.h"
- float point[2];
- int points = 10000000;
- void f1(){
- point[0] = point[0]*0.5;
- point[1] = point[1]*0.5;
- }
- void f2(){
- point[0] = point[0]*0.5+0.5;
- point[1] = point[1]*0.5;
- }
- void f3(){
- point[0] = point[0]*0.5;
- point[1] = point[1]*0.5+0.5;
- }
- void p1(){
- point[0] = 0;
- point[1] = 0.16*point[1];
- }
- void p2(){
- point[0] = 0.85*point[0]+0.04*point[1];
- point[1] = -0.04*point[0]+0.85*point[1] + 1.6;
- }
- void p3(){
- point[0] = 0.2*point[0] - 0.26*point[1];
- point[1] = 0.23*point[0] + 0.22*point[1] + 1.6;
- }
- void p4(){
- point[0] = -0.15*point[0] + 0.28*point[1];
- point[1] = 0.26*point[0] + 0.24*point[1] + 0.44;
- }
- void set_rand_point(){
- //point[0] = (rand() % 1000) /1000.0;
- //point[1] = (rand() % 1000) /1000.0;
- point[0] = 0;
- point[1] = 0;
- }
- int probability(){
- int r = rand() % 100;
- if(r < 1)
- return 0;
- if(r < 86)
- return 1;
- if(r < 93)
- return 2;
- return 3;
- }
- void render_scene(void) {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPointSize(1);
- glBegin(GL_POINTS);
- set_rand_point();
- for(int i = 0; i < points; i++)
- {
- switch(probability()){
- case 0:
- p1();
- break;
- case 1:
- p2();
- break;
- case 2:
- p3();
- break;
- case 3:
- p4();
- break;
- }
- glVertex2f(point[0],point[1]);
- }
- glEnd();
- glFlush();
- }
- void my_keyboard(unsigned char key, int x, int y){
- switch(key){
- case '+':
- if(points * 2 > 1000000)
- points = 1000000;
- else{
- points *= 2;
- }
- points *= 2;
- break;
- case '-':
- if(points > 1)points /= 2;;
- break;
- }
- render_scene();
- }
- int main(int argc, char **argv) {
- // init GLUT and create window
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA);
- glutInitWindowSize(600,600);
- glutCreateWindow("Lighthouse3D - GLUT Tutorial");
- // register callbacks
- glutDisplayFunc(render_scene);
- glutKeyboardFunc(my_keyboard);
- // OpenGL init
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_MODELVIEW);
- glTranslated(-0.5,-1.0,0);
- glScalef(0.18,0.18,0.18);
- // enter GLUT event processing cycle
- glutMainLoop();
- return 1;
- }
Add Comment
Please, Sign In to add comment