// This code is converted from Python to C++ using CodeConvert AI
// https://www.codeconvert.ai/python-to-c++-converter
// Some modifications may be needed to make it work
// Include the necessary libraries
#include <iostream>
#include <vector>
#include <tuple>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <memory>
#include <stdexcept>
#include <sstream>
#include <fstream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <numeric>
#include <regex>
#include <random>
#include <chrono>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <future>
#include <atomic>
#include <type_traits>
#include <utility>
#include <iomanip>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdarg>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cinttypes>
#include <cstddef>
#include <new>
#include <memory_resource>
#include <limits>
#include <exception>
#include <stdexcept>
#include <system_error>
#include <cerrno>
#include <initializer_list>
#include <typeinfo>
#include <typeindex>
#include <bitset>
#include <functional>
#include <tuple>
#include <any>
#include <optional>
#include <variant>
#include <compare>
#include <version>
#include <source_location>
#include <concepts>
#include <coroutine>
#include <numbers>
#include <ratio>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <complex>
#include <valarray>
#include <iosfwd>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <syncstream>
#include <fstream>
#include <strstream>
#include <cstdio>
#include <locale>
#include <clocale>
#include <codecvt>
#include <regex>
#include <atomic>
#include <thread>
#include <mutex>
#include <shared_mutex>
#include <future>
#include <condition_variable>
#include <filesystem>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <span>
#include <ranges>
#include <iterator>
#include <algorithm>
#include <execution>
#include <memory>
#include <scoped_allocator>
#include <memory_resource>
#include <string>
#include <string_view>
#include <charconv>
#include <format>
#include <chrono>
#include <date>
#include <stop_token>
#include <latch>
#include <barrier>
#include <semaphore>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <cinttypes>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <stdexcept>
#include <system_error>
#include <new>
#include <typeinfo>
#include <typeindex>
#include <initializer_list>
#include <limits>
#include <cfenv>
#include <cstdalign>
#include <cstdbool>
#include <tgmath.h>
#include <ccomplex>
#include <ctgmath>
#include <ciso646>
#include <cstdnoreturn>
#include <cuchar>
#include <Adafruit_ILI9341.h>
#include <Adafruit_GPIO.h>
#include <Adafruit_GPIO_SPI.h>
using namespace std;
// Raspberry Pi configuration.
const int DC = 18;
const int RST = 17;
const int SPI_PORT = 0;
const int SPI_DEVICE = 0;
// BeagleBone Black configuration.
// const char* DC = "P9_15";
// const char* RST = "P9_12";
// const int SPI_PORT = 1;
// const int SPI_DEVICE = 0;
// Create TFT LCD display class.
Adafruit_ILI9341 disp(DC, RST, SPI_PORT, SPI_DEVICE);
// Initialize display.
disp.begin();
// Clear the display to a red background.
// Can pass any tuple of red, green, blue values (from 0 to 255 each).
disp.clear(make_tuple(255, 0, 0));
// Alternatively can clear to a black screen by calling:
// disp.clear();
// Get a PIL Draw object to start drawing on the display buffer.
auto draw = disp.draw();
// Draw some shapes.
// Draw a blue ellipse with a green outline.
draw.ellipse(make_tuple(10, 10, 110, 80), make_tuple(0,255,0), make_tuple(0,0,255));
// Draw a purple rectangle with yellow outline.
draw.rectangle(make_tuple(10, 90, 110, 160), make_tuple(255,255,0), make_tuple(255,0,255));
// Draw a white X.
draw.line(make_tuple(10, 170, 110, 230), make_tuple(255,255,255));
draw.line(make_tuple(10, 230, 110, 170), make_tuple(255,255,255));
// Draw a cyan triangle with a black outline.
draw.polygon(vector<tuple<int, int>>{make_tuple(10, 275), make_tuple(110, 240), make_tuple(110, 310)}, make_tuple(0,0,0), make_tuple(0,255,255));
// Load default font.
auto font = ImageFont.load_default();
// Alternatively load a TTF font.
// Some other nice fonts to try: http://www.dafont.com/bitmap.php
//font = ImageFont.truetype("Minecraftia.ttf", 16);
// Define a function to create rotated text. Unfortunately PIL doesn't have good
// native support for rotated fonts, but this function can be used to make a
// text image and rotate it so it's easy to paste in the buffer.
void draw_rotated_text(Image& image, string text, tuple<int, int> position, int angle, ImageFont& font, tuple<int, int, int> fill = make_tuple(255,255,255)) {
// Get rendered font width and height.
auto draw = ImageDraw.Draw(image);
auto width = draw.textsize(text, font).first;
auto height = draw.textsize(text, font).second;
// Create a new image with transparent background to store the text.
auto textimage = Image("RGBA", make_tuple(width, height), make_tuple(0,0,0,0));
// Render the text.
auto textdraw = ImageDraw.Draw(textimage);
textdraw.text(make_tuple(0,0), text, font, fill);
// Rotate the text image.
auto rotated = textimage.rotate(angle, true);
// Paste the text into the image, using it as a mask for transparency.
image.paste(rotated, position, rotated);
}
// Write two lines of white text on the buffer, rotated 90 degrees counter clockwise.
draw_rotated_text(disp.buffer, "Hello World!", make_tuple(150, 120), 90, font, make_tuple(255,255,255));
draw_rotated_text(disp.buffer, "This is a line of text.", make_tuple(170, 90), 90, font, make_tuple(255,255,255));
// Write buffer to display hardware, must be called to make things visible on the
// display!
disp.display();