как нарисовать хоть что то в консоле
, Тут попрасили помочь сыну в школу задание дали
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
| ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
| [216.73.216.43] |
|
|
| Страницы: (2) 1 [2] все ( Перейти к последнему сообщению ) |
как нарисовать хоть что то в консоле
, Тут попрасили помочь сыну в школу задание дали
|
Сообщ.
#16
,
|
|
|
|
Синусоида в консоле:
![]() ![]() #include <iostream> #include <vector> #include <algorithm> #include <functional> #include <iterator> #include <math.h> typedef std::vector<std::vector<char> > CharMatrix; class Shape { public: virtual ~Shape() { } void Release() { delete this; } virtual void Draw(CharMatrix* buf) = 0; }; class Sin : public Shape { void Draw(CharMatrix* buf) { int Rows = buf->size(); int Cols = (*buf)[0].size(); const int Count = 1000; for (int i = 0 ; i < Count ; ++i) { int Col = int((1.0 * i * Cols) / Count); int Row = int((sin((12.56 * i) / Count) / 2.0 + 0.5) * Rows); (*buf)[Row][Col] = '*'; } } }; void main() { CharMatrix m(25, std::vector<char>(80, ' ')); std::vector<Shape*> Shapes; Shapes.push_back(new Sin); std::for_each(Shapes.begin(), Shapes.end(), std::bind2nd(std::mem_fun1<void, Shape, CharMatrix*>(&Shape::Draw), &m)); for (CharMatrix::const_iterator i = m.begin() ; i != m.end() ; ++i) { std::copy(i->begin(), i->end(), std::ostream_iterator<char>(std::cout)); std::cout << std::endl; } std::for_each(Shapes.begin(), Shapes.end(), std::mem_fun<void, Shape>(&Shape::Release)); } Аналогичная тема |