aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-05-14 23:06:20 +0200
committerAdrian Kummerlaender2016-05-14 23:06:20 +0200
commit64880ba1019f8c81470d697143b7bf48143b2fc8 (patch)
treef758030b5d151a47b50df233d39215ea5abaec63 /src
parent8e1d7c4e484ef43dddc5074055727694ceb0e37b (diff)
downloadvoronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.tar
voronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.tar.gz
voronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.tar.bz2
voronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.tar.lz
voronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.tar.xz
voronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.tar.zst
voronoi-64880ba1019f8c81470d697143b7bf48143b2fc8.zip
Separate into multiple compilation units, add color functions
* fix cartesian coordinate determination
Diffstat (limited to 'src')
-rw-r--r--src/color.cc19
-rw-r--r--src/color.h24
-rw-r--r--src/imgen.cc29
-rw-r--r--src/imgen.h21
-rw-r--r--src/ppm_pixel_stream.cc32
-rw-r--r--src/ppm_pixel_stream.h23
6 files changed, 105 insertions, 43 deletions
diff --git a/src/color.cc b/src/color.cc
new file mode 100644
index 0000000..9af409a
--- /dev/null
+++ b/src/color.cc
@@ -0,0 +1,19 @@
+#include "color.h"
+
+namespace imgen {
+
+color red() { return color{255, 0, 0}; }
+color lime() { return color{ 0, 255, 0}; }
+color blue() { return color{ 0, 0, 255}; }
+color yellow() { return color{255, 255, 0}; }
+color cyan() { return color{ 0, 255, 255}; }
+color magenta() { return color{255, 0, 255}; }
+color silver() { return color{192, 192, 192}; }
+color maroon() { return color{128, 0, 0}; }
+color olive() { return color{128, 128, 0}; }
+color green() { return color{ 0, 128, 0}; }
+color purple() { return color{128, 0, 128}; }
+color teal() { return color{ 0, 128, 128}; }
+color navy() { return color{ 0, 0, 128}; }
+
+}
diff --git a/src/color.h b/src/color.h
new file mode 100644
index 0000000..2c35465
--- /dev/null
+++ b/src/color.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <tuple>
+#include <cstdint>
+
+namespace imgen {
+
+using color = std::tuple<std::uint8_t, std::uint8_t, std::uint8_t>;
+
+color red();
+color lime();
+color blue();
+color yellow();
+color cyan();
+color magenta();
+color silver();
+color maroon();
+color olive();
+color green();
+color purple();
+color teal();
+color navy();
+
+}
diff --git a/src/imgen.cc b/src/imgen.cc
index 25731e1..027e425 100644
--- a/src/imgen.cc
+++ b/src/imgen.cc
@@ -1,34 +1,9 @@
#include "imgen.h"
-namespace {
-
-inline void write_color(std::ofstream& out, const imgen::color& color) {
- out << std::get<0>(color)
- << std::get<1>(color)
- << std::get<2>(color);
-}
-
-}
+#include "ppm_pixel_stream.h"
namespace imgen {
-ppm_pixel_stream::ppm_pixel_stream(
- const std::string& path,
- const std::size_t width,
- const std::size_t height
-): stream_() {
- this->stream_.open(path, std::ios::binary | std::ios::out);
- this->stream_.sync_with_stdio(false);
-
- this->stream_ << "P6\n" << width << " " << height << "\n255\n";
-}
-
-ppm_pixel_stream& ppm_pixel_stream::operator<<(const color& value) {
- write_color(this->stream_, value);
-
- return *this;
-}
-
void write_ppm(
const std::string& path,
const std::size_t width,
@@ -42,7 +17,7 @@ void write_ppm(
const std::ptrdiff_t min_x = width / 2 * -1;
const std::ptrdiff_t max_x = width / 2;
- for ( std::ptrdiff_t posY = min_y; posY < max_y; ++posY ) {
+ for ( std::ptrdiff_t posY = max_y; posY > min_y; --posY ) {
for ( std::ptrdiff_t posX = min_x; posX < max_x; ++posX ) {
file << generator(posX, posY);
}
diff --git a/src/imgen.h b/src/imgen.h
index 35b798d..6954239 100644
--- a/src/imgen.h
+++ b/src/imgen.h
@@ -1,24 +1,13 @@
+#pragma once
+
#include <string>
-#include <utility>
-#include <fstream>
#include <functional>
-namespace imgen {
-
-using color = std::tuple<std::uint8_t, std::uint8_t, std::uint8_t>;
+#include "color.h"
-class ppm_pixel_stream {
- public:
- ppm_pixel_stream(const std::string& path,
- const std::size_t width,
- const std::size_t height);
-
- ppm_pixel_stream& operator<<(const color& value);
-
- private:
- std::ofstream stream_;
+namespace imgen {
-};
+using colored_vector = std::tuple<int, int, color>;
void write_ppm(
const std::string& path,
diff --git a/src/ppm_pixel_stream.cc b/src/ppm_pixel_stream.cc
new file mode 100644
index 0000000..465584b
--- /dev/null
+++ b/src/ppm_pixel_stream.cc
@@ -0,0 +1,32 @@
+#include "ppm_pixel_stream.h"
+
+namespace {
+
+inline void write_color(std::ofstream& out, const imgen::color& color) {
+ out << std::get<0>(color)
+ << std::get<1>(color)
+ << std::get<2>(color);
+}
+
+}
+
+namespace imgen {
+
+ppm_pixel_stream::ppm_pixel_stream(
+ const std::string& path,
+ const std::size_t width,
+ const std::size_t height
+): stream_() {
+ this->stream_.open(path, std::ios::binary | std::ios::out);
+ this->stream_.sync_with_stdio(false);
+
+ this->stream_ << "P6\n" << width << " " << height << "\n255\n";
+}
+
+ppm_pixel_stream& ppm_pixel_stream::operator<<(const color& value) {
+ write_color(this->stream_, value);
+
+ return *this;
+}
+
+}
diff --git a/src/ppm_pixel_stream.h b/src/ppm_pixel_stream.h
new file mode 100644
index 0000000..9d8f5a8
--- /dev/null
+++ b/src/ppm_pixel_stream.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <string>
+#include <fstream>
+
+#include "color.h"
+
+namespace imgen {
+
+class ppm_pixel_stream {
+ public:
+ ppm_pixel_stream(const std::string& path,
+ const std::size_t width,
+ const std::size_t height);
+
+ ppm_pixel_stream& operator<<(const color& value);
+
+ private:
+ std::ofstream stream_;
+
+};
+
+}