Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Tree.h"
- #include <windows.h>
- #include <GL/glut.h>
- #include <stdlib.h>
- Tree::Tree(const int x, const int y, const int height):GraphicObject(x,y)
- {
- if(height<2)
- {
- this->height=2;
- this->div=7;
- colorChange = 0.2;
- }
- else
- {
- if(height<=7)
- {
- this->height=height;
- this->div=10-height+1;
- colorChange = 0.08-div/100;
- }
- else
- {
- this->height=7;
- this->div=4;
- colorChange = 0.08;
- }
- }
- for(int i = 0;i<=20;i++) //kmen
- {
- colPoints.insert(std::pair<int, int>(28, i));
- }
- /*
- int pom = height * 32;
- for(int z = 32*height;z>=0;z--) //vrch
- {
- colPoints.insert(std::pair<int, int>(i, 0));
- }*/
- for(int i=0;i<this->height;i++)
- {
- colPoints.insert(std::pair<int, int>(6+i*div, 20+i*12));
- colPoints.insert(std::pair<int, int>(58-i*div, 20+i*12));
- colPoints.insert(std::pair<int, int>(32, 34+i*12));
- }
- };
- void Tree::draw()
- {
- glBegin(GL_POLYGON); //kmen
- glColor3f(0.5, 0.15, 0.15);
- glVertex2i(28+x, 0+y); //1
- glVertex2i(36+x, 0+y);
- glVertex2i(36+x, 20+y);
- glVertex2i(28+x, 20+y);
- glEnd();
- for(int i=0;i<this->height;i++)
- {
- glBegin(GL_TRIANGLES);
- glColor3f(0.4, 0.65-i*this->colorChange, 0.45-i*this->colorChange);
- glVertex2i(6+i*div+x, 20+i*12+y);
- glVertex2i(58-i*div+x, 20+i*12+y);
- glVertex2i(32+x, 34+i*12+y);
- glEnd();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement