-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.py
More file actions
35 lines (28 loc) · 867 Bytes
/
texture.py
File metadata and controls
35 lines (28 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from math import sin
from vec3 import Vec3
from perlin import Perlin
class Texture:
## def __init__(self, color):
## self.color = color
def value(self, u, v, p):
return Vec3(0, 0, 0)
class ConstantTexture(Texture):
def __init__(self, color):
self.color = color
def value(self, u, v, p):
return self.color
class CheckerTexture(Texture):
def __init__(self, t0, t1):
self.t0 = t0
self.t1 = t1
def value(self, u, v, p):
sines = sin(10*p.x) * sin(10*p.y) * sin(10*p.z)
if sines < 0:
return self.t0.value(u, v, p)
return self.t1.value(u, v, p)
class NoiseTexture(Texture):
def __init__(self):
self.color = Vec3(1,1,1)
def value(self, u, v, p):
noise = Perlin.noise(p)
return noise*Vec3(1,1,1)