Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include "graphics.h"
- using namespace std;
- class tPoint
- {
- protected:
- int x;
- int y;
- int color;
- public:
- tPoint();
- tPoint(int x1, int y1);
- tPoint(int x1, int y1, int col);
- //tPoint(tPoint &point);
- ~tPoint();
- void draw();
- void move (int dx, int dy);
- void hide();
- };
- class tCircle : public tPoint
- {
- protected:
- double r;
- public:
- tCircle();
- tCircle(int x1, int y1, double r1);
- tCircle(int x1, int y1, double r1, int col);
- //tCircle(tCircle &circle);
- ~tCircle();
- void draw();
- void hide();
- };
- class tLine : public tPoint
- {
- protected:
- int dx;
- int dy;
- public:
- tLine();
- tLine(int x1, int y1, int dx1, int dy1);
- tLine(int x1, int y1, int dx1, int dy1, int col);
- //tLine(tLine &line);
- ~tLine();
- void draw();
- void hide();
- void rotate (double fi);
- };
- class tSquare : public tLine
- {
- public:
- tSquare();
- tSquare(int x1, int y1, int dx1, int dy1);
- tSquare(int x1, int y1, int dx1, int dy1, int col);
- ~tSquare();
- void draw();
- void hide();
- // void rotate(double fi);
- };
- /*class Romb : public Square
- {
- }
- class Rect : public Square
- {
- }
- class Parallel : public Romb, public Rect
- {
- }*/
- //tPoint operators
- tPoint::tPoint(){
- x=0;
- y=0;
- color=13;
- }
- tPoint::tPoint(int x1, int y1){
- x=x1;
- y=y1;
- }
- tPoint::tPoint(int x1, int y1, int col){
- x=x1;
- y=y1;
- color=col;
- }
- tPoint::~tPoint(){
- }
- void tPoint::draw(){
- putpixel(x, y, color);
- }
- void tPoint::hide(){
- putpixel(x,y,0);
- }
- //tCircle operators
- tCircle::tCircle():tPoint(){
- r=1;
- }
- tCircle::tCircle(int x1, int y1, double r1):tPoint(x1, y1){
- r=r1;
- }
- tCircle::tCircle(int x1, int y1, double r1, int col):tPoint(x1, y1, col){
- r=r1;
- }
- tCircle::~tCircle(){
- }
- void tCircle::draw(){
- setcolor(color);
- circle(x, y, r);
- }
- void tCircle::hide(){
- setcolor(0);
- circle(x, y, r);
- }
- //tLine operators
- tLine::tLine():tPoint(){
- dx=10;
- dy=10;
- }
- tLine::tLine(int x1, int y1, int dx1, int dy1):tPoint(x1, y1){
- dx=dx1;
- dy=dy1;
- }
- tLine::tLine(int x1, int y1, int dx1, int dy1, int col):tPoint(x1, y1, col){
- dx=dx1;
- dy=dy1;
- }
- tLine::~tLine(){
- }
- void tLine::draw(){
- setcolor(color);
- line(x, y, x+dx, y+dy);
- }
- void tLine::hide(){
- setcolor(0);
- line(x, y, x+dx, y+dy);
- }
- void tLine::rotate (double fi){
- int dx1 = dx;
- int dy1 = dy;
- dx = (dx1*cos(fi) - dy1*sin(fi));
- dy = (dy1*cos(fi) + dx1*sin(fi));
- }
- //tSquare operators
- tSquare::tSquare():tLine(){};
- tSquare::tSquare(int x1, int y1, int dx1, int dy1):tLine(x1, y1, dx1, dy1){};
- tSquare::tSquare(int x1, int y1, int dx1, int dy1, int col):tLine(x1, y1, dx1, dy1, col){};
- tSquare::~tSquare(){};
- void tSquare::draw(){
- setcolor(color);
- line(x, y, x+dx, y+dy);
- line(x, y, x-dx, y-dy);
- line(x+dx, y+dy, x, y+dy+dy);
- line(x-dx, y+dy, x, y+dy+dy);
- }
- void tSquare::hide(){
- setcolor(0);
- line(x, y, x+dx, y+dy);
- line(x, y, x-dx, y-dy);
- line(x+dx, y+dy, x, y+dy+dy);
- line(x-dx, y+dy, x, y+dy+dy);
- }
- int main ()
- {
- int gddriver = DETECT, gmode, errorcode;
- initgraph(&gddriver, &gmode, "");
- tPoint A;
- A.draw();
- tCircle B(15, 15, 10, 11);
- B.draw();
- tLine C(30, 30, 15, 15, 10);
- C.draw();
- C.rotate(1.789);
- C.draw();
- tSquare D(50, 50, 10, 10, 9);
- D.draw();
- getch();
- closegraph();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement