Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include<iostream>
- #include<cmath>
- #include <cstdlib>
- #include <GL\glut.h>
- using namespace std;
- void Draw() {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0,0,0);
- int wybor;
- cout<<"#######ZALEGLE ZAJECIA#######\n"<<endl;
- cout<<"1) rysuj czworokat"<<endl;
- cout<<"2) rysuj trojkat"<<endl;
- cout<<"3) rysuj punkt"<<endl;
- cout<<"4) rysuj wstege trojatow"<<endl;
- cout<<"5) rysuj linie"<<endl;
- cout<<"6) rysuj wachlarz\n"<<endl;
- cout<<"#############################\n"<<endl;
- cin>>wybor;
- switch(wybor)
- {
- case 1://czworokąt
- {
- double x1, y1, x2, y2, x3, y3, x4, y4;
- /*x1=-0.2;
- y1=-0.2;
- x2=0.2;
- y2=-0.2;
- x3=0.2;
- y3=0.2;
- x4=-0.2;
- y4=0.2;*/
- cout<< "podaj wspolrzede punktu 1: "<<endl;
- cout << "x1 : " ;
- cin>>x1;
- cout << "y1 : ";
- cin>>y1;
- cout<< "podaj wspolrzede punktu 2: "<<endl;
- cout << "x2 : " ;
- cin>>x2;
- cout << "y2 : ";
- cin>>y2;
- cout<< "podaj wspolrzede punktu 3: "<<endl;
- cout << "x3 : " ;
- cin>>x3;
- cout << "y3 : ";
- cin>>y3;
- cout<< "podaj wspolrzede punktu 4: "<<endl;
- cout << "x4 : " ;
- cin>>x4;
- cout << "y4 : ";
- cin>>y4;
- glColor3f(1,0,0);
- glBegin(GL_POLYGON);
- glVertex2d(x1,y1);
- glVertex2d(x2,y2);
- glVertex2d(x3,y3);
- glVertex2d(x4,y4);
- glEnd();
- break;
- }
- case 2://trójkąt
- {
- double x1, x2, x3, y1, y2, y3;
- /* x1=0;
- y1=0;
- x2=0;
- y2=0.2;
- x3=0.3;
- y3=0;*/
- cout<< "podaj wspolrzede punktu 1: "<<endl;
- cout << "x1 : " ;
- cin>>x1;
- cout << "y1 : ";
- cin>>y1;
- cout<< "podaj wspolrzede punktu 2: "<<endl;
- cout << "x2 : " ;
- cin>>x2;
- cout << "y2 : ";
- cin>>y2;
- cout<< "podaj wspolrzede punktu 3: "<<endl;
- cout << "x3 : " ;
- cin>>x3;
- cout << "y3 : ";
- cin>>y3;
- glColor3f(1,0,0);
- glBegin(GL_TRIANGLES);
- glVertex2d(x1, y1);
- glVertex2d(x2, y2);
- glVertex2d(x3, y3);
- glEnd();
- break;
- }
- case 3://punkty o różnej szerokości
- {
- double x,y;
- //cin>>x>>y;
- x=0;
- y=0;
- cout<<"podaj ilosc punktow : "<<endl;
- int ilosc;
- cin>>ilosc;
- cout<<"podaj wielkosc punktow : "<<endl;
- float rozmiar;
- cin>>rozmiar;
- glPointSize(rozmiar);
- glColor3f(1,0,0);
- for(int i=0;i<ilosc;i++)
- {
- glBegin(GL_POINTS);
- glVertex2d(x,y);
- glEnd();
- glTranslated(0.1,0,0);
- }
- }
- break;
- case 4://wstęga trójtątów
- {
- int ilosc;
- double delta=0.1;
- cout<<"podaj ilosc trojkatow : "<<endl;
- cin>>ilosc;
- double x1, x2, x3, y1, y2, y3;
- //cin>>x1>>y1;
- //
- x1=-0.5;
- y1=-0.5;
- x2=-0.5;
- y2=0.3;
- x3=-0.3;
- y3=-0.5;
- // glColor3f(0,0,0);
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2d(x1, y1);
- glVertex2d(x2, y2);
- glVertex2d(x3, y3);
- glEnd();
- for(int i=0; i<ilosc; i++)
- {
- if(i%2==1)
- {
- glColor3f(1,0,0);
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2d(x2,y2);
- glVertex2d(x2+delta,y2);
- glVertex2d(x3,y3);
- glEnd();
- x2+=delta;
- }
- else
- {
- glColor3d(0,1,0);
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2d(x3,y3);
- glVertex2d(x2,y2);
- glVertex2d(x3+delta,y3);
- glEnd();
- x3+=delta;
- }
- }
- }
- break;
- case 5://linie o róznej grubości i wzorze
- {
- double grubosc;
- cout<<"podaj grubosc lini : "<<endl;
- cin>>grubosc;
- glLineWidth(grubosc);
- double x1, x2, y1, y2;
- x1=-0.5;
- y1=-0.5;
- x2=0.2;
- y2=0.2;
- //cin>>x1>>y1;
- //cin>>x2>>y2;
- glBegin(GL_LINES);
- glVertex2d(x1, y1);
- glVertex2d(x2, y2);
- glEnd();
- glFlush();
- glEnable(GL_LINE_STIPPLE);
- double wzor, factor;
- cout<<"podaj pattern : "<<endl; //czyli wzor rysowanej linii
- cin>>wzor;
- cout<<"podaj factor : "<<endl;
- cin>>factor;
- //glColor3f(0.7,0.2,0.1);
- //glLineStipple(1, 0x00FF);
- glColor3f(1,0,0);
- glLineStipple(factor, wzor);
- glBegin(GL_LINES);
- glVertex2d(x1, y1);
- glVertex2d(x2, y2);
- glEnd();
- glFlush();
- }
- break;
- case 6:
- {
- glColor3f(0,1,0);
- double delta = 0.09;
- double r; //promien
- r=0.7;
- double n;
- cout<<"podaj ilosc trojkatow : "<<endl;
- cin>>n;
- double angle;
- double PI = 22/7;
- double a,b;
- a=-0.2;
- b=-0.2;
- //cin>>a>>b;
- double pom_x, pom_y;
- pom_x=0;
- pom_y=0;
- double x, y; //wsp
- glBegin(GL_TRIANGLE_FAN);
- for(double i=0; i<=n; i++)
- {
- glColor3d(0.1+(i*2),0.1+(i*2),0.1+(i*2));
- glVertex2d(a,b);
- glVertex2d(pom_x, pom_y);
- angle = 2*i*PI/n;
- x=r*cos(angle)*1.4;
- pom_x=x;
- y=r*sin(angle)*1.4;
- pom_y=y;
- glVertex2f(x, y);
- }
- glEnd();
- }
- break;
- }
- glFlush();
- }
- void Initialize() {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(500, 500);
- glutInitWindowPosition(200, 200);
- glutCreateWindow("zalegle zajecia");
- Initialize();
- glutDisplayFunc(Draw);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment