Skip to content

Instantly share code, notes, and snippets.

View MarioLiebisch's full-sized avatar

Mario Liebisch MarioLiebisch

View GitHub Profile
@MarioLiebisch
MarioLiebisch / aoc2021-day1.gd
Created December 1, 2021 09:48
Solution for Advent of Code 2021 day 1 using GDScript
# Execute with:
# godot --no-window -s aoc2021-day1.gd
extends SceneTree
func read_ints(file: String) -> Array:
var ints = []
var f = File.new()
f.open(file, File.READ)
if f.is_open():
@MarioLiebisch
MarioLiebisch / morse.ino
Created March 24, 2020 13:52
Simplified Morse Code Generator for Arduino
// Pins used for this
#define LED_PIN 13
#define BUZZER_PIN 11
// The time in milliseconds for short signals
#define TIME_UNIT 100
// Frequency used
// For classic codes both should match
#define FREQUENCY_LONG 220
#define FREQUENCY_SHORT 440
@MarioLiebisch
MarioLiebisch / hexagons.cpp
Created August 29, 2019 06:43
A simple SFML program to draw a colored, hexagonal grid.
#include <SFML/Graphics.hpp>
#include <vector>
int main()
{
sf::RenderWindow window({640, 480}, "Hexagons", sf::Style::Default, sf::ContextSettings(0, 0, 8));
// We're simply abusing a `CircleShape` here,
// since a circle defined by 6 points IS a hexagon!
sf::CircleShape hexagon(25, 6);
@MarioLiebisch
MarioLiebisch / conext.hpp
Created July 14, 2019 12:42
An old simple wrapper I've used in a few old tools to get cross-platform coloring in console
/**
* @file conext.h
* @author Mario Liebisch <mario.liebisch@gmail.com>
* @section LICENSE
*
* © 2011 All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@MarioLiebisch
MarioLiebisch / timer.cpp
Created May 6, 2019 18:11
Quick and simple timer example using SFML
#include <SFML/Graphics.hpp>
#include <sstream>
#include <iomanip>
int main(int argc, char **argv) {
sf::RenderWindow window(sf::VideoMode(300, 100), "Timer Test", sf::Style::Default);
window.setVerticalSyncEnabled(true);
sf::Font font;
font.loadFromFile("Arial.ttf");
@MarioLiebisch
MarioLiebisch / statswindow.cpp
Created August 26, 2018 19:02
Small example how to add stats counting to a SFML `sf::RenderWindow`. Release builds could just use `sf::RenderWindow` directly instead. Note this isn't necessarily 100% perfect or correct; written from memory.
#include <SFML/Graphics.hpp>
#include <sstream>
class RenderWindowStats : public sf::RenderWindow {
public:
RenderWindowStats() : RenderWindow({640, 480}, "Test") {
}
void draw(sf::Drawable &dr, sf::RenderStates states = sf::RenderStates()) {
++mDrawCallsTemp;
@MarioLiebisch
MarioLiebisch / getself.cpp
Created July 22, 2018 16:18
Small utility function to get a running program's own executable path. This should work even if it's called using a symbolic link.
std::string getSelf()
{
char buf[1024] = { 0 };
#ifdef WIN32
DWORD ret = GetModuleFileNameA(NULL, buf, sizeof(buf));
if (ret && ret != sizeof(buf)) {
std::string res(buf);
for (auto &c : res)
if (c == '\\')
c = '/';
@MarioLiebisch
MarioLiebisch / fpsmeter.cpp
Last active July 16, 2018 08:09
A simple to use, self-containing FPS meter for SFML programs I use for testing
/*
Usage:
* Load a font, if you don't have one yet
* Create the `FpsMeter` object
* Optional: Set a position
* Draw the meter
sf::Font font;
font.loadFromFile("myfont.ttf");
@MarioLiebisch
MarioLiebisch / observable.cpp
Created July 10, 2018 13:49
Simple implementation of an observable variable that will trigger once its value is changed (and which could be adjusted in the callback). This was really just a random idea, it's not perfect by any means.
#include <iostream>
#include <functional>
#include <string>
// Definee an `Observable` class.
// This works as a wrapper around a variable of any type.
// Once it's assigned a new value, a predefined callback is defined to react on this.
template<typename T>
class Observable {
public:
@MarioLiebisch
MarioLiebisch / circletext.cpp
Last active May 12, 2018 16:54
A minimalistic example to print text in a circle using SFML. (Example output: https://i.imgur.com/2M2OURz.png)
#include <SFML/Graphics.hpp>
int main(int argc, char **argv) {
sf::RenderWindow window(sf::VideoMode(800, 600), "Circle Text", sf::Style::Default);
window.setVerticalSyncEnabled(true);
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Text text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut ultrices ante. Aliquam ornare eu enim eget accumsan.", font);