Lab - 10
# Import required libraries
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from PIL import Image, ImageDraw
# 1. Rendering a Simple 2D Scene
def render_2d_scene():
    plt.figure(figsize=(6, 6))
    plt.fill([1, 3, 5], [1, 4, 1], color='brown') # House
    plt.fill([3, 3.5, 2.5], [4, 6, 6], color='red') # Roof
    plt.plot(6, 6, marker='o', markersize=20, color='yellow')   # Sun
    plt.axis('off')
    plt.title("2D Rendering Example")
    plt.show()
# 2. Exploring 3D Rendering
def render_3d_cube():
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    # Cube coordinates
    x = [0, 0, 1, 1, 0, 0, 1, 1]
    y = [0, 1, 1, 0, 0, 1, 1, 0]
   z = [0, 0, 0, 0, 1, 1, 1, 1]
   # Cube faces
   ax.plot_trisurf(x, y, z, color='cyan', alpha=0.7)
   ax.set_title("3D Cube Rendering")
   plt.show()
# 3. Shading and Texturing Techniques
def render_textured_circle():
    img = Image.new('RGB', (200, 200), 'white')
    draw = ImageDraw.Draw(img)
    draw.ellipse((50, 50, 150, 150), fill='blue', outline='black')
    draw.line((50, 100, 150, 100), fill='yellow', width=5)
    plt.imshow(img)
    plt.axis('off')
    plt.title("Textured Circle")
    plt.show()
def render_gradient():
    width, height = 200, 200
    gradient = np.zeros((height, width, 3), dtype=np.uint8)
   for y in range(height):
       for x in range(width):
           gradient[y, x] = (x % 255, y % 255, 128)   # RGB gradient
   gradient_img = Image.fromarray(gradient)
   plt.imshow(gradient_img)
   plt.axis('off')
   plt.title("Gradient Example")
   plt.show()
def render_combined_texture_gradient():
    width, height = 200, 200
    gradient = np.zeros((height, width, 3), dtype=np.uint8)
    for y in range(height):
        for x in range(width):
            gradient[y, x] = (x % 255, y % 255, 128) # RGB gradient
   gradient_img = Image.fromarray(gradient)
   draw = ImageDraw.Draw(gradient_img)
   for i in range(0, 200, 20):
       draw.line([(i, 0), (i, 200)], fill='white', width=2)
   plt.imshow(gradient_img)
   plt.axis('off')
   plt.title("Combined Texture and Gradient")
   plt.show()
# Main Function to Run Examples
if __name__ == "__main__":
    render_2d_scene()
    render_3d_cube()
    render_textured_circle()
    render_gradient()
    render_combined_texture_gradient()