Skip to content

Instantly share code, notes, and snippets.

View t-karcher's full-sized avatar

Thomas Karcher t-karcher

View GitHub Profile
@t-karcher
t-karcher / curved_fragment.shader
Last active August 24, 2023 15:08
Godot shader bending a flat 2d world (e.g. a platformer) to a tiny planet.
shader_type canvas_item;
uniform sampler2D screen_texture : hint_screen_texture, filter_nearest;
uniform float radius = 3.0;
void fragment() {
vec2 uv = SCREEN_UV;
uv.y = 1.0 - uv.y; // seems like the origin changed in Godot 4.
vec2 surface = vec2(0.5, 0.2);
vec2 center = surface - vec2(0, radius);
@t-karcher
t-karcher / LineEdit.gd
Created May 5, 2020 05:32
Filters out characters from input in LineEdit using a RegExp pattern of allowed characters
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 October 4, 2023 13:42
GDScipt function converting a floating point number to a string in scientific notation
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