Skip to content

Instantly share code, notes, and snippets.

@behreajj
behreajj / cube_sphere.py
Last active July 14, 2023 00:49
Cube Sphere Initial
import bpy
from math import cos, sin, pi
import colorsys
from random import TWOPI
# Center of sphere.
x_center = 0.0
y_center = 0.0
z_center = 0.0
@behreajj
behreajj / sampler_full.py
Created May 29, 2018 23:07
Sampler Full
import bpy
from math import cos, sin, fmod
from random import TWOPI
def append_group_inst(nodes, group_name, data=bpy.data, group_creation_func=None, use_fake_user=False, parent=None, custom_color=None):
group = None
try:
group = data.node_groups[group_name]
except IndexError:
@behreajj
behreajj / bmesh_tut_18_convex_hull_fib_sphere.py
Created July 26, 2020 13:26
Fibonacci Sphere Convex Hull
from bpy import data as D, context as C
import bmesh
import math
def fibonacci_points(count=32, radius=0.5):
"""
Distributes points on a sphere according to
the golden ratio, (1.0 + sqrt(5.0)) / 2.0.
"""
@behreajj
behreajj / classTemplate.lua
Created March 2, 2021 04:54
Lua Class Template
Vec2 = {}
Vec2.__index = Vec2
-- Allow Vec2(3, 4) without new.
setmetatable(Vec2, {
__call = function (cls, ...)
return cls.new(...)
end})
function Vec2.new(x, y)
@behreajj
behreajj / cube_grid_initial.py
Created May 10, 2021 05:27
Cube Grid Initial
import bpy
# Number of cubes on each axis.
count = 7
# Range used with for-loops.
count_range = range(0, count, 1)
# Size of grid.
extents = 2.0
@behreajj
behreajj / vec2round.lua
Last active June 24, 2022 20:43
Vec2 Rounding
---Rounds a vector according to its sign.
---@param a table left operand
---@return table
function Vec2.round(a)
local iy, fy = math.modf(a.y)
if iy <= 0.0 and fy <= -0.5 then iy = iy - 1
elseif iy >= 0.0 and fy >= 0.5 then iy = iy + 1 end
local ix, fx = math.modf(a.x)
if ix <= 0.0 and fx <= -0.5 then ix = ix - 1
@behreajj
behreajj / helloWorld3.lua
Last active May 8, 2022 00:01
Hello World: Pixel Level
local dlg = Dialog { title = "Hello World!" }
dlg:check {
id = "cw",
label = "Chirality: ",
text = "Flip y axis.",
selected = false
}
dlg:button {
@behreajj
behreajj / perceptualTransform2.cs
Created November 10, 2021 20:58
Perceptual Transforms, Cont.
static Vector4 LinearToXyz (in Color c)
{
// This could also be written as matrix-vector multiplication.
// Perceptual luminance is the y component.
return new Vector4 (
0.41241086f * c.r + 0.35758457f * c.g + 0.1804538f * c.b,
0.21264935f * c.r + 0.71516913f * c.g + 0.07218152f * c.b,
0.019331759f * c.r + 0.11919486f * c.g + 0.95039004f * c.b,
c.a);
}
@behreajj
behreajj / lutGen.cs
Created November 10, 2021 04:21
Linear Gamma Luts
byte[ ] stlLut = new byte[256];
byte[ ] ltsLut = new byte[256];
for (int i = 0; i < 256; ++i)
{
float x = i / 255.0f;
float y = StandardToLinearChannel (x);
stlLut[i] = (byte) (0.5f + 255.0f * y);
float z = LinearToStandardChannel (x);
ltsLut[i] = (byte) (0.5f + 255.0f * z);
@behreajj
behreajj / Grayscale.cs
Last active November 10, 2021 03:41
Unity Grayscale Setup
using UnityEngine;
[RequireComponent (typeof (SpriteRenderer))]
public class Grayscale : MonoBehaviour
{
void Start ( )
{
SpriteRenderer renderer = GetComponent<SpriteRenderer> ( );
Sprite sprite = renderer.sprite;
Texture2D srcTexture = sprite.texture;