Skip to content

Instantly share code, notes, and snippets.

@micycle1
micycle1 / Triangle Wave Function
Last active November 17, 2018 21:23
Triangle Wave Function
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
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;
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);
@micycle1
micycle1 / ASCII Character Ramp.txt
Last active July 30, 2018 14:40
ASCII Character Ramp
"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:
" .:-=+*#%@"
@micycle1
micycle1 / example.java
Created October 24, 2018 11:46
Guava ArrayTable from int[]
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}
@micycle1
micycle1 / reflect.java
Created March 10, 2019 11:55
Reflecting Java instance methods with primitives
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);
@micycle1
micycle1 / a.md
Last active November 7, 2024 13:56
Downloading full-size media from DeviantArt

For direct image URL, the image quality is much lower than the original upload (the resolution and size of the original upload can be found in the right sidebar). This is not the case few years ago when the original image was accessible through right click, but on 2017, Wix acquired DeviantArt, and has been migrating the images to their own image hosting system from the original DeviantArt system. They linked most of the direct images to a stripped-down version of the original images; hence the bad image quality. Below are the three different formats of direct image URLs I found:

  • URL with /v1/fill inside: this means that the image went through Wix's encoding system and is modified to a specific size and quality. In this case, you remove ?token= and its values, add /intermediary in front of /f/ in the URL, and change the image settings right after /v1/fill/ to w_5100,h_5100,bl,q_100. The definitions of the values can be found in [Wix's Image Service](https://support.wi
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;
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:
@micycle1
micycle1 / clonePGraphics.java
Created January 4, 2021 19:00
Code to clone PGraphics via reflection
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;