Skip to content

Instantly share code, notes, and snippets.

@seth10
Created March 29, 2017 23:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seth10/f414708c08b7c5514d946a22b59badfa to your computer and use it in GitHub Desktop.
Save seth10/f414708c08b7c5514d946a22b59badfa to your computer and use it in GitHub Desktop.
Systematic Love
#include <iostream>
#include <math.h>
const int HEART_SIZE = 20;
const int HALF_SIZE = HEART_SIZE / 2;
bool is_in_love(int x, int y);
int main(void)
{
std::string message = " SYSTEMATIC LOVE";
int message_indent = (HALF_SIZE - (message.length() / 4)) - 1;
for(int y = 0; y < HEART_SIZE; ++y)
{
for(int x = 0; x < HEART_SIZE; ++x)
{
std::cout << ((is_in_love(x,y)) ? "vv" : " ");
if(y == HALF_SIZE -1)
{
if(x == message_indent)
{
std::cout << message.c_str();
x += (message.length() / 2);
}
}
}
std::cout << "\n";
}
return 0;
}
bool is_in_love(int x, int y)
{
const float width = 2.2f;
const float height = 3.0f;
const float HEART_COEFFICIENT = 0.7f;
float check_x = ((static_cast<float>(x) / static_cast<float>(HEART_SIZE)) - 0.5f) * width;
float check_y = ((static_cast<float>(HEART_SIZE - y) / static_cast<float>(HEART_SIZE)) - 0.4f) * height;
float top_y = 0.0f;
float bottom_y = 0.0f;
if(check_x >= 0)
{
top_y = sqrt(1 - (check_x * check_x)) + (HEART_COEFFICIENT * sqrt(check_x));
bottom_y = -sqrt(1 - (check_x * check_x)) + (HEART_COEFFICIENT * sqrt(check_x));
}
else
{
top_y = sqrt(1 - (check_x * check_x)) + (HEART_COEFFICIENT * sqrt(-check_x));
bottom_y = -sqrt(1 - (check_x * check_x)) + (HEART_COEFFICIENT * sqrt(-check_x));
}
if((bottom_y <= check_y) && (check_y <= top_y))
{
return true;
}
else
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment