Skip to content

Commit

Permalink
Apply ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janbridley committed May 28, 2024
1 parent 1b13c5e commit fa70464
Show file tree
Hide file tree
Showing 28 changed files with 1,347 additions and 1,102 deletions.
77 changes: 39 additions & 38 deletions doc/gallery/cuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,50 @@
import sys
import os

data = numpy.load('cuboids.npz')
data = numpy.load("cuboids.npz")

scene = fresnel.Scene()
scene.lights = fresnel.light.lightbox()
W, H, D = data['width']
poly_info = fresnel.util.convex_polyhedron_from_vertices([
[-W, -H, -D],
[-W, -H, D],
[-W, H, -D],
[-W, H, D],
[W, -H, -D],
[W, -H, D],
[W, H, -D],
[W, H, D],
])

geometry = fresnel.geometry.ConvexPolyhedron(scene,
poly_info,
position=data['position'],
orientation=data['orientation'],
outline_width=0.015)
geometry.material = fresnel.material.Material(color=fresnel.color.linear(
[0.1, 0.1, 0.6]),
roughness=0.1,
specular=1)
geometry.outline_material = fresnel.material.Material(color=(0.95, 0.93, 0.88),
roughness=0.1,
metal=1.0)

scene.camera = fresnel.camera.Orthographic.fit(scene, view='front')

if 'CI' in os.environ:
W, H, D = data["width"]
poly_info = fresnel.util.convex_polyhedron_from_vertices(
[
[-W, -H, -D],
[-W, -H, D],
[-W, H, -D],
[-W, H, D],
[W, -H, -D],
[W, -H, D],
[W, H, -D],
[W, H, D],
]
)

geometry = fresnel.geometry.ConvexPolyhedron(
scene,
poly_info,
position=data["position"],
orientation=data["orientation"],
outline_width=0.015,
)
geometry.material = fresnel.material.Material(
color=fresnel.color.linear([0.1, 0.1, 0.6]), roughness=0.1, specular=1
)
geometry.outline_material = fresnel.material.Material(
color=(0.95, 0.93, 0.88), roughness=0.1, metal=1.0
)

scene.camera = fresnel.camera.Orthographic.fit(scene, view="front")

if "CI" in os.environ:
samples = 1
else:
samples = 64

out = fresnel.pathtrace(scene, samples=samples, light_samples=32, w=580, h=580)
PIL.Image.fromarray(out[:], mode='RGBA').save('cuboid.png')

if len(sys.argv) > 1 and sys.argv[1] == 'hires':
out = fresnel.pathtrace(scene,
samples=256,
light_samples=16,
w=1380,
h=1380)
PIL.Image.fromarray(out[:], mode='RGBA').save('cuboid-hires.png')
PIL.Image.fromarray(out[:], mode="RGBA").save("cuboid.png")

if len(sys.argv) > 1 and sys.argv[1] == "hires":
out = fresnel.pathtrace(
scene, samples=256, light_samples=16, w=1380, h=1380
)
PIL.Image.fromarray(out[:], mode="RGBA").save("cuboid-hires.png")
79 changes: 42 additions & 37 deletions doc/gallery/gumballs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@

"""Gumballs example scene."""

import fresnel
import os
import sys

import numpy as np
from matplotlib.colors import LinearSegmentedColormap
import PIL
import sys
import os
from matplotlib.colors import LinearSegmentedColormap

import fresnel

# First, we create a color map for gumballs.
colors = [
'#e56d60',
'#ee9944',
'#716e80',
'#eadecd',
'#cec746',
'#c0443f',
'#734d56',
'#5d5f7b',
'#ecb642',
'#8a9441',
"#e56d60",
"#ee9944",
"#716e80",
"#eadecd",
"#cec746",
"#c0443f",
"#734d56",
"#5d5f7b",
"#ecb642",
"#8a9441",
]
cmap = LinearSegmentedColormap.from_list(name='gumball',
colors=colors,
N=len(colors))
cmap = LinearSegmentedColormap.from_list(
name="gumball", colors=colors, N=len(colors)
)

rng = np.random.default_rng(123)


# Next, we gather information needed for the geometry.
position = np.load('gumballs.npz')['position']
np.random.seed(123)
color = fresnel.color.linear(cmap(np.random.rand(len(position))))
position = np.load("gumballs.npz")["position"]
color = fresnel.color.linear(cmap(rng.random(len(position))))
material = fresnel.material.Material(
primitive_color_mix=1.0,
roughness=0.2,
Expand All @@ -49,31 +53,32 @@
)

# Configure camera and lighting.
scene.camera = fresnel.camera.Perspective(position=(0, 0, 25),
look_at=(0, 0, 0),
up=(0, 1, 0),
focal_length=0.5,
f_stop=0.25)
scene.camera = fresnel.camera.Perspective(
position=(0, 0, 25),
look_at=(0, 0, 0),
up=(0, 1, 0),
focal_length=0.5,
f_stop=0.25,
)
scene.camera.focus_on = (0, 0, 5.6)
scene.lights = fresnel.light.lightbox()
scene.lights.append(
fresnel.light.Light(direction=(0.3, -0.3, 1),
color=(0.5, 0.5, 0.5),
theta=np.pi))
fresnel.light.Light(
direction=(0.3, -0.3, 1), color=(0.5, 0.5, 0.5), theta=np.pi
)
)

if 'CI' in os.environ:
if "CI" in os.environ:
samples = 1
else:
samples = 128

# Execute rendering.
out = fresnel.pathtrace(scene, w=600, h=600, samples=samples, light_samples=64)
PIL.Image.fromarray(out[:], mode='RGBA').save('gumballs.png')
PIL.Image.fromarray(out[:], mode="RGBA").save("gumballs.png")

if len(sys.argv) > 1 and sys.argv[1] == 'hires':
out = fresnel.pathtrace(scene,
w=1500,
h=1500,
samples=256,
light_samples=64)
PIL.Image.fromarray(out[:], mode='RGBA').save('gumballs-hires.png')
if len(sys.argv) > 1 and sys.argv[1] == "hires":
out = fresnel.pathtrace(
scene, w=1500, h=1500, samples=256, light_samples=64
)
PIL.Image.fromarray(out[:], mode="RGBA").save("gumballs-hires.png")
34 changes: 15 additions & 19 deletions doc/gallery/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,31 @@
import sys
import os

data = numpy.load('spheres.npz')
data = numpy.load("spheres.npz")

scene = fresnel.Scene()
scene.lights = fresnel.light.cloudy()

geometry = fresnel.geometry.Sphere(scene,
position=data['position'],
radius=0.5,
outline_width=0.1)
geometry = fresnel.geometry.Sphere(
scene, position=data["position"], radius=0.5, outline_width=0.1
)

geometry.material = fresnel.material.Material(color=fresnel.color.linear(
[0.1, 0.8, 0.1]),
roughness=0.8,
specular=0.2)
geometry.material = fresnel.material.Material(
color=fresnel.color.linear([0.1, 0.8, 0.1]), roughness=0.8, specular=0.2
)

scene.camera = fresnel.camera.Orthographic.fit(scene)

if 'CI' in os.environ:
if "CI" in os.environ:
samples = 1
else:
samples = 64

out = fresnel.pathtrace(scene, samples=samples, light_samples=32, w=580, h=580)
PIL.Image.fromarray(out[:], mode='RGBA').save('sphere.png')

if len(sys.argv) > 1 and sys.argv[1] == 'hires':
out = fresnel.pathtrace(scene,
samples=256,
light_samples=16,
w=1380,
h=1380)
PIL.Image.fromarray(out[:], mode='RGBA').save('sphere-hires.png')
PIL.Image.fromarray(out[:], mode="RGBA").save("sphere.png")

if len(sys.argv) > 1 and sys.argv[1] == "hires":
out = fresnel.pathtrace(
scene, samples=256, light_samples=16, w=1380, h=1380
)
PIL.Image.fromarray(out[:], mode="RGBA").save("sphere-hires.png")
Loading

0 comments on commit fa70464

Please sign in to comment.