Generate the twelve ribbon studies from analytic sphere intersections
This commit is contained in:
@@ -0,0 +1,417 @@
|
||||
[
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
0,
|
||||
0,
|
||||
19.7,
|
||||
0
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.95,
|
||||
0.1905
|
||||
],
|
||||
[
|
||||
-0.458,
|
||||
0.35
|
||||
],
|
||||
[
|
||||
0.2795,
|
||||
0.3775
|
||||
],
|
||||
[
|
||||
0.4815,
|
||||
0.4985
|
||||
],
|
||||
[
|
||||
0.87,
|
||||
0.24
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#eeb798",
|
||||
"0/2": "#8a8396",
|
||||
"0/3": "#ea8176",
|
||||
"0/4": "#bc8780",
|
||||
"0/5": "#826d7d",
|
||||
"1/0": "#9f9fad",
|
||||
"1/1": "#dbb6ad",
|
||||
"2/0": "#874564",
|
||||
"2/2": "#ac92a1",
|
||||
"3/0": "#82798c",
|
||||
"3/3": "#f3c2b6",
|
||||
"3/4": "#aeb2b7",
|
||||
"4/0": "#694f6e",
|
||||
"4/3": "#f08679",
|
||||
"4/4": "#56274a",
|
||||
"4/5": "#8a8398",
|
||||
"5/0": "#e7a990",
|
||||
"5/4": "#f8bd93",
|
||||
"5/5": "#f4cbb7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
-1.791,
|
||||
-32.186,
|
||||
0.07,
|
||||
-2.839
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-1.0594,
|
||||
0.4096
|
||||
],
|
||||
[
|
||||
-0.731,
|
||||
0.3594
|
||||
],
|
||||
[
|
||||
-0.3312,
|
||||
0.2787
|
||||
],
|
||||
[
|
||||
0.1514,
|
||||
0.2592
|
||||
],
|
||||
[
|
||||
0.6196,
|
||||
0.2753
|
||||
],
|
||||
[
|
||||
1.0483,
|
||||
0.4561
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/3": "#784e69",
|
||||
"0/4": "#8b6172",
|
||||
"0/5": "#7b4861",
|
||||
"0/6": "#693b58",
|
||||
"1/0": "#efb092",
|
||||
"1/2": "#ddaaa6",
|
||||
"1/3": "#eab8a3",
|
||||
"2/0": "#da7e77",
|
||||
"2/2": "#713b53",
|
||||
"2/3": "#d18e8c",
|
||||
"2/4": "#e9a59b",
|
||||
"3/0": "#e7a28a",
|
||||
"3/3": "#966776",
|
||||
"3/4": "#f6c4a7",
|
||||
"3/5": "#f6bfa2",
|
||||
"4/0": "#e88881",
|
||||
"4/4": "#ae6671",
|
||||
"4/5": "#e98a82",
|
||||
"4/6": "#f1988c",
|
||||
"5/0": "#cc938c",
|
||||
"5/5": "#b57a7f",
|
||||
"5/6": "#d79a8f"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
89.303,
|
||||
14.637,
|
||||
-1.031,
|
||||
11.417
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.5511,
|
||||
0.5986
|
||||
],
|
||||
[
|
||||
0.5624,
|
||||
0.5718
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#8b7c92",
|
||||
"0/2": "#af7b7e",
|
||||
"1/0": "#7f4366",
|
||||
"1/1": "#9c798e",
|
||||
"2/0": "#dac4b1",
|
||||
"2/2": "#dcb6a7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
-44.684,
|
||||
26.855,
|
||||
-1.6,
|
||||
2.652
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.8871,
|
||||
0.3778
|
||||
],
|
||||
[
|
||||
-0.2958,
|
||||
0.4983
|
||||
],
|
||||
[
|
||||
0.5552,
|
||||
0.665
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#f0b093",
|
||||
"0/2": "#91909e",
|
||||
"0/3": "#dca4a1",
|
||||
"1/1": "#f9c09b",
|
||||
"2/0": "#9ca0ab",
|
||||
"2/1": "#f7ceb7",
|
||||
"2/2": "#b6bcc6",
|
||||
"3/0": "#794c69",
|
||||
"3/2": "#b2a2ac",
|
||||
"3/3": "#e69c95"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
0,
|
||||
0,
|
||||
24.3,
|
||||
0
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.69,
|
||||
0.57
|
||||
],
|
||||
[
|
||||
0.7285,
|
||||
0.57
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#a7afb5",
|
||||
"0/2": "#80778c",
|
||||
"1/0": "#ef8275",
|
||||
"1/1": "#f9c7ba",
|
||||
"2/0": "#94536e",
|
||||
"2/2": "#b6a4ad"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
24.617,
|
||||
21.92,
|
||||
15.227,
|
||||
4.721
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.3092,
|
||||
0.9832
|
||||
],
|
||||
[
|
||||
0.6666,
|
||||
0.569
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#6f3d5c",
|
||||
"0/2": "#868495",
|
||||
"1/0": "#946176",
|
||||
"1/1": "#ea9187",
|
||||
"2/0": "#e4af94",
|
||||
"2/1": "#f6ba9f",
|
||||
"2/2": "#997b80"
|
||||
}
|
||||
},
|
||||
{
|
||||
"angles": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"bands": [],
|
||||
"mode": "petals",
|
||||
"inks": {
|
||||
"0/1": "#9a556e",
|
||||
"1/0": "#81798d",
|
||||
"1/1": "#b8a5b0",
|
||||
"0/2": "#ff9b81",
|
||||
"2/0": "#837d91",
|
||||
"2/2": "#ffd5b5",
|
||||
"0/3": "#a55f72",
|
||||
"3/0": "#ff8771",
|
||||
"3/3": "#ffa188"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
-0.899,
|
||||
9.985,
|
||||
-3.206,
|
||||
-0.452
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.8721,
|
||||
0.2916
|
||||
],
|
||||
[
|
||||
0.0183,
|
||||
0.5875
|
||||
],
|
||||
[
|
||||
0.9273,
|
||||
0.3999
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#f68b79",
|
||||
"0/2": "#9294a2",
|
||||
"1/1": "#eda58f",
|
||||
"2/0": "#90909f",
|
||||
"2/2": "#b9c5ca",
|
||||
"3/0": "#833c60",
|
||||
"3/3": "#a1506f"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
7.565,
|
||||
23.002,
|
||||
-9.66,
|
||||
12.642
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-1.0253,
|
||||
0.7238
|
||||
],
|
||||
[
|
||||
-0.0246,
|
||||
0.9293
|
||||
],
|
||||
[
|
||||
0.8626,
|
||||
0.5551
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#dcbeb2",
|
||||
"0/2": "#bb8d90",
|
||||
"1/1": "#beadb0",
|
||||
"2/0": "#5e3458",
|
||||
"2/1": "#9c8791",
|
||||
"2/2": "#d2b0ad",
|
||||
"3/0": "#5a375a",
|
||||
"3/2": "#765e78",
|
||||
"3/3": "#d9bdb1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
90.42,
|
||||
1.38,
|
||||
26.293,
|
||||
2.256
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.9005,
|
||||
0.3924
|
||||
],
|
||||
[
|
||||
0.0113,
|
||||
0.5277
|
||||
],
|
||||
[
|
||||
0.9205,
|
||||
0.3849
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#8f4b68",
|
||||
"0/2": "#f38778",
|
||||
"0/3": "#793057",
|
||||
"1/0": "#f29c83",
|
||||
"1/1": "#e1a78e",
|
||||
"2/0": "#9897a3",
|
||||
"2/2": "#f6c4b7",
|
||||
"3/0": "#f39d82",
|
||||
"3/3": "#edb79a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "bands",
|
||||
"angles": [
|
||||
-8.06,
|
||||
11.533,
|
||||
19.651,
|
||||
12.902
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
-0.8357,
|
||||
0.371
|
||||
],
|
||||
[
|
||||
0.0753,
|
||||
0.4804
|
||||
],
|
||||
[
|
||||
0.8661,
|
||||
0.3363
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"0/1": "#8d5b78",
|
||||
"0/2": "#f29c85",
|
||||
"0/3": "#998994",
|
||||
"1/0": "#867e94",
|
||||
"1/1": "#ad95a4",
|
||||
"2/0": "#62224d",
|
||||
"2/2": "#c4827f",
|
||||
"3/0": "#864255",
|
||||
"3/3": "#f7c8b2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"mode": "spiral",
|
||||
"angles": [
|
||||
8,
|
||||
3,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"bands": [
|
||||
[
|
||||
0.12,
|
||||
0.38
|
||||
]
|
||||
],
|
||||
"inks": {
|
||||
"1/0": "#ff967e",
|
||||
"2/0": "#a8babb",
|
||||
"3/0": "#a26d86",
|
||||
"0/1": "#7c526f",
|
||||
"0/2": "#98586e",
|
||||
"0/3": "#714561",
|
||||
"1/1": "#ffb58d",
|
||||
"1/2": "#ffb58d",
|
||||
"1/3": "#ffb58d",
|
||||
"2/1": "#bfd2c9",
|
||||
"2/2": "#bfd2c9",
|
||||
"2/3": "#bfd2c9",
|
||||
"3/1": "#ac8497",
|
||||
"3/2": "#ac8497",
|
||||
"3/3": "#ac8497"
|
||||
}
|
||||
}
|
||||
]
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
@@ -0,0 +1,93 @@
|
||||
"""Procedural ribbon shells. Run with --turn 20 to rotate every shell in depth."""
|
||||
import argparse
|
||||
import json
|
||||
from math import asin, atan2, cos, pi, radians, sin, sqrt
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import zlib
|
||||
|
||||
BG = (68, 23, 68)
|
||||
STYLE_FILE = Path(__file__).with_name("shell-styles.json")
|
||||
|
||||
|
||||
def make_shader(style, turn):
|
||||
roll, pitch, linear, quadratic = style["angles"]
|
||||
cr, sr = cos(radians(roll)), sin(radians(roll))
|
||||
cp, sp = cos(radians(pitch)), sin(radians(pitch))
|
||||
ct, st = cos(radians(turn)), sin(radians(turn))
|
||||
bands = style["bands"]
|
||||
palette = {tuple(map(int, pair.split("/"))): tuple(bytes.fromhex(ink[1:]))
|
||||
for pair, ink in style["inks"].items()}
|
||||
mode = style["mode"]
|
||||
|
||||
def band_at(u, v, w):
|
||||
if mode == "petals":
|
||||
for index, (a, b) in enumerate(((0, 1), (.8660254, -.5), (-.8660254, -.5)), 1):
|
||||
radial, tangent = a*u+b*v, b*u-a*v
|
||||
if radial + .72*w*tangent > .725:
|
||||
return index
|
||||
return 0
|
||||
if mode == "spiral":
|
||||
phase, width = bands[0]
|
||||
cycle = 3*(.5+asin(max(-1, min(1, v)))/pi) - atan2(w,u)/(2*pi) + phase
|
||||
return 1+round(cycle)%3 if abs(cycle-round(cycle)) < width/2 else 0
|
||||
angle = radians(linear*u + quadratic*(2*u*u-1))
|
||||
height = v*cos(angle) + w*sin(angle)
|
||||
for index, (centre, width) in enumerate(bands, 1):
|
||||
if abs(height-centre) <= width/2:
|
||||
return index
|
||||
return 0
|
||||
|
||||
def face(x, y, z):
|
||||
depth = st*x+ct*z
|
||||
return band_at(ct*x-st*z, cp*y+sp*depth, cp*depth-sp*y)
|
||||
|
||||
def pixel(x, y):
|
||||
d = 1-x*x-y*y
|
||||
if d <= 0:
|
||||
return BG
|
||||
z = sqrt(d)
|
||||
u, v = cr*x+sr*y, cr*y-sr*x
|
||||
front, back = face(u,v,z), face(u,v,-z)
|
||||
if not (front or back):
|
||||
return BG
|
||||
# Each pair of visible faces defines one ink mixture. New angles can
|
||||
# reveal pairs absent from the reference view.
|
||||
color = palette.get((front, back))
|
||||
if color is None:
|
||||
ink = palette.get((front, 0), palette.get((front, front), BG))
|
||||
rear = palette.get((0, back), palette.get((back, back), BG))
|
||||
color = tuple((f+r)/2 for f,r in zip(ink,rear)) if front and back else (ink if front else rear)
|
||||
light = 1+.045*(-x+y)/2
|
||||
return tuple(min(255,round(k*light)) for k in color)
|
||||
return pixel
|
||||
|
||||
|
||||
def sheet(turn, size=118, samples=3):
|
||||
gap = size//3
|
||||
width, height = 4*(size+gap)+gap, 3*(size+gap)+gap
|
||||
pixels = bytearray(bytes(BG)*width*height)
|
||||
for i, style in enumerate(json.loads(STYLE_FILE.read_text())):
|
||||
shade = make_shader(style, turn)
|
||||
left, top = gap+(i%4)*(size+gap), gap+(i//4)*(size+gap)
|
||||
for row in range(size):
|
||||
for col in range(size):
|
||||
colors = [shade(2*(col+(a+.5)/samples)/size-1,
|
||||
1-2*(row+(b+.5)/samples)/size)
|
||||
for a in range(samples) for b in range(samples)]
|
||||
start = 3*((top+row)*width+left+col)
|
||||
pixels[start:start+3] = bytes(round(sum(c)/len(colors)) for c in zip(*colors))
|
||||
def chunk(kind, data):
|
||||
return (struct.pack(">I", len(data))+kind+data+
|
||||
struct.pack(">I", zlib.crc32(kind+data)))
|
||||
scanlines = b"".join(b"\0"+pixels[i:i+3*width] for i in range(0,len(pixels),3*width))
|
||||
return (b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">2I5B",width,height,8,2,0,0,0))+
|
||||
chunk(b"IDAT",zlib.compress(scanlines,9))+chunk(b"IEND",b""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--turn", type=float, default=0)
|
||||
parser.add_argument("--output", type=Path, default=Path(__file__).with_suffix(".png"))
|
||||
options = parser.parse_args()
|
||||
options.output.write_bytes(sheet(options.turn))
|
||||
Reference in New Issue
Block a user