Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Karcher t-karcher

  • Munich, Germany
View GitHub Profile
@t-karcher
t-karcher / curved_fragment.shader
Created Nov 9, 2020
Godot shader bending a flat 2d world (e.g. a platformer) to a tiny planet.
View curved_fragment.shader
shader_type canvas_item;
uniform float radius = 3.0;
void fragment() {
vec2 uv = SCREEN_UV;
vec2 surface = vec2(0.5, 0.2);
vec2 center = surface - vec2(0, radius);
float base = length(uv - center);
float height = base - radius;
@t-karcher
t-karcher / LineEdit.gd
Created May 5, 2020
Filters out characters from input in LineEdit using a RegExp pattern of allowed characters
View LineEdit.gd
extends LineEdit
var allowed_characters = "[A-Za-z]"
func _on_LineEdit_text_changed(new_text):
var old_caret_position = self.caret_position
var word = ''
var regex = RegEx.new()
regex.compile(allowed_characters)
@t-karcher
t-karcher / scientific_notation.gd
Last active Sep 1, 2020
GDScipt function converting a floating point number to a string in scientific notation
View scientific_notation.gd
func test_output():
print (get_scientific_notation(123456789.0, 0)) # 1e8
print (get_scientific_notation(123456789.0, 1)) # 1.2e8
print (get_scientific_notation(123456789.0)) # 1.2345678e8
print (get_scientific_notation(0.123456789, 0)) # 1e-1
print (get_scientific_notation(0.123456789, 1)) # 1.2e-1
print (get_scientific_notation(0.123456789)) # 1.2345678e-1
print (get_scientific_notation(12345, 0, true)) # 12e3
print (get_scientific_notation(1234567, 0, true)) # 1e6
print (get_scientific_notation(123456789, 0, true)) # 123e6