Euphoria
hashgen.retro.cc
Go to the documentation of this file.
1 #include "core/hashgen.h"
2 
3 
4 
5 #include "core/image.h"
6 #include "base/rgb.h"
7 #include "assert/assert.h"
8 #include "core/rng.h"
9 #include "base/numeric.h"
10 #include "core/image_draw.h"
11 #include "base/cint.h"
12 
13 
14 namespace
15 {
16  using namespace eu;
17  using namespace eu::core;
18 
19  template
20  <
21  typename TGenerator,
22  typename I
23  >
24  void
25  render_retro_impl
26  (
27  Image* image,
28  I code,
29  int half_size = 3
30  )
31  {
32  const auto size = half_size * 2;
33 
34  // todo(Gustav): figure out color (randomly?)
35  const auto foreground_color = NamedColor::white;
36  const auto background_color = NamedColor::black;
37 
38  const auto dx = image->width / (size - 1);
39  const auto dy = image->height / size;
40 
41  auto rect = [&](const vec2i& top_left)
42  {
43  draw_rect
44  (
45  image,
46  {foreground_color},
48  (
49  top_left,
50  dx+1, dy
51  )
52  );
53  };
54 
55  clear(image, {background_color});
56 
57  auto generator = TGenerator{code};
58 
59  for(int y=0; y<size; y+=1)
60  {
61  for(int x=0; x<half_size; x+=1)
62  {
63  const auto filled = generator.get_next_float01() < 0.5f;
64  if(filled)
65  {
66  rect(vec2i{x*dx, (y+1)*dy});
67  if(x != half_size-1)
68  {
69  rect(vec2i{image->width - ((x+1)*dx + 2), (y+1)*dy});
70  }
71  }
72  }
73  }
74  }
75 }
76 
77 
78 namespace eu::core
79 {
80  void
81  render_retro(Image* image, U32 code)
82  {
83  render_retro_impl<RandomXorShift32>(image, code);
84  }
85 }
86 
void clear(Image *image, const Rgbai &color)
Definition: image_draw.cc:32
void render_retro(Image *image, U32 code)
void draw_rect(Image *image, const Rgbai &color, const Recti &rect)
Definition: image_draw.cc:39
Definition: assert.h:90
std::uint32_t U32
Definition: ints.h:13
static Recti from_top_left_width_height(const vec2i &topleft, int width, int height)
Definition: rect.cc:561
Definition: vec2.h:72