My old project for strange attractors, new approach
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

69 lines
1.4 KiB

//
// 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 <vector>
#include "nd_array.hpp"
class Canvas2D : public nd_array<unsigned int, 2>{
typedef Canvas2D self;
typedef nd_array<unsigned int, 2> 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<std::vector<unsigned int> > {
typedef Canvas2Db self;
typedef std::vector<std::vector<unsigned int> > 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