Skip to main content
added 41 characters in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13

C++ using SFML : 722 703 683 527 411411 399 bytes

-12 bytes thanks to ceilingcat and pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice. His second optimization renders the use of vector useless, making an include and object usage useless

#include<SFML/Graphics.hpp>
#define B+__builtin_popcount(
void v(int n){sf::CircleShape h(4,6);for(sf::RenderWindow w({1200,1000},"");w.isOpen();;w.display()){for(sf::Event e;w.pollEvent(e);)if(!e.type?h.setOrigin(-600,-650):w.close();w.clear();for(int x=0,y,z=1<<n;x++<z;z=1<<n;x<z;)for(y=0;y<=zy=x++-x;z;y++;)h.setPosition(4.3*(-2*y+z-x),-2.5*(3*x-22+z-z)3*x),h.setOrigin(-600,-650),h.setFillColor(sf::Color((B(-x)B(-y)B(z z+y-x-y++)^n)&1-n&1?65535:-65281)),w.draw(h);w.display();}}

C++ using SFML : 722 703 683 527 411 bytes

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice. His second optimization renders the use of vector useless, making an include and object usage useless

#include<SFML/Graphics.hpp>
#define B+__builtin_popcount
void v(int n){sf::CircleShape h(4,6);for(sf::RenderWindow w({1200,1000},"");w.isOpen();){for(sf::Event e;w.pollEvent(e);)if(!e.type)w.close();w.clear();for(int x=0,y,z=1<<n;x++<z;)for(y=0;y<=z-x;)h.setPosition(4.3*(-2*y+z-x),-2.5*(3*x-2-z)),h.setOrigin(-600,-650),h.setFillColor(sf::Color((B(-x)B(y)B(z-x-y++)^n)&1?65535:-65281)),w.draw(h);w.display();}}

C++ using SFML : 722 703 683 527 411 399 bytes

-12 bytes thanks to ceilingcat and pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice. His second optimization renders the use of vector useless, making an include and object usage useless

#include<SFML/Graphics.hpp>
#define B+__builtin_popcount(
void v(int n){sf::CircleShape h(4,6);for(sf::RenderWindow w({1200,1000},"");w.isOpen();w.display()){for(sf::Event e;w.pollEvent(e);)e.type?h.setOrigin(-600,-650):w.close();w.clear();for(int x=0,y,z=1<<n;x<z;)for(y=x++-z;y++;)h.setPosition(4.3*(2*y+z-x),2.5*(2+z-3*x)),h.setFillColor(sf::Color(B-x)B-y)B z+y-x)-n&1?65535:-65281)),w.draw(h);}}
deleted 366 characters in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13

C++ using SFML : 722 703 683 527527 411 bytes

-156 bytes thanks to pan

-116 bytes again thanks to pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice.

SFML is a library that helps with His second optimization renders the developmentuse of graphical / audio / network applications.

There's probably some golfing optimization to be done using macros herevector useless, making an include and there.object usage useless

It has 2 functions, the d(int) function computes positions on the screen of the hexagons and their color, and returns a structure composed of the x and y coordinates, and a boolean that is true for light color and false for dark color. The v(int) function does the call topan's code d(int) and does all the graphical things:

#include<vector>
#include<SFML/Graphics.hpp>
#define B+__builtin_popcount
struct t{double x,y;int b;};voidvoid v(int n){sf::CircleShape h(4,6);std::vector<t>v;auto r=5.;for(int x=0,y,z,w=1<<n;x<w;++x)for(y=0;y<w-x;++y)z=w-1-x-y,v.push_back({-.86*(r*y-r*z),r*x-(r*y+r*z)/2,B(x)B(y)B(z)^n});for(sf::RenderWindow w({1200,1000},"");w.isOpen();){for(sf::Event e;w.pollEvent(e);)if(!e.type)w.close();w.clear();for(t&a:vint x=0,y,z=1<<n;x++<z;)for(y=0;y<=z-x;)h.setPosition(a4.3*(-2*y+z-x),-a2.y5*(3*x-2-z)),h.setOrigin(-600,-650),h.setFillColor(sf::Color(a.b&1(B(-x)B(y)B(z-x-y++)^n)&1?65535:-65281)),w.draw(h);w.display();}}

SFML is a library that helps with the development of graphical / audio / network applications.

C++ using SFML : 722 703 683 527 bytes

-156 bytes thanks to pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice.

SFML is a library that helps with the development of graphical / audio / network applications.

There's probably some golfing optimization to be done using macros here and there.

It has 2 functions, the d(int) function computes positions on the screen of the hexagons and their color, and returns a structure composed of the x and y coordinates, and a boolean that is true for light color and false for dark color. The v(int) function does the call to d(int) and does all the graphical things

#include<vector>
#include<SFML/Graphics.hpp>
#define B+__builtin_popcount
struct t{double x,y;int b;};void v(int n){sf::CircleShape h(4,6);std::vector<t>v;auto r=5.;for(int x=0,y,z,w=1<<n;x<w;++x)for(y=0;y<w-x;++y)z=w-1-x-y,v.push_back({-.86*(r*y-r*z),r*x-(r*y+r*z)/2,B(x)B(y)B(z)^n});for(sf::RenderWindow w({1200,1000},"");w.isOpen();){for(sf::Event e;w.pollEvent(e);)if(!e.type)w.close();w.clear();for(t&a:v)h.setPosition(a.x,-a.y),h.setOrigin(-600,-650),h.setFillColor(sf::Color(a.b&1?65535:-65281)),w.draw(h);w.display();}}

C++ using SFML : 722 703 683 527 411 bytes

-156 bytes thanks to pan

-116 bytes again thanks to pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice. His second optimization renders the use of vector useless, making an include and object usage useless

pan's code :

#include<SFML/Graphics.hpp>
#define B+__builtin_popcount
void v(int n){sf::CircleShape h(4,6);for(sf::RenderWindow w({1200,1000},"");w.isOpen();){for(sf::Event e;w.pollEvent(e);)if(!e.type)w.close();w.clear();for(int x=0,y,z=1<<n;x++<z;)for(y=0;y<=z-x;)h.setPosition(4.3*(-2*y+z-x),-2.5*(3*x-2-z)),h.setOrigin(-600,-650),h.setFillColor(sf::Color((B(-x)B(y)B(z-x-y++)^n)&1?65535:-65281)),w.draw(h);w.display();}}

SFML is a library that helps with the development of graphical / audio / network applications.

added 1061 characters in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13

C++ using SFML : 722 703 683683 527 bytes

-20 bytes, I used the using keyword for namespaces and components, and stopped using .f for magic numbers

-156 bytes thanks to pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice.

It has 2 functions, the d(int) function computes positions on the screen of the hexagons and their color, and returns a structure composed of the x and y coordinates, and a boolean that is true for light color and false for dark color. The v(int) function does the call to d(int) and does all the graphical things

#include<vector>
#include<SFML/Graphics.hpp>
#define B+__builtin_popcount
struct t{double x,y;int b;};void v(int n){sf::CircleShape h(4,6);std::vector<t>v;auto r=5.;for(int x=0,y,z,w=1<<n;x<w;++x)for(y=0;y<w-x;++y)z=w-1-x-y,v.push_back({-.86*(r*y-r*z),r*x-(r*y+r*z)/2,B(x)B(y)B(z)^n});for(sf::RenderWindow w({1200,1000},"");w.isOpen();){for(sf::Event e;w.pollEvent(e);)if(!e.type)w.close();w.clear();for(t&a:v)h.setPosition(a.x,-a.y),h.setOrigin(-600,-650),h.setFillColor(sf::Color(a.b&1?65535:-65281)),w.draw(h);w.display();}}

Previous 683 bytes answer (with the "exact" value or cos(210°)) :

C++ using SFML : 722 703 683 bytes

-20 bytes, I used the using keyword for namespaces and components, and stopped using .f for magic numbers

It has 2 functions, the d(int) function computes positions on the screen of the hexagons and their color, and returns a structure composed of the x and y coordinates, and a boolean that is true for light color and false for dark color. The v(int) function does the call to d(int) and does all the graphical things

C++ using SFML : 722 703 683 527 bytes

-20 bytes, I used the using keyword for namespaces and components, and stopped using .f for magic numbers

-156 bytes thanks to pan

pan's proposed version approximates the value of cos(210) to around -.86, which will produce a slightly different graphic output, but very close to what's required by the challenge. This makes the cmath include useless. He also put the whole code into one function, and used a number of golfy techniques to reduce more the byte count, which makes the result very nice.

It has 2 functions, the d(int) function computes positions on the screen of the hexagons and their color, and returns a structure composed of the x and y coordinates, and a boolean that is true for light color and false for dark color. The v(int) function does the call to d(int) and does all the graphical things

#include<vector>
#include<SFML/Graphics.hpp>
#define B+__builtin_popcount
struct t{double x,y;int b;};void v(int n){sf::CircleShape h(4,6);std::vector<t>v;auto r=5.;for(int x=0,y,z,w=1<<n;x<w;++x)for(y=0;y<w-x;++y)z=w-1-x-y,v.push_back({-.86*(r*y-r*z),r*x-(r*y+r*z)/2,B(x)B(y)B(z)^n});for(sf::RenderWindow w({1200,1000},"");w.isOpen();){for(sf::Event e;w.pollEvent(e);)if(!e.type)w.close();w.clear();for(t&a:v)h.setPosition(a.x,-a.y),h.setOrigin(-600,-650),h.setFillColor(sf::Color(a.b&1?65535:-65281)),w.draw(h);w.display();}}

Previous 683 bytes answer (with the "exact" value or cos(210°)) :

added 1 character in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13
Loading
Corrected the explainations
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13
Loading
added 125 characters in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13
Loading
added 125 characters in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13
Loading
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13
Loading