Skip to content

Instantly share code, notes, and snippets.

import { Button, VerticalBox, SpinBox, HorizontalBox, LineEdit} from "std-widgets.slint";
component CharacterStat inherits Rectangle {
in property<string> statname: "???";
in property<int> value: 12;
HorizontalLayout {
alignment: stretch;
Text { text: "\{statname}"; }
LineEdit {
text: "\{value}";
@joeld42
joeld42 / emit_parts.cpp
Last active August 16, 2021 20:01
number of particles to emit for a given rate
size_t EmitterNode::_numPartsForRate(float rate, float dt) {// number of parts to emit
size_t numParts = 0;
float numPartsReal = rate * dt;
// Treat fractional particles as a probability -- e.g. .3 particles
// means 30% chance to emit
float numPartsF = floor(numPartsReal);
float partProb = numPartsReal - numPartsF;
numParts = (size_t)numPartsF;
@joeld42
joeld42 / bumpme
Last active November 19, 2020 07:31
Thu Nov 19 07:31:12 UTC 2020
@joeld42
joeld42 / thread.cpp
Created April 8, 2019 17:30
Example threading in c++
// c++ -std=c++11 thread.cpp -o thread && ./thread
#include <iostream>
#include <algorithm>
#include <vector>
#include <thread>
class TraceTile
{
public:
int tileNum = 0;
@joeld42
joeld42 / cgincWatcher.py
Created October 26, 2018 19:58
cginclude watcher script for editing unity shaders
#!/usr/bin/env python
# CGInclude Watcher
# Joel Davis (joeld42@gmail.com, @joeld42 on Twitter)
#
# Usage: Run this from a directory where you have shaders.
#
# Use at your own risk (and use an editor that properly handles
# open files being modified by another program).
#
@joeld42
joeld42 / raygui_mouse.c
Created August 17, 2018 21:14
RayGUI Mouse Events
bool g_isMouseDown;
float g_mouseButtonPrevPressTime;
float g_mouseButtonLastPressTime;
Vector2 g_mouseDownPos;
Vector2 g_mousePos;
bool g_isDragging = false;
// Frame mouse events
bool _isDragStarted = false;
@joeld42
joeld42 / k_means.py
Created November 15, 2017 06:54
Simple brute-force k-means palette quantization
# Slow, bad K-Means image quantization.
# This code is in the public domain.
import os, sys
import random
from PIL import Image, ImageDraw
# Doesn't seem to get much better after this, YMMV...
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/Headers/FSEvents.h
@joeld42
joeld42 / gist:4a5978c12fcbe26af5dc5d9bab344ab1
Created April 11, 2017 21:10
How to make a console for printfs in windows....
#ifndef NDEBUG
AllocConsole();
SetConsoleTitle( L"console window title" );
freopen("CONOUT$", "w", stdout );
#endif
@joeld42
joeld42 / TK_FootStepController.cs
Created August 23, 2016 05:34
Simple Footstep controller for mechscale game
using UnityEngine;
using System;
using System.Collections;
// This moves a node to follow "stepGoal" in a foot step like manner. stepGoal is
// typically an empty parented to your model that sits on the ground and is offset (left
// or right) from the center of mass.
// This just moves the foot, a separate IK controller is needed to follow wiht the legs