// // Canvas.hpp // AwesomeAttractorND // // Created by Joshua Moerman on 10/28/11. // Copyright 2011 Vadovas. All rights reserved. // #ifndef AwesomeAttractorND_Canvas_hpp #define AwesomeAttractorND_Canvas_hpp #include #include "nd_array.hpp" class Canvas2D : public nd_array{ typedef Canvas2D self; typedef nd_array super; public: Canvas2D(size_t width, size_t height) : super(width, height) {} void plot(double const * const position){ const size_t width = get_size(0); const size_t height = get_size(1); const size_t x = 0.5*position[0]*width + width*.5; const size_t y = 0.5*position[1]*width + height*.5; if(x < width && y < height) { (*this)[x][y]++; } } }; class Canvas2Db : public std::vector > { typedef Canvas2Db self; typedef std::vector > super; public: Canvas2Db(size_t width, size_t height) : super(width, super::value_type(height, 0)) {} void plot(double const * const position){ const size_t width = get_size(0); const size_t height = get_size(1); const size_t x = 0.5*position[0]*width + width*.5; const size_t y = 0.5*position[1]*width + height*.5; if(x < width && y < height) { (*this)[x][y]++; } } size_t get_size(size_t n) const { switch (n) { case 0: return size(); case 1: return front().size(); } return 0; } }; #endif