This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static double[] table = null; | |
static double step; | |
static double invStep; | |
static int size = 0; | |
static | |
{ | |
size = 10000; | |
table = new double[size]; | |
step = 2d * Math.PI / size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final class Riven { | |
private static final int SIN_BITS, SIN_MASK, SIN_COUNT; | |
private static final float radFull, radToIndex; | |
private static final float degFull, degToIndex; | |
private static final float[] sin, cos; | |
static { | |
SIN_BITS = 12; | |
SIN_MASK = ~(-1 << SIN_BITS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Standard" character ramp for grey scale pictures, black -> white: | |
"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'. " | |
A more convincing but shorter sequence for representing 10 levels of grey is: | |
" .:-=+*#%@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.collect.ArrayTable; | |
import com.google.common.collect.Table; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
int[] rows = new int[]{1,2,3} | |
int[] columns = new int[]{4,5,6,7} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function for triangle-wave y coordinate (oscillate between 0 and m). | |
y = m - abs(t % (2*m) - m) | |
Where: | |
y = output | |
m = max value (peak) | |
t = time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final Map<Class<?>, Class<?>> W2P; // wrapper to primitive | |
static { | |
W2P = new HashMap<>(); | |
W2P.put(Boolean.class, boolean.class); | |
W2P.put(Byte.class, byte.class); | |
W2P.put(Character.class, char.class); | |
W2P.put(Double.class, double.class); | |
W2P.put(Float.class, float.class); | |
W2P.put(Integer.class, int.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long pow2(long a, long b) { | |
long re = 1; | |
while (b > 0) { | |
if ((b & 1) == 1) { | |
re *= a; | |
} | |
b >>= 1; | |
a *= a; | |
} | |
return re; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stereopsis.com/2div.html | |
Ben and 2 Divides | |
Two years ago, Ben Weiss (the guy who wrote Kai's Power Tools, Goo, Soap, etc.) was telling me about this idea he had to combine two divides. I just didn't pay attention. | |
Luckily, he told me again. | |
Ben's idea is really simple, and I use it everywhere now. | |
2 divides at once | |
Suppose you want to compute: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static PGraphics cloneGraphics(PGraphics source) { | |
final String renderer; | |
switch (source.parent.sketchRenderer()) { | |
case "processing.opengl.PGraphics2D": | |
renderer = P2D; | |
break; | |
case "processing.opengl.PGraphics3D": | |
renderer = P3D; | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://momentsingraphics.de/CubicRoots.html#_Blinn06a | |
Returns the three real roots of the cubic polynomial (of form 1 + 2x + 3x^2 + 4x^3) | |
float3 SolveCubic(float4 Coefficient){ | |
// Normalize the polynomial | |
Coefficient.xyz/=Coefficient.w; | |
// Divide middle coefficients by three | |
Coefficient.yz/=3.0f; | |
// Compute the Hessian and the discrimant |
OlderNewer