0% found this document useful (0 votes)
11 views3 pages

Ascii - Pattern - Generator Qudwduuwfwufidii

The document is a Lua script that generates various ASCII art patterns, including sine waves, spirals, Mandelbrot-inspired designs, and diamonds. It configures the canvas size and utilizes mathematical functions to create each pattern. Additionally, it provides random statistics and fun facts related to computing and ASCII art.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Ascii - Pattern - Generator Qudwduuwfwufidii

The document is a Lua script that generates various ASCII art patterns, including sine waves, spirals, Mandelbrot-inspired designs, and diamonds. It configures the canvas size and utilizes mathematical functions to create each pattern. Additionally, it provides random statistics and fun facts related to computing and ASCII art.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

-- ASCII Pattern Generator

-- Creates various mathematical patterns using ASCII characters

math.randomseed(os.time())

-- Configuration
local width = 60
local height = 20
local patterns = {"wave", "spiral", "mandelbrot", "diamond"}

-- Function to create a sine wave pattern


function create_wave_pattern(w, h)
print("=== SINE WAVE PATTERN ===")
for y = 1, h do
local line = ""
for x = 1, w do
local wave = math.sin((x / w) * math.pi * 4) * (h / 4) + (h / 2)
if math.abs(y - wave) < 1.5 then
line = line .. "*"
else
line = line .. " "
end
end
print(line)
end
print()
end

-- Function to create a spiral pattern


function create_spiral_pattern(w, h)
print("=== SPIRAL PATTERN ===")
local grid = {}
for y = 1, h do
grid[y] = {}
for x = 1, w do
grid[y][x] = " "
end
end

local cx, cy = w / 2, h / 2
for i = 0, 100 do
local angle = i * 0.3
local radius = i * 0.3
local x = math.floor(cx + radius * math.cos(angle))
local y = math.floor(cy + radius * math.sin(angle))

if x >= 1 and x <= w and y >= 1 and y <= h then


grid[y][x] = "#"
end
end

for y = 1, h do
local line = ""
for x = 1, w do
line = line .. grid[y][x]
end
print(line)
end
print()
end

-- Function to create a simple Mandelbrot-inspired pattern


function create_mandelbrot_pattern(w, h)
print("=== MANDELBROT-INSPIRED PATTERN ===")
for y = 1, h do
local line = ""
for x = 1, w do
local zx = (x - w/2) / (w/4)
local zy = (y - h/2) / (h/4)
local iterations = 0
local max_iter = 20

local cx, cy = zx, zy


while (zx*zx + zy*zy < 4 and iterations < max_iter) do
local temp = zx*zx - zy*zy + cx
zy = 2*zx*zy + cy
zx = temp
iterations = iterations + 1
end

if iterations == max_iter then


line = line .. "@"
elseif iterations > 10 then
line = line .. "#"
elseif iterations > 5 then
line = line .. "+"
else
line = line .. "."
end
end
print(line)
end
print()
end

-- Function to create a diamond pattern


function create_diamond_pattern(w, h)
print("=== DIAMOND PATTERN ===")
for y = 1, h do
local line = ""
for x = 1, w do
local dx = math.abs(x - w/2)
local dy = math.abs(y - h/2)
local distance = dx + dy

if distance < h/3 then


if (x + y) % 2 == 0 then
line = line .. "◊"
else
line = line .. "○"
end
else
line = line .. " "
end
end
print(line)
end
print()
end

-- Function to generate a random color code (for terminals that support it)
function get_random_color()
local colors = {31, 32, 33, 34, 35, 36, 37} -- ANSI color codes
return colors[math.random(#colors)]
end

-- Main execution
print("🎨 ASCII Pattern Generator 🎨")
print("Generating " .. #patterns .. " different patterns...\n")

-- Generate all patterns


create_wave_pattern(width, height)
create_spiral_pattern(width, height)
create_mandelbrot_pattern(width, height)
create_diamond_pattern(width, height)

-- Generate a random text art title


print("=== RANDOM STATS ===")
print("Canvas size: " .. width .. "x" .. height)
print("Patterns generated: " .. #patterns)
print("Random number: " .. math.random(1, 1000))
print("Timestamp: " .. os.date("%Y-%m-%d %H:%M:%S"))

-- Fun fact generator


local facts = {
"The first computer bug was an actual bug found in a computer in 1947!",
"Lua was created in Brazil and means 'moon' in Portuguese.",
"ASCII art has been around since the 1960s.",
"The @ symbol is called an 'arobase' in French.",
"Mathematical patterns appear everywhere in nature!"
}

print("Random fact: " .. facts[math.random(#facts)])


print("\n✨ Pattern generation complete! ✨")

You might also like