Skip to content

Instantly share code, notes, and snippets.

Avatar
❤️
html canvas

Krab KrabCode

❤️
html canvas
View GitHub Profile
View ExampleSketch.java
import processing.core.PApplet;
public class ExampleSketch extends TransparentApplet{
public static void main(String[] args){
PApplet.main(java.lang.invoke.MethodHandles.lookup().lookupClass());
}
@Override
public void settings(){
View ShaderFeedbackDemo.pde
PShader feedbackShader;
float t;
void setup() {
size(1000, 1000, P2D);
background(0);
feedbackShader = loadShader("feedback.frag");
}
void draw() {
View SinewaveReferenceWithShadows.pde
int sketchWidth = 600;
int sketchHeight = 600;
int rulerWidth = 400;
int rulerHeight = 375;
float waveHeight = 200;
float waveHeightHalf = waveHeight / 2;
int xLeft = sketchWidth / 2 - rulerWidth / 2;
int xRight = sketchWidth / 2 + rulerWidth / 2;
View SinewaveReference.pde
import java.util.Date;
int sketchWidth = 600;
int sketchHeight = 600;
int rulerWidth = 400;
int rulerHeightOuter = 130;
float rulerHeightInner = 130;
float waveHeight = 200;
float waveHeightHalf = waveHeight / 2;
View SimpleHexagonGrid.pde
// see https://www.redblobgames.com/grids/hexagons/
float size = 1000/24;
float w = size*2;
float h = sqrt(3)*size;
float xStep = w*(3/4f);
float yStep = h;
int xCount;
int yCount;
@KrabCode
KrabCode / PowderToy.pde
Created Sep 13, 2021
Working powder toy with a simple material picker for APDE.
View PowderToy.pde
// Should work on APDE
// Based on a GDC talk called "Exploring the Tech and Design of Noita"
// https://www.youtube.com/watch?v=prXuyMCgbTc
private PGraphics pg;
float scale = 0.075f;
float prevScale = scale;
float rectWidth, rectHeight;
@KrabCode
KrabCode / NoitaPhysics.pde
Created Sep 11, 2021
sorry for misleading naming in "water", it behaves like sand instead
View NoitaPhysics.pde
float[][] grid;
float[][] temp;
float scale = 0.12;
int w, h;
boolean add = false;
float touchSize = 10;
void setup() {
fullScreen();
colorMode(HSB,1,1,1,1);
@KrabCode
KrabCode / blur.glsl
Created Sep 24, 2020
adjustable blur shader
View blur.glsl
// From the PostFX library for Processing, put this file into the data folder in the sketch folder
// Adapted from:
// <a href="http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html" target="_blank" rel="nofollow">http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html</a>
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
View redBall.pde
void setup() {
size(800, 800, P2D);
}
void draw() {
float t = radians(frameCount);
int detail = 50;
float whiteRadius = 150+150*sin(t);
float redRadius = 350;
background(0);
@KrabCode
KrabCode / LiveShader.pde
Created Aug 11, 2020
Reload shaders at runtime
View LiveShader.pde
import static java.lang.System.currentTimeMillis;
void setup() {
size(600, 600, P2D);
}
void draw() {
float t = radians(frameCount);
String testShader = "frag.glsl";
uniform(testShader).set("time", t);