Skip to content

Instantly share code, notes, and snippets.

@Kojirion
Kojirion / SlidingConsole.cpp
Created July 30, 2016 09:47
Animating movement between two points with Thor - a SFML extension
#include <SFML/Graphics.hpp>
#include <Thor/Animations.hpp>
#include <Thor/Input.hpp>
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Widgets.hpp>
template <class Item>
void SetPosition(Item&, const sf::Vector2f&);
template <>
@Kojirion
Kojirion / genCMakeLists.py
Created March 25, 2016 00:08
Automatically generate CMakeLists.txt for a SFML project
from os import listdir
f = open("CMakeLists.txt", "w")
f.write(
"""project(Foo)
cmake_minimum_required(VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH \"${CMAKE_CURRENT_LIST_DIR}/cmake\")
find_package(SFML 2 REQUIRED graphics window system)
include_directories(${SFML_INCLUDE_DIR})\n\n""")
@Kojirion
Kojirion / buildSFThorGui.sh
Last active May 26, 2016 22:23
Bash script to build master branch of SFML, SFGUI and Thor libraries
function Build {
local buildType="$1"
mkdir -p $buildType/install
cd $buildType
cmake -DCMAKE_BUILD_TYPE=$buildType -DCMAKE_MODULE_PATH=$(pwd)../../../SFML/cmake/Modules/ -DSFML_ROOT=$(pwd)/../../../SFML/Builds/$buildType/install -DCMAKE_INSTALL_PREFIX=$(pwd)/install -DCMAKE_CXX_FLAGS=-std=c++14 ../..
make -j6 install
cd ..
}
function CloneAndBuild {
xi_star = 0.4
max_diameter = 4
def u(xi):
return xi_star - xi
def f1(xi):
return (1 / (xi + 0.1)) ** 2
@Kojirion
Kojirion / cholesky.py
Created October 8, 2014 01:03
Testing a cholesky factorisation C program through a python script
import subprocess
import pickle
SetupTime = []
FactorisationTime = []
TotalTime = []
ApproximateSolution = []
TrueSolution = 0.199268 # hardcoded
AbsoluteError = []
/*
Output:
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%)
0.000029s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%)
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%)
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%)
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%)
*/
@Kojirion
Kojirion / KnightSwap.cpp
Created April 5, 2014 12:51
Knight swap
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/join.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/phoenix.hpp>
#include <cstdint>
@Kojirion
Kojirion / shapes.cpp
Last active August 29, 2015 13:57
The separating axis algorithm for arbitrary sf::Shapes
#include <SFML/Graphics.hpp>
#include <cmath>
#include <vector>
#include <memory>
//Vector math functions
float dotProduct(const sf::Vector2f& lhs, const sf::Vector2f& rhs)
{
return lhs.x * rhs.x + lhs.y * rhs.y;
@Kojirion
Kojirion / permutations.cpp
Created January 19, 2014 11:51
Permutation API
typedef unsigned int Uint;
class Permutation {
public:
//construct identity of given order
explicit Permutation(Uint order);
//construct from init list
Permutation(std::initializer_list<Uint> list);
@Kojirion
Kojirion / problem55.cpp
Created November 25, 2013 01:54
Project Euler problem 55
#include <iostream>
#include <boost/timer/timer.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm/count_if.hpp>
#include <algorithm>
#include <gmpxx.h>
using boost::irange;
typedef mpz_class Int;