raycasting.lua

-- Raycasting
-- This generates a messy random blocking pattern, selects a random point
-- within it, and casts rays from that point to identify a 'visible' area.

local primitives   = require('forma.primitives')
local raycasting   = require("forma.raycasting")
local multipattern = require("forma.multipattern")

-- Generate a domain and a messy 'blocking' pattern
local domain = primitives.square(80, 20)
local blocks = domain:sample(100)
domain = domain - blocks

-- Cast rays in all direction from a random point in the domain
local traced = raycasting.cast_360(domain:rcell(), domain, 10)
multipattern.new({blocks, traced}):print({'#', '+'}, domain)
generated by LDoc 1.5.0 Last updated 2025-03-12 19:36:11