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 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 |
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 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: |
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
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. | |
""" |
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
Vec2 = {} | |
Vec2.__index = Vec2 | |
-- Allow Vec2(3, 4) without new. | |
setmetatable(Vec2, { | |
__call = function (cls, ...) | |
return cls.new(...) | |
end}) | |
function Vec2.new(x, y) |
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 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 |
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
---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 |
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
local dlg = Dialog { title = "Hello World!" } | |
dlg:check { | |
id = "cw", | |
label = "Chirality: ", | |
text = "Flip y axis.", | |
selected = false | |
} | |
dlg:button { |
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 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); | |
} |
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
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); |
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
using UnityEngine; | |
[RequireComponent (typeof (SpriteRenderer))] | |
public class Grayscale : MonoBehaviour | |
{ | |
void Start ( ) | |
{ | |
SpriteRenderer renderer = GetComponent<SpriteRenderer> ( ); | |
Sprite sprite = renderer.sprite; | |
Texture2D srcTexture = sprite.texture; |
NewerOlder