Skip to content

Instantly share code, notes, and snippets.

View andrew-wilkes's full-sized avatar

Andrew Wilkes andrew-wilkes

View GitHub Profile
@andrew-wilkes
andrew-wilkes / prime-numbers.gd
Created July 11, 2021 08:00
Prime Numbers with GDScript
extends Node2D
export var nmax = 300
func _ready():
# Find prime numbers
sieve_of_eratosthenes(nmax)
func sieve_of_eratosthenes(n: int):
@andrew-wilkes
andrew-wilkes / assembler-6502.gd
Created March 25, 2024 13:13
6502 Assembler Code
func process_lines_pass1(lines):
var addr = 0
var line_num = 0
for line in lines:
line_num += 1
var label = ""
var directive = ""
var op_code = -1
var op_token = ""
var no_comment_line = remove_comment(line, ";")
@andrew-wilkes
andrew-wilkes / audio.gd
Created September 2, 2022 04:43
Audio File Parser
class_name Audio
var player: AudioStreamPlayer
var info
func _init(audio_player_instance):
player = audio_player_instance
func load_data(path: String):
@andrew-wilkes
andrew-wilkes / flip-speed.gd
Created October 15, 2023 14:08
Godot Speed Testing
extends Control
# Code to flip between 0 and 1 speed comparisons
func _ready():
const MILLION = 1_000_000
var start = Time.get_ticks_msec()
var x = 1
for n in MILLION:
@andrew-wilkes
andrew-wilkes / quit.gd
Created August 20, 2023 10:02
Godot Quit Request Capture
func _notification(what):
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
if not Input.is_key_pressed(KEY_F8):
get_tree().quit()
@andrew-wilkes
andrew-wilkes / circular-progress.shader
Created January 16, 2020 11:41
Circular Progress Shader in Godot Engine
shader_type canvas_item;
uniform float value: hint_range(0, 100); // %
uniform float thickness: hint_range(0, 100) = 30.; // % thickness
uniform sampler2D fg: hint_albedo;
uniform sampler2D bg: hint_black_albedo;
uniform float offset: hint_range(0, 100); // %
uniform float smoothing: hint_range(0, 100) = 5.;
void fragment() {
// https://www.shadertoy.com/view/lslSR7
shader_type canvas_item;
vec3 hsv(float h,float s,float v) {
return mix(vec3(1.),clamp((abs(fract(h+vec3(3.,2.,1.)/3.)*6.-3.)-1.),0.,1.),s)*v;
}
float circle(vec2 p, float r) {
return smoothstep(0.1, 0.0, abs(length(p)-r)); // try changing the 0.1 to 0.3
}
void fragment() {
@andrew-wilkes
andrew-wilkes / tunnel.php
Created March 20, 2021 11:18
PHP Script to Start and Stop a Reverse SSH Tunnel from a Remote Server
<?php
/*
This script is placed on a server or computer that remains powered up and is run via a
crontab job at regular intervals to ensure that the reverse SSH tunnel that it creates
remains active or gets killed according to the text value contained in a file on a remote
server that tells it whether to start or kill the process.
That file contains "on" or "off" text that is accessible via a URL.
On that server, the user should be able to SSH to it and change the command value in the file.
@andrew-wilkes
andrew-wilkes / sudoku-puzzle-extraction.gd
Created April 1, 2023 11:45
Godot 4 code to extract sudoku puzzle from html table
extends Control
func _on_button_pressed():
var html: String = $Src.text
# Find start of table
var idx1 = html.find("boardtable")
if idx1 > 0:
var idx2 = html.find("</table", idx1)
if idx2 > 0:
var table = html.substr(idx1, idx2 - idx1)
@andrew-wilkes
andrew-wilkes / equirectangular.gdshader
Last active December 30, 2022 12:04
Equirectangular Shader in Godot
// This shader creates a 2D image that may be used as a Equirectangular panorama background
// It creates fairly evenly spread stars (blobs) on a black background
// Todo: randomly modulate the positions via theta and radius
shader_type canvas_item;
uniform float samples = 1000.0;
void fragment() {
// Project from plane onto a sphere
float phi = PI * UV.y;