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 / 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 / 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()
// 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 / 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;
@andrew-wilkes
andrew-wilkes / spiral.shader
Last active December 9, 2022 02:04
godot spiral shader
shader_type canvas_item;
const float PI = 3.14159265358979323846;
const float w = 0.1; // Width of line
void fragment() {
float dis = 0.1; // Displacement (spacing) of lines
// Get an angle value around a circle of 0.0 .. 1.0
vec2 pt = (UV - vec2(0.5)) * 2.0; // +/-1.0
@andrew-wilkes
andrew-wilkes / rgb-to-hsv.gd
Last active November 22, 2022 11:25
GDScript function to convert RGB color to HSV values
# I/O values are in the range 0.0 .. 1.0
func rgb_to_hsv(c: Color):
var M: float = rgb.max()
var m: float = rgb.min()
var v = M
var s = 0.0 if M < 0.001 else 1.0 - m / M
var h = (c.r - c.g / 2.0 - c.b / 2.0) / sqrt(c.r*c.r + c.g*c.g + c.b*c.b - c.r*c.g - c.r*c.b - c.g*c.b)
return { h=h, s=s, v=v }
@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 / collatz.gd
Created March 12, 2022 09:53
Collatz conjecture 3n + 1 code
extends Node2D
# Has a Line2D child node to plot a curve using each number of the series that tends to 1
const XSTEP = 10
var x = 0
func _ready():
calc(211)