z biblioteki winbgim.
Chodzi o to, ze chcialbym zeby punkt (0,0) znalazl sie w srodku okna i odpowiednio do klasycznego malaly i rosly wartosci na osiach
Oto kod:
plik main.cpp
Kod: Zaznacz cały
#include <cstdlib>
#include <iostream>
#include <winbgim.h>
#include "class.h"
#include "inicjalizacje klas.h"
using namespace std;
int main(int argc, char *argv[])
{
Grafika Rysuj;
int szer, wys;
szer = 400;
wys = 400;
//************************* Podajemy wymiary okna
/*cout << "Podaj wymiary okna w pikselach: ";
cout << "Szerokosc: ";
cin >> szer;
cout << "Wysokosc: ";
cin >> wys;*/
//************************ Rysujemy uklad i okno
Rysuj.RysujOkno(szer,wys);
Rysuj.RysujUklad(szer,wys);
//************************ Praca
/*int a = 2;
int x, y;
for (x = 0; x < szer; x++)
{
y = a * x;
if (x < szer / 2)x = x - szer / 2;
if (x > szer / 2)x = x / 2;
if (y < wys / 2)y = wys - y;
if (y > wys / 2)y = -y / 2;
if (x == szer / 2)x = 0;
if (y == wys / 2)y = 0;
putpixel(x, y, BLUE);
}*/
while(!kbhit());
closegraph();
system("PAUSE");
return EXIT_SUCCESS;
}
plik class.h
Kod: Zaznacz cały
class Grafika
{
public:
Grafika();
~Grafika(){}
float GetX() const { return itsX; }
//void SetX(int x) { itsX = x; }
float GetY() const { return itsY; }
//void SetX(int y) { itsY = y; }
void RysujOkno(int &x, int &y);
void RysujUklad(int &x, int &y);
private:
int itsX;
int itsY;
};
plik inicjalizacja klas.h
Kod: Zaznacz cały
//************************ Konstruktor
Grafika::Grafika():
itsX(0),
itsY(0)
{}
//************************ Funkcja od rysowania okna
void Grafika::RysujOkno(int &width, int &height)
{
initwindow(width,height);
setfillstyle(SOLID_FILL, WHITE);
bar (0,0,getmaxx(), getmaxy());
}
//************************ Funkcja od rysowania ukladu
void Grafika::RysujUklad(int &width, int &height)
{
setcolor(BLACK);
//os x
line( 0, (width / 2), width, (height / 2));
//os y
line( (width / 2), 0, (width / 2), height);
//strzalki
//od osi x
line( (width - 10), (height / 2 + 4), width, (height / 2) );
line( (width - 10), (height / 2 - 4), width, (height / 2) );
//od osi y
line( (width / 2 + 4), 10, (width / 2), 0 );
line( (width / 2 - 4), 10, (width / 2), 0 );
}