はんぎょねこの憂鬱

耳から変な汁が出てきた

Node Graphでテクスチャ生成

f:id:dungeonneko:20150630230337p:plain

Substance買うお金無い

Python

# conding: utf-8
import math
from PIL import Image

PI = 3.1415926536

# 正弦
class Sin:
    def __init__(self, in_x):
        self.x = in_x
    def __call__(self):
        return math.sin(self.x())

# 余弦
class Cos:
    def __init__(self, in_x):
        self.x = in_x
    def __call__(self):
        return math.cos(self.x())

# 最大
class Max:
    def __init__(self, in_x, in_y):
        self.x = in_x
        self.y = in_y
    def __call__(self):
        x = self.x()
        y = self.y()
        return x if x >= y else y

# 束縛
class Const:
    def __init__(self, in_value):
        self.value = in_value
    def __call__(self):
        return self.value

# 加算
class Add:
    def __init__(self, in_x, in_y):
        self.x = in_x
        self.y = in_y
    def __call__(self):
        return self.x() + self.y()

# 減算
class Sub:
    def __init__(self, in_x, in_y):
        self.x = in_x
        self.y = in_y
    def __call__(self):
        return self.x() - self.y()

# 乗算
class Mul:
    def __init__(self, in_x, in_y):
        self.x = in_x
        self.y = in_y
    def __call__(self):
        return self.x() * self.y()

img = Image.new("L", (256, 256))
p = img.load()
for y in range(256):
    for x in range(256):
        u = Const(x / 256.0)
        v = Const(1.0 - (y / 256.0))
        r  = Const(2.0 * PI * -0.02)
        s = Sub(Mul(u, Cos(r)), Mul(v, Sin(r)))
        t = Add(Mul(v, Cos(r)), Mul(u, Sin(r)))
        freq = Const(2.0 * PI * 10.0)
        lhs = Cos(Mul(s, freq))
        rhs = Cos(Mul(t, freq))
        F = Max(lhs, rhs)
        p[ x, y ] = int(F() * 255)
img.show()