На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: Qraizer, Hsilgos
Страницы: (2) 1 [2]  все  ( Перейти к последнему сообщению )  
> как нарисовать хоть что то в консоле , Тут попрасили помочь сыну в школу задание дали
    Синусоида в консоле:
    ExpandedWrap disabled
      #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));
      }


    Аналогичная тема
    0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
    0 пользователей:


    Рейтинг@Mail.ru
    [ Script execution time: 0,0249 ]   [ 16 queries used ]   [ Generated: 20.12.25, 09:35 GMT ]