Skip to content

Instantly share code, notes, and snippets.

View pmark's full-sized avatar

P. Mark Anderson pmark

View GitHub Profile
@pmark
pmark / RenderCounterModifier.swift
Created May 3, 2023 23:00
RenderCounterModifier
/**
USAGE
someView.renderCounter()
*/
import SwiftUI
struct RenderCounterModifier: ViewModifier {
@State private var renderCount: Int = 0
@pmark
pmark / OnRenderViewModifier
Created May 3, 2023 20:45
SwiftUI .onRender view modifier
/*
USAGE
struct ContentView: View {
var body: some View {
Text("Hello, World!")
.onRender {
print("View rendered or updated")
}
}
@pmark
pmark / DesignTokenDSL.ts
Last active March 8, 2023 06:46
A Figma API client for declaratively automating design token style sync and docs
class FigmaFile {
private fileId: string;
constructor(fileId: string) {
this.fileId = fileId;
}
async getColors(): Promise<FigmaColor[]> {
const response = await fetch(`https://api.figma.com/v1/files/${this.fileId}/`);
const json = await response.json();
@pmark
pmark / Level.swift
Last active March 6, 2023 00:14
OctopusKit 2D game with data driven tile maps
import Foundation
import SpriteKit
class Level {
let tileSet: SKTileSet
let mapSize: CGSize
let tileSize: CGSize
let tileData: [[Int]]
init(jsonData: Data) throws {
@pmark
pmark / water-shader.metal
Created March 5, 2023 17:19
Metal water
// https://twitter.com/zozuar/status/1632160439944478721?s=42&t=kZ3wyx2jn4JBuVn3WNWeYQ
fragment float4 waterShader(const VertexOut vertexOut [[stage_in]],
constant Uniforms& uniforms [[buffer(0)]]) {
float height, iteration, amplitude, waveLength, xCoord, globalWaveHeight;
// Initialize variables
height = vertexOut.position.y;
iteration = 0.0;
@pmark
pmark / design-tokens.d.ts
Created March 2, 2023 01:14
DesignToken theme TS type
const lightThemeTokens = {
colorPrimary: '#007bff',
colorSecondary: '#6c757d',
fontSizeSmall: '12px',
fontSizeMedium: '16px',
};
const darkThemeTokens = {
colorPrimary: '#61dafb',
colorSecondary: '#c9c9c9',
@pmark
pmark / GameWorld.swift
Last active March 2, 2023 16:39
DSL for game world and level declaration
class GameWorld {
var systems: [System] = []
var entities: [Entity] = []
var terrain: Terrain?
var level: Level?
var player: Player?
// Add a system to the game world
func addSystem(_ system: System) {
systems.append(system)
@pmark
pmark / warp-geometry-shader.metal
Created December 30, 2020 14:45
Geometry shader modifier: warp effect
_geometry.position.xz += _geometry.position.xz
* sin(1.0 * _geometry.position.y + 1 * u_time) * 0.05
* (u_time < 3.0 ? u_time / 3.0 : 1.0);
@pmark
pmark / grid-surface-shader.metal
Last active December 30, 2020 14:45
Surface shader modifier: grid effect
float u = _surface.diffuseTexcoord.x;
float v = _surface.diffuseTexcoord.y;
int u100 = int(u * 100.0);
int v100 = int(v * 100.0);
if (u100 % 2 == 1 || v100 % 2 == 1) {
// do nothing
} else {
discard_fragment();

Keybase proof

I hereby claim:

  • I am pmark on github.
  • I am pmark (https://keybase.io/pmark) on keybase.
  • I have a public key whose fingerprint is 7CC0 475C 36C8 1053 9F08 8117 1BE3 1439 87A7 B197

To claim this, I am signing this object: