From f802ad40ca7ab85367346722466936f5f65e7189 Mon Sep 17 00:00:00 2001 From: Yam Date: Sun, 8 Mar 2026 03:20:00 -0400 Subject: [PATCH 1/8] Ported "Input" examples from Processing Ported all examples under the Input section of the Processing examples website. --- examples/clock.lua | 70 ++++++++++++++++++++++++ examples/constrain.lua | 50 +++++++++++++++++ examples/easing.lua | 44 +++++++++++++++ examples/keyboard-functions.lua | 97 +++++++++++++++++++++++++++++++++ examples/keyboard.lua | 50 +++++++++++++++++ examples/milliseconds.lua | 29 ++++++++++ examples/mouse-functions.lua | 78 ++++++++++++++++++++++++++ examples/mouse-press.lua | 34 ++++++++++++ examples/mouse-signals.lua | 77 ++++++++++++++++++++++++++ examples/mouse1d.lua | 34 ++++++++++++ examples/mouse2d.lua | 31 +++++++++++ examples/storing-input.lua | 53 ++++++++++++++++++ main.lua | 12 ++-- 13 files changed, 653 insertions(+), 6 deletions(-) create mode 100644 examples/clock.lua create mode 100644 examples/constrain.lua create mode 100644 examples/easing.lua create mode 100644 examples/keyboard-functions.lua create mode 100644 examples/keyboard.lua create mode 100644 examples/milliseconds.lua create mode 100644 examples/mouse-functions.lua create mode 100644 examples/mouse-press.lua create mode 100644 examples/mouse-signals.lua create mode 100644 examples/mouse1d.lua create mode 100644 examples/mouse2d.lua create mode 100644 examples/storing-input.lua diff --git a/examples/clock.lua b/examples/clock.lua new file mode 100644 index 0000000..26f932a --- /dev/null +++ b/examples/clock.lua @@ -0,0 +1,70 @@ +--[[ + Clock. + + The current time can be read with the second(), minute(), + and hour() functions. In this example, sin() and cos() values + are used to set the position of the hands + + Adapted from Processing Examples website. + https://processing.org/examples/clock.html +]] -- +require("L5") + +-- Declare Variables +local cx, cy +local secondsRadius +local minutesRadius +local hoursRadius +local clockDiameter + +function setup() + size(640, 360) + windowTitle("Clock") + describe("Display the current time") + + stroke(255) + + -- Initialize variables + local radius = min(width, height) / 2 + secondsRadius = radius * 0.72 + minutesRadius = radius * 0.60 + hoursRadius = radius * 0.50 + clockDiameter = radius * 1.8 + + cx = width / 2 + cy = height / 2 +end + +function draw() + background(0) + + -- Draw the clock background + fill(80) + noStroke() + ellipse(cx, cy, clockDiameter, clockDiameter) + + -- Angles for sin() and cos() start at 3 o'clock; + -- subtract HALF_PI to make them start at the top + local s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI + local m = map(minute() + map(second(), 0, 60, 0, 1), 0, 60, 0, TWO_PI) - HALF_PI + local h = map(hour() + map(minute(), 0, 60, 0, 1), 0, 24, 0, TWO_PI * 2) - HALF_PI + + -- Draw the hands of the clock + stroke(255) + strokeWeight(1) + line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius) + strokeWeight(2) + line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius) + strokeWeight(4) + line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius) + + -- Draw the minute ticks + strokeWeight(2) + for a = 0, 354, 6 do + local angle = radians(a) + local x = cx + cos(angle) * secondsRadius + local y = cy + sin(angle) * secondsRadius + point(x, y) + end +end + diff --git a/examples/constrain.lua b/examples/constrain.lua new file mode 100644 index 0000000..b2caecd --- /dev/null +++ b/examples/constrain.lua @@ -0,0 +1,50 @@ +--[[ + Constrain. + + Move the mouse across the screen to move the circle. + The program constrains the circle to its box. + + Adapted from Processing Examples website. + https://processing.org/examples/constrain.html +]] -- +require("L5") + +-- Declare Variables +local mx = 0 +local my = 0 +local easing = 0.05 +local radius = 24 +local edge = 100 +local inner = edge + radius + +function setup() + size(640, 360) + windowTitle("Contrain") + describe(" Move the mouse across the screen to move the circle. The program constrains the circle to its box.") + + -- Draw Modes + noStroke() + ellipseMode(RADIUS) + rectMode(CORNERS) +end + +function draw() + background(51) + + -- Change the position of the drawn ellipse to the position of the mouse with easing + if (abs(mouseX - mx) > 0.1) then + mx = mx + (mouseX - mx) * easing + end + + if (abs(mouseY - my) > 0.1) then + my = my + (mouseY - my) * easing + end + + -- Constrain the position of the ellipse to the inner rectangle + mx = constrain(mx, inner, width - inner) + my = constrain(my, inner, height - inner) + fill(76) + rect(edge, edge, width - edge, height - edge) + fill(255) + ellipse(mx, my, radius, radius) +end diff --git a/examples/easing.lua b/examples/easing.lua new file mode 100644 index 0000000..61ab3e1 --- /dev/null +++ b/examples/easing.lua @@ -0,0 +1,44 @@ +--[[ + Easing. + + Move the mouse across the screen and the symbol will follow. + Between drawing each frame of the animation, the program + calculates the difference between the position of the + symbol and the curson. If the difference is larger than + 1 pixel, the symbol moves part of the distance (0.05) from its + current position toward the cursor. + + Adapted from Processing Examples website. + https://processing.org/examples/easing.html +]] -- +require("L5") + +-- Declare Variables +local x = 0 +local y = 0 +local easing = 0.05 + +function setup() + size(640, 360) + windowTitle("Easing") + describe(" Move the mouse across the screen and the symbol will follow.") + + -- Draw Modes + noStroke() +end + +function draw() + background(51) + + -- Change the position of the drawn ellipse to the position of the mouse with easing + + targetX = mouseX + dx = targetX - x + x = x + dx * easing + + targetY = mouseY + dy = targetY - y + y = y + dy * easing + + ellipse(x, y, 66) +end diff --git a/examples/keyboard-functions.lua b/examples/keyboard-functions.lua new file mode 100644 index 0000000..1252e15 --- /dev/null +++ b/examples/keyboard-functions.lua @@ -0,0 +1,97 @@ +--[[ + Keyboard Functions + + Click on the window to give it focus and press the letter keys to type colors. + The keyboard function keyPressed() is called whenever a key is pressed. + keyPressed() is another keyboard function that is called when a key is released. + + Adapted from Processing Examples website. + https://processing.org/examples/keyboardfunctions.html + by Martin Gomez + + Original 'Color Typewriter' concept by John Maeda. +]] -- +require("L5") + +local maxHeight = 40 +local minHeight = 20 +local letterHeight = maxHeight +local letterWidth = 20 + +local x = -letterWidth +local y = 0 + +local newletter = false + +local numChars = 26 +local colors = {} + +function setup() + size(640, 360) + windowTitle("Keyboard Functions") + describe("Press letter keys to create forms in time and space") + + noStroke() + colorMode(HSB, numChars) + background(numChars / 2) + + -- Set a hue value for each key + for i = 0, numChars - 1 do + colors[i] = color(i, numChars, numChars) + end +end + +function draw() + if newletter == true then + -- Draw the "letter" + local y_pos + if letterHeight == maxHeight then + y_pos = y + rect(x, y_pos, letterWidth, letterHeight) + else + y_pos = y + minHeight + rect(x, y_pos, letterWidth, letterHeight) + fill(numChars / 2) + rect(x, y_pos - minHeight, letterWidth, letterHeight) + end + newletter = false + end +end + +function keyPressed() + -- If the key is between 'A'(65) to 'Z' and 'a' to 'z'(122) + local keyByte = string.byte(key) + + if (keyByte >= string.byte('A') and keyByte <= string.byte('Z')) or + (keyByte >= string.byte('a') and keyByte <= string.byte('z')) then + local keyIndex + if keyByte <= string.byte('Z') then + keyIndex = keyByte - string.byte('A') + letterHeight = maxHeight + fill(colors[keyIndex]) + else + keyIndex = keyByte - string.byte('a') + letterHeight = minHeight + fill(colors[keyIndex]) + end + else + fill(0) + letterHeight = 10 + end + + newletter = true + + -- Update the "letter" position + x = x + letterWidth + + -- Wrap horizontally + if x > width - letterWidth then + x = 0 + y = y + maxHeight + end + + -- Wrap vertically + if y > height - letterHeight then + y = 0 + end +end diff --git a/examples/keyboard.lua b/examples/keyboard.lua new file mode 100644 index 0000000..845d688 --- /dev/null +++ b/examples/keyboard.lua @@ -0,0 +1,50 @@ +--[[ + Keyboard. + + Click on the image to give it focus and press the letter keys + to create forms in time and space. Each key has a unique identifying + number. These numbers can be used to position shapes in space. + + Adapted from Processing Examples website. + https://processing.org/examples/keyboard.html +]] -- +require("L5") + +-- Declare Variables +local rectWidth = width / 4 + +function setup() + size(640, 360) + windowTitle("Keyboard") + describe("Press letter keys to create forms in time and space") + + -- Draw Modes + noStroke() + background(0) +end + +function draw() + -- Keep draw() heer to continue looping while waiting for keys +end + +function keyPressed() + local keyIndex = -1 + -- Convert the built-in key variable from a string to its byte value + local keyByte = string.byte(key) + + if (keyByte >= string.byte('A') and keyByte <= string.byte('Z')) then + keyIndex = keyByte - string.byte('A') + elseif (keyByte >= string.byte('a') and keyByte <= string.byte('z')) then + keyIndex = keyByte - string.byte('a') + end + + if (keyIndex == -1) then + -- If it's not a letter key, clear the screen + background(0) + else + -- If it's a letter key, fill a rectangle + fill(millis() % 255) + x = map(keyIndex, 0, 25, 0, width - rectWidth) + rect(x, 0, rectWidth, height) + end +end diff --git a/examples/milliseconds.lua b/examples/milliseconds.lua new file mode 100644 index 0000000..cb6ed39 --- /dev/null +++ b/examples/milliseconds.lua @@ -0,0 +1,29 @@ +--[[ + Milliseconds. + + A millisecond is 1/1000 of a second. + L5 keeps track of the number of miliseconds a program has run. + By modifying this number with the modulo(%) operator, + different patterns in time are created. + + Adapted from Processing Examples website. + https://processing.org/examples/milliseconds.html +]] -- +require("L5") + +function setup() + size(640, 360) + windowTitle("Milliseconds") + describe("How L5 keeps track of the number of milliseconds a program has run") + + noStroke() + scale = width / 20 +end + +function draw() + for i = 0, scale do + colorMode(RGB, (i + 1) * scale * 10) + fill(millis() % ((i + 1) * scale * 10)) + rect(i * scale, 0, scale, height) + end +end diff --git a/examples/mouse-functions.lua b/examples/mouse-functions.lua new file mode 100644 index 0000000..43f763d --- /dev/null +++ b/examples/mouse-functions.lua @@ -0,0 +1,78 @@ +--[[ + Mouse Functions. + + Click on the box and drag it across the screen. + + Adapted from Processing Examples website. + https://processing.org/examples/mousefunctions.html +]] -- +require("L5") + +-- Declare Variables +local bx = 0 +local by = 0 +local boxSize = 75 +local overbox = false +local locked = false +local xOffset = 0.0 +local yOffset = 0.0 + +function setup() + size(640, 360) + windowTitle("Mouse Functions") + describe("Click on the box and drag it across the screen.") + + -- Draw Modes + noStroke() + rectMode(RADIUS) + + -- Initialize Variables + bx = width / 2.0 + by = height / 2.0 + boxSize = 75 + overbox = false + locked = false + xOffset = 0.0 + yOffset = 0.0 +end + +function draw() + background(0) + + if ((mouseX > bx - boxSize and mouseX < bx + boxSize) and (mouseY > by - boxSize and mouseY < by + boxSize)) then + overbox = true + if (not locked) then + stroke(255) + fill(153) + end + + else + stroke(153) + fill(153) + overbox = false + end + + rect(bx, by, boxSize, boxSize) +end + +function mousePressed() + if (overbox) then + locked = true + fill(255, 255, 255) + else + locked = false + end + xOffset = mouseX - bx + yOffset = mouseY - by +end + +function mouseDragged() + if (locked) then + bx = mouseX - xOffset + by = mouseY - yOffset + end +end + +function mouseReleased() + locked = false +end diff --git a/examples/mouse-press.lua b/examples/mouse-press.lua new file mode 100644 index 0000000..a7422e8 --- /dev/null +++ b/examples/mouse-press.lua @@ -0,0 +1,34 @@ +--[[ + Mouse Press. + + Move the mouse to position the shape. + Press the mouse button to invert the color + + Adapted from Processing Examples website. + https://processing.org/examples/mousepress.html +]] -- +require("L5") + +function setup() + size(640, 360) + windowTitle("Mouse Press") + describe("Move and press the mouse button to position the shape and invert the color") + + -- Draw Modes + noSmooth() + fill(126) + background(102) +end + +function draw() + -- In processing mousePressed is both a function signature and global built-in variable + -- In L5, this is differentiated into mousePressed(), the function and mouseIsPressed, the built-in variable + if (mouseIsPressed) then + stroke(255) + else + stroke(0) + end + + line(mouseX - 66, mouseY, mouseX + 66, mouseY) + line(mouseX, mouseY - 66, mouseX, mouseY + 66) +end diff --git a/examples/mouse-signals.lua b/examples/mouse-signals.lua new file mode 100644 index 0000000..7e07169 --- /dev/null +++ b/examples/mouse-signals.lua @@ -0,0 +1,77 @@ +--[[ + Mouse Signals + + Move and click the mouse to generate signals. + The top row is the signal from "mouseX", + the middle row is the signal from "mouseY", + and the bottom row is the signal from "mousePressed". + + Adapted from Processing Examples website. + https://processing.org/examples/mousesignals.html +]] -- +require("L5") + +-- Declare Variables +local xvals +local yvals +local bvals + +function setup() + size(640, 360) + windowTitle("Mouse Signals") + describe("Move and click the mouse to generate signals") + + noSmooth() + + xvals = {} + yvals = {} + bvals = {} + + -- Initialize tables with 0 + for i = 1, width do + xvals[i] = 0 + yvals[i] = 0 + bvals[i] = 0 + end +end + +function draw() + background(102) + + -- Shift the values to the left + for i = 2, width do + xvals[i - 1] = xvals[i] + yvals[i - 1] = yvals[i] + bvals[i - 1] = bvals[i] + end + + -- Add the new values to the end of the array + xvals[width] = mouseX + yvals[width] = mouseY + + if mouseIsPressed then + bvals[width] = 0 + else + bvals[width] = height / 3 + end + + fill(255) + noStroke() + rect(0, height / 3, width, height / 3 + 1) + + for i = 1, width - 1 do + -- Draw the x-values + stroke(255) + point(i, map(xvals[i], 0, width, 0, height / 3 - 1)) + + -- Draw the y-values + stroke(0) + point(i, height / 3 + yvals[i] / 3) + end + + for i = 2, width do + -- Draw the mouse presses + stroke(255) + line(i, (2 * height / 3) + bvals[i], i, (2 * height / 3) + bvals[i - 1]) + end +end diff --git a/examples/mouse1d.lua b/examples/mouse1d.lua new file mode 100644 index 0000000..44549bd --- /dev/null +++ b/examples/mouse1d.lua @@ -0,0 +1,34 @@ +--[[ + Mouse 1D. + + Move the mouse left and right to shift the balance. + The "mouseX" variable is used to control both the + size and color of the rectangles. + + Adapted from Processing Examples website. + https://processing.org/examples/mouse1d.html +]] -- +require("L5") + +function setup() + size(640, 360) + windowTitle("Mouse 1D") + describe("Move the mouse left and right to shift the balance.") + + noStroke() + colorMode(RGB, height, height, height) + rectMode(CENTER) +end + +function draw() + background(0.0) + + local r1 = map(mouseX, 0, width, 0, height) + local r2 = height - r1 + + fill(r1) + rect(width / 2 + r1 / 2, height / 2, r1, r1) + + fill(r2) + rect(width / 2 - r2 / 2, height / 2, r2, r2) +end diff --git a/examples/mouse2d.lua b/examples/mouse2d.lua new file mode 100644 index 0000000..d514480 --- /dev/null +++ b/examples/mouse2d.lua @@ -0,0 +1,31 @@ +--[[ + Mouse 2D. + + Moving the mouse changes the position and size of each box + + Adapted from Processing Examples website. + https://processing.org/examples/mouse2d.html +]] -- +require("L5") + +function setup() + size(640, 360) + windowTitle("Mouse 2D") + describe("Moving the mouse changes the position and size of each box") + + noStroke() + rectMode(CENTER) +end + +function draw() + background(0.0) + + fill(255, 204) + rect(mouseX, height / 2, mouseY / 2 + 10, mouseY / 2 + 10) + + fill(255, 204) + + local inverseX = width - mouseX + local inverseY = height - mouseY + rect(inverseX, height / 2, (inverseY / 2) + 10, (inverseY / 2) + 10) +end diff --git a/examples/storing-input.lua b/examples/storing-input.lua new file mode 100644 index 0000000..42e0fc9 --- /dev/null +++ b/examples/storing-input.lua @@ -0,0 +1,53 @@ +--[[ + Storing Input. + + Move the mouse across the screen to change the position + of the circles. The positions of the mouse are recorded + into an array and played back every frame. Between each + frame, the newest value are added to the end of each array + and the oldest value is deleted + + Adapted from Processing Examples website. + https://processing.org/examples/storinginput.html +]] -- +require("L5") + +-- Declare Variables +local num = 60 +local mx +local my + +function setup() + size(640, 360) + windowTitle("Storing Input") + describe(" Move the mouse across the screen to change the position of the circles and store them") + + noStroke() + + mx = {} + my = {} + + -- Initialize tables with 0 + for i = 0, num - 1 do + mx[i] = 0 + my[i] = 0 + end + + fill(255, 153) +end + +function draw() + background(51) + + -- Cycle through the array, using a different entry on each frame. + -- Using modulo (%) like this is faster than moving all the values over + local which = frameCount % num + mx[which] = mouseX + my[which] = mouseY + + for i = 0, num - 1 do + -- which+1 is the smallest (the oldest in the array) + local index = (which + 1 + i) % num + ellipse(mx[index], my[index], i, i) + end +end diff --git a/main.lua b/main.lua index c9d2b7e..4b62484 100644 --- a/main.lua +++ b/main.lua @@ -1,16 +1,16 @@ require("L5") function setup() - size(400, 400) + size(400, 400) - -- Set the program title - windowTitle("Basic sketch") + -- Set the program title + windowTitle("Basic sketch") - describe('Draws a yellow background') + describe('Draws a yellow background') end function draw() - -- Fills the background with the color yellow - background(255, 215, 0) + -- Fills the background with the color yellow + background(255, 215, 0) end From 0f0f0a4d14e2614ac2b15528b3ccb9a196f0b6e0 Mon Sep 17 00:00:00 2001 From: Yam Date: Mon, 9 Mar 2026 23:49:24 -0400 Subject: [PATCH 2/8] fix: error declaring rectWidth outside setup() --- examples/keyboard.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/keyboard.lua b/examples/keyboard.lua index 845d688..cdb3cca 100644 --- a/examples/keyboard.lua +++ b/examples/keyboard.lua @@ -10,9 +10,6 @@ ]] -- require("L5") --- Declare Variables -local rectWidth = width / 4 - function setup() size(640, 360) windowTitle("Keyboard") @@ -21,6 +18,9 @@ function setup() -- Draw Modes noStroke() background(0) + + -- Declare Variables + rectWidth = width / 4 end function draw() From b29a3fb746c6b790550b9c9955ca9c7fed6fe261 Mon Sep 17 00:00:00 2001 From: Yam Date: Mon, 16 Mar 2026 23:00:28 -0400 Subject: [PATCH 3/8] Making sure ported examples here are identical to website's --- L5.lua | 28 +++++++----- examples/clock.lua | 5 +-- examples/constrain.lua | 6 +-- examples/easing.lua | 4 +- examples/keyboard-functions.lua | 29 ++++++------- examples/keyboard.lua | 6 +-- examples/milliseconds.lua | 2 +- examples/mouse-functions.lua | 6 +-- examples/mouse-press.lua | 3 -- examples/mouse-signals.lua | 4 +- examples/mouse1d.lua | 2 +- examples/mouse2d.lua | 2 +- examples/storing-input.lua | 4 +- main.lua | 75 ++++++++++++++++++++++++++++++--- 14 files changed, 111 insertions(+), 65 deletions(-) diff --git a/L5.lua b/L5.lua index 66b0d30..510283f 100644 --- a/L5.lua +++ b/L5.lua @@ -144,9 +144,9 @@ function love.load() -- Clear both buffers initially love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) -- gray background + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) -- gray background + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas() initShaderDefaults() @@ -322,6 +322,7 @@ function love.textinput(_text) key = _text L5_env.typedKey = _text L5_env.keyWasTyped = true + if textinput ~= nil then textinput(_text) end end function love.resize(w, h) @@ -332,12 +333,12 @@ function love.resize(w, h) L5_env.backBuffer = love.graphics.newCanvas(w, h) L5_env.frontBuffer = love.graphics.newCanvas(w, h ) - -- Clear new buffers and apply scaling + -- Clear new buffers with current background color love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas(L5_env.backBuffer) @@ -423,11 +424,11 @@ function size(_w, _h) L5_env.backBuffer = love.graphics.newCanvas(_w, _h) L5_env.frontBuffer = love.graphics.newCanvas(_w, _h) - -- Clear new buffers + -- Clear new buffers with current background color love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) + love.graphics.clear(unpack(L5_env.bgColor)) -- Set back to back buffer for continued drawing love.graphics.setCanvas(L5_env.backBuffer) @@ -485,9 +486,9 @@ function fullscreen(display) L5_env.frontBuffer = love.graphics.newCanvas(w, h) love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) + love.graphics.clear(unpack(L5_env.bgColor)) love.graphics.setCanvas(L5_env.backBuffer) width, height = love.graphics.getDimensions() @@ -852,6 +853,7 @@ function define_env_globals() -- global color state L5_env.fill_mode="fill" --also: "line" L5_env.stroke_color = {0,0,0} + L5_env.bgColor = {0.5, 0.5, 1} L5_env.currentTint = {1, 1, 1, 1} -- Default: no tint white L5_env.color_max = {255,255,255,255} L5_env.color_mode = RGB --also: HSB, HSL @@ -898,6 +900,8 @@ function define_env_globals() L5_env.useTexture = false L5_env.textureMode=IMAGE -- NORMAL or IMAGE L5_env.textureWrap=CLAMP -- wrap mode CLAMP or REPEAT + -- Background color tracking: {r, g, b, a} normalized 0-1 + L5_env.bgColor = {0.5, 0.5, 0.5, 1} -- custom print output on screen L5_env.printBuffer = {} L5_env.defaultFont = love.graphics.getFont() @@ -1673,8 +1677,10 @@ function background(_r,_g,_b,_a) if type(_r) == "userdata" and _r:type() == "Image" then image(_r,0,0,width,height) else + local bgColor = toColor(_r,_g,_b,_a) + L5_env.bgColor = bgColor -- Store normalized RGBA for buffer clearing local prevR, prevG, prevB, prevA = love.graphics.getColor() - love.graphics.setColor(unpack(toColor(_r,_g,_b,_a))) + love.graphics.setColor(unpack(bgColor)) love.graphics.rectangle("fill", 0, 0, width, height) love.graphics.setColor(prevR, prevG, prevB, prevA) L5_env.clearscreen = true diff --git a/examples/clock.lua b/examples/clock.lua index 26f932a..020a275 100644 --- a/examples/clock.lua +++ b/examples/clock.lua @@ -10,7 +10,6 @@ ]] -- require("L5") --- Declare Variables local cx, cy local secondsRadius local minutesRadius @@ -24,7 +23,6 @@ function setup() stroke(255) - -- Initialize variables local radius = min(width, height) / 2 secondsRadius = radius * 0.72 minutesRadius = radius * 0.60 @@ -66,5 +64,4 @@ function draw() local y = cy + sin(angle) * secondsRadius point(x, y) end -end - +end \ No newline at end of file diff --git a/examples/constrain.lua b/examples/constrain.lua index b2caecd..940fd1d 100644 --- a/examples/constrain.lua +++ b/examples/constrain.lua @@ -9,7 +9,6 @@ ]] -- require("L5") --- Declare Variables local mx = 0 local my = 0 local easing = 0.05 @@ -19,10 +18,9 @@ local inner = edge + radius function setup() size(640, 360) - windowTitle("Contrain") + windowTitle("Constrain") describe(" Move the mouse across the screen to move the circle. The program constrains the circle to its box.") - -- Draw Modes noStroke() ellipseMode(RADIUS) rectMode(CORNERS) @@ -47,4 +45,4 @@ function draw() rect(edge, edge, width - edge, height - edge) fill(255) ellipse(mx, my, radius, radius) -end +end \ No newline at end of file diff --git a/examples/easing.lua b/examples/easing.lua index 61ab3e1..0653709 100644 --- a/examples/easing.lua +++ b/examples/easing.lua @@ -13,7 +13,6 @@ ]] -- require("L5") --- Declare Variables local x = 0 local y = 0 local easing = 0.05 @@ -23,7 +22,6 @@ function setup() windowTitle("Easing") describe(" Move the mouse across the screen and the symbol will follow.") - -- Draw Modes noStroke() end @@ -41,4 +39,4 @@ function draw() y = y + dy * easing ellipse(x, y, 66) -end +end \ No newline at end of file diff --git a/examples/keyboard-functions.lua b/examples/keyboard-functions.lua index 1252e15..f5a4aa1 100644 --- a/examples/keyboard-functions.lua +++ b/examples/keyboard-functions.lua @@ -58,22 +58,17 @@ function draw() end end -function keyPressed() - -- If the key is between 'A'(65) to 'Z' and 'a' to 'z'(122) - local keyByte = string.byte(key) - - if (keyByte >= string.byte('A') and keyByte <= string.byte('Z')) or - (keyByte >= string.byte('a') and keyByte <= string.byte('z')) then - local keyIndex - if keyByte <= string.byte('Z') then - keyIndex = keyByte - string.byte('A') - letterHeight = maxHeight - fill(colors[keyIndex]) - else - keyIndex = keyByte - string.byte('a') - letterHeight = minHeight - fill(colors[keyIndex]) - end +function textinput(text) + local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + if string.match(key, "^[A-Z]$") then + keyIndex = string.find(alphabet, key) - 1 + letterHeight = maxHeight + fill(colors[keyIndex]) + elseif string.match(key, "^[a-z]$") then + keyIndex = string.find(alphabet, string.upper(key)) - 1 + letterHeight = minHeight + fill(colors[keyIndex]) else fill(0) letterHeight = 10 @@ -94,4 +89,4 @@ function keyPressed() if y > height - letterHeight then y = 0 end -end +end \ No newline at end of file diff --git a/examples/keyboard.lua b/examples/keyboard.lua index cdb3cca..c8b8acd 100644 --- a/examples/keyboard.lua +++ b/examples/keyboard.lua @@ -15,16 +15,14 @@ function setup() windowTitle("Keyboard") describe("Press letter keys to create forms in time and space") - -- Draw Modes noStroke() background(0) - -- Declare Variables rectWidth = width / 4 end function draw() - -- Keep draw() heer to continue looping while waiting for keys + -- Keep draw() here to continue looping while waiting for keys end function keyPressed() @@ -47,4 +45,4 @@ function keyPressed() x = map(keyIndex, 0, 25, 0, width - rectWidth) rect(x, 0, rectWidth, height) end -end +end \ No newline at end of file diff --git a/examples/milliseconds.lua b/examples/milliseconds.lua index cb6ed39..90eb045 100644 --- a/examples/milliseconds.lua +++ b/examples/milliseconds.lua @@ -26,4 +26,4 @@ function draw() fill(millis() % ((i + 1) * scale * 10)) rect(i * scale, 0, scale, height) end -end +end \ No newline at end of file diff --git a/examples/mouse-functions.lua b/examples/mouse-functions.lua index 43f763d..5cbadf3 100644 --- a/examples/mouse-functions.lua +++ b/examples/mouse-functions.lua @@ -8,7 +8,6 @@ ]] -- require("L5") --- Declare Variables local bx = 0 local by = 0 local boxSize = 75 @@ -22,11 +21,9 @@ function setup() windowTitle("Mouse Functions") describe("Click on the box and drag it across the screen.") - -- Draw Modes noStroke() rectMode(RADIUS) - -- Initialize Variables bx = width / 2.0 by = height / 2.0 boxSize = 75 @@ -39,6 +36,7 @@ end function draw() background(0) + -- Test if the cursor is over the box if ((mouseX > bx - boxSize and mouseX < bx + boxSize) and (mouseY > by - boxSize and mouseY < by + boxSize)) then overbox = true if (not locked) then @@ -75,4 +73,4 @@ end function mouseReleased() locked = false -end +end \ No newline at end of file diff --git a/examples/mouse-press.lua b/examples/mouse-press.lua index a7422e8..4a358ef 100644 --- a/examples/mouse-press.lua +++ b/examples/mouse-press.lua @@ -14,15 +14,12 @@ function setup() windowTitle("Mouse Press") describe("Move and press the mouse button to position the shape and invert the color") - -- Draw Modes noSmooth() fill(126) background(102) end function draw() - -- In processing mousePressed is both a function signature and global built-in variable - -- In L5, this is differentiated into mousePressed(), the function and mouseIsPressed, the built-in variable if (mouseIsPressed) then stroke(255) else diff --git a/examples/mouse-signals.lua b/examples/mouse-signals.lua index 7e07169..0ceeab6 100644 --- a/examples/mouse-signals.lua +++ b/examples/mouse-signals.lua @@ -11,7 +11,6 @@ ]] -- require("L5") --- Declare Variables local xvals local yvals local bvals @@ -27,7 +26,6 @@ function setup() yvals = {} bvals = {} - -- Initialize tables with 0 for i = 1, width do xvals[i] = 0 yvals[i] = 0 @@ -74,4 +72,4 @@ function draw() stroke(255) line(i, (2 * height / 3) + bvals[i], i, (2 * height / 3) + bvals[i - 1]) end -end +end \ No newline at end of file diff --git a/examples/mouse1d.lua b/examples/mouse1d.lua index 44549bd..91ca815 100644 --- a/examples/mouse1d.lua +++ b/examples/mouse1d.lua @@ -31,4 +31,4 @@ function draw() fill(r2) rect(width / 2 - r2 / 2, height / 2, r2, r2) -end +end \ No newline at end of file diff --git a/examples/mouse2d.lua b/examples/mouse2d.lua index d514480..74680ae 100644 --- a/examples/mouse2d.lua +++ b/examples/mouse2d.lua @@ -28,4 +28,4 @@ function draw() local inverseX = width - mouseX local inverseY = height - mouseY rect(inverseX, height / 2, (inverseY / 2) + 10, (inverseY / 2) + 10) -end +end \ No newline at end of file diff --git a/examples/storing-input.lua b/examples/storing-input.lua index 42e0fc9..bb0630d 100644 --- a/examples/storing-input.lua +++ b/examples/storing-input.lua @@ -12,7 +12,6 @@ ]] -- require("L5") --- Declare Variables local num = 60 local mx local my @@ -27,7 +26,6 @@ function setup() mx = {} my = {} - -- Initialize tables with 0 for i = 0, num - 1 do mx[i] = 0 my[i] = 0 @@ -50,4 +48,4 @@ function draw() local index = (which + 1 + i) % num ellipse(mx[index], my[index], i, i) end -end +end \ No newline at end of file diff --git a/main.lua b/main.lua index 4b62484..024f81d 100644 --- a/main.lua +++ b/main.lua @@ -1,16 +1,79 @@ require("L5") +local maxHeight = 40 +local minHeight = 20 +local letterHeight = maxHeight +local letterWidth = 20 + +local x = -letterWidth +local y = 0 + +local newletter = false + +local numChars = 26 +local colors = {} + function setup() - size(400, 400) + size(640, 360) + windowTitle("Keyboard Functions") + describe("Press letter keys to create forms in time and space") - -- Set the program title - windowTitle("Basic sketch") + noStroke() + colorMode(HSB, numChars) + background(numChars / 2) - describe('Draws a yellow background') + -- Set a hue value for each key + for i = 0, numChars - 1 do + colors[i] = color(i, numChars, numChars) + end end function draw() - -- Fills the background with the color yellow - background(255, 215, 0) + if newletter == true then + -- Draw the "letter" + local y_pos + if letterHeight == maxHeight then + y_pos = y + rect(x, y_pos, letterWidth, letterHeight) + else + y_pos = y + minHeight + rect(x, y_pos, letterWidth, letterHeight) + fill(numChars / 2) + rect(x, y_pos - minHeight, letterWidth, letterHeight) + end + newletter = false + end end +function textinput(text) + local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + if string.match(key, "^[A-Z]$") then + keyIndex = string.find(alphabet, key) - 1 + letterHeight = maxHeight + fill(colors[keyIndex]) + elseif string.match(key, "^[a-z]$") then + keyIndex = string.find(alphabet, string.upper(key)) - 1 + letterHeight = minHeight + fill(colors[keyIndex]) + else + fill(0) + letterHeight = 10 + end + + newletter = true + + -- Update the "letter" position + x = x + letterWidth + + -- Wrap horizontally + if x > width - letterWidth then + x = 0 + y = y + maxHeight + end + + -- Wrap vertically + if y > height - letterHeight then + y = 0 + end +end \ No newline at end of file From f1fa2d3b2ba6b3878a49a6d371cdc9d28fe3b813 Mon Sep 17 00:00:00 2001 From: Yam Date: Tue, 17 Mar 2026 11:31:53 -0400 Subject: [PATCH 4/8] Matched input examples merged in website Matched the revised input examples in the L5 website, with proper crediting/licensing. Cleaned up unrelated L5.lua and main.lua changes for another issue --- L5.lua | 25 +++++----- examples/clock.lua | 5 +- examples/constrain.lua | 3 +- examples/easing.lua | 3 +- examples/keyboard-functions.lua | 4 +- examples/keyboard.lua | 63 ++++++++++++------------- examples/milliseconds.lua | 3 +- examples/mouse-functions.lua | 66 +++++++++++++-------------- examples/mouse-press.lua | 5 +- examples/mouse-signals.lua | 3 +- examples/mouse1d.lua | 3 +- examples/mouse2d.lua | 3 +- examples/storing-input.lua | 3 +- main.lua | 81 ++++----------------------------- 14 files changed, 96 insertions(+), 174 deletions(-) diff --git a/L5.lua b/L5.lua index 510283f..62fbaad 100644 --- a/L5.lua +++ b/L5.lua @@ -144,9 +144,9 @@ function love.load() -- Clear both buffers initially love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) -- grey background love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) -- grey background love.graphics.setCanvas() initShaderDefaults() @@ -322,7 +322,6 @@ function love.textinput(_text) key = _text L5_env.typedKey = _text L5_env.keyWasTyped = true - if textinput ~= nil then textinput(_text) end end function love.resize(w, h) @@ -333,12 +332,12 @@ function love.resize(w, h) L5_env.backBuffer = love.graphics.newCanvas(w, h) L5_env.frontBuffer = love.graphics.newCanvas(w, h ) - -- Clear new buffers with current background color + -- Clear new buffers and apply scaling love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) love.graphics.setCanvas(L5_env.backBuffer) @@ -424,11 +423,11 @@ function size(_w, _h) L5_env.backBuffer = love.graphics.newCanvas(_w, _h) L5_env.frontBuffer = love.graphics.newCanvas(_w, _h) - -- Clear new buffers with current background color + -- Clear new buffers love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) -- Set back to back buffer for continued drawing love.graphics.setCanvas(L5_env.backBuffer) @@ -486,9 +485,9 @@ function fullscreen(display) L5_env.frontBuffer = love.graphics.newCanvas(w, h) love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(unpack(L5_env.bgColor)) + love.graphics.clear(0.5, 0.5, 0.5, 1) love.graphics.setCanvas(L5_env.backBuffer) width, height = love.graphics.getDimensions() @@ -853,7 +852,7 @@ function define_env_globals() -- global color state L5_env.fill_mode="fill" --also: "line" L5_env.stroke_color = {0,0,0} - L5_env.bgColor = {0.5, 0.5, 1} + L5_env.currentTint = {1, 1, 1, 1} -- Default: no tint white L5_env.color_max = {255,255,255,255} L5_env.color_mode = RGB --also: HSB, HSL @@ -900,8 +899,6 @@ function define_env_globals() L5_env.useTexture = false L5_env.textureMode=IMAGE -- NORMAL or IMAGE L5_env.textureWrap=CLAMP -- wrap mode CLAMP or REPEAT - -- Background color tracking: {r, g, b, a} normalized 0-1 - L5_env.bgColor = {0.5, 0.5, 0.5, 1} -- custom print output on screen L5_env.printBuffer = {} L5_env.defaultFont = love.graphics.getFont() diff --git a/examples/clock.lua b/examples/clock.lua index 020a275..02154ed 100644 --- a/examples/clock.lua +++ b/examples/clock.lua @@ -4,9 +4,8 @@ The current time can be read with the second(), minute(), and hour() functions. In this example, sin() and cos() values are used to set the position of the hands - - Adapted from Processing Examples website. - https://processing.org/examples/clock.html + + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/constrain.lua b/examples/constrain.lua index 940fd1d..ff2f938 100644 --- a/examples/constrain.lua +++ b/examples/constrain.lua @@ -4,8 +4,7 @@ Move the mouse across the screen to move the circle. The program constrains the circle to its box. - Adapted from Processing Examples website. - https://processing.org/examples/constrain.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/easing.lua b/examples/easing.lua index 0653709..524edcc 100644 --- a/examples/easing.lua +++ b/examples/easing.lua @@ -8,8 +8,7 @@ 1 pixel, the symbol moves part of the distance (0.05) from its current position toward the cursor. - Adapted from Processing Examples website. - https://processing.org/examples/easing.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/keyboard-functions.lua b/examples/keyboard-functions.lua index f5a4aa1..2ef4993 100644 --- a/examples/keyboard-functions.lua +++ b/examples/keyboard-functions.lua @@ -5,9 +5,7 @@ The keyboard function keyPressed() is called whenever a key is pressed. keyPressed() is another keyboard function that is called when a key is released. - Adapted from Processing Examples website. - https://processing.org/examples/keyboardfunctions.html - by Martin Gomez + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. Original 'Color Typewriter' concept by John Maeda. ]] -- diff --git a/examples/keyboard.lua b/examples/keyboard.lua index c8b8acd..bac6a76 100644 --- a/examples/keyboard.lua +++ b/examples/keyboard.lua @@ -5,44 +5,41 @@ to create forms in time and space. Each key has a unique identifying number. These numbers can be used to position shapes in space. - Adapted from Processing Examples website. - https://processing.org/examples/keyboard.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") function setup() - size(640, 360) - windowTitle("Keyboard") - describe("Press letter keys to create forms in time and space") - - noStroke() - background(0) - - rectWidth = width / 4 -end - -function draw() - -- Keep draw() here to continue looping while waiting for keys + size(640, 360) + windowTitle("Keyboard") + describe("Press letter keys to create forms in time and space") + noStroke() + background(0) + rectWidth = width / 4 end function keyPressed() - local keyIndex = -1 - -- Convert the built-in key variable from a string to its byte value - local keyByte = string.byte(key) - - if (keyByte >= string.byte('A') and keyByte <= string.byte('Z')) then - keyIndex = keyByte - string.byte('A') - elseif (keyByte >= string.byte('a') and keyByte <= string.byte('z')) then - keyIndex = keyByte - string.byte('a') - end - - if (keyIndex == -1) then - -- If it's not a letter key, clear the screen - background(0) - else - -- If it's a letter key, fill a rectangle - fill(millis() % 255) - x = map(keyIndex, 0, 25, 0, width - rectWidth) - rect(x, 0, rectWidth, height) - end + local keyIndex = -1 + local alphabet = "abcdefghijklmnopqrstuvwxyz" + local upperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + -- Check if it's a letter and get its index + local upperPos = string.find(upperAlphabet, key) + local lowerPos = string.find(alphabet, key) + + if upperPos then + keyIndex = upperPos - 1 + elseif lowerPos then + keyIndex = lowerPos - 1 + end + + if keyIndex == -1 then + -- If it's not a letter key, clear the screen + background(0) + else + -- It's a letter key, fill a rectangle + fill(millis() % 255) + local x = map(keyIndex, 0, 25, 0, width - rectWidth) + rect(x, 0, rectWidth, height) + end end \ No newline at end of file diff --git a/examples/milliseconds.lua b/examples/milliseconds.lua index 90eb045..ef87a5b 100644 --- a/examples/milliseconds.lua +++ b/examples/milliseconds.lua @@ -6,8 +6,7 @@ By modifying this number with the modulo(%) operator, different patterns in time are created. - Adapted from Processing Examples website. - https://processing.org/examples/milliseconds.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/mouse-functions.lua b/examples/mouse-functions.lua index 5cbadf3..ff20f27 100644 --- a/examples/mouse-functions.lua +++ b/examples/mouse-functions.lua @@ -3,8 +3,7 @@ Click on the box and drag it across the screen. - Adapted from Processing Examples website. - https://processing.org/examples/mousefunctions.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") @@ -24,53 +23,54 @@ function setup() noStroke() rectMode(RADIUS) - bx = width / 2.0 - by = height / 2.0 + bx = width / 2 + by = height / 2 boxSize = 75 overbox = false locked = false - xOffset = 0.0 - yOffset = 0.0 + xOffset = 0 + yOffset = 0 end function draw() - background(0) + background(0) - -- Test if the cursor is over the box - if ((mouseX > bx - boxSize and mouseX < bx + boxSize) and (mouseY > by - boxSize and mouseY < by + boxSize)) then - overbox = true - if (not locked) then - stroke(255) - fill(153) - end - - else - stroke(153) - fill(153) - overbox = false + -- Test if the cursor is over the box + if ((mouseX > bx - boxSize and mouseX < bx + boxSize) and (mouseY > by - boxSize and mouseY < by + boxSize)) then + overbox = true + if (not locked) then + stroke(255) + fill(153) end - rect(bx, by, boxSize, boxSize) + else + stroke(153) + fill(153) + overbox = false + end + + -- draw the box + rect(bx, by, boxSize, boxSize) end function mousePressed() - if (overbox) then - locked = true - fill(255, 255, 255) - else - locked = false - end - xOffset = mouseX - bx - yOffset = mouseY - by + if (overbox) then + locked = true + fill(255, 255, 255) + else + locked = false + end + xOffset = mouseX - bx + yOffset = mouseY - by end function mouseDragged() - if (locked) then - bx = mouseX - xOffset - by = mouseY - yOffset - end + if (locked) then + bx = mouseX - xOffset + by = mouseY - yOffset + end end function mouseReleased() - locked = false + locked = false end \ No newline at end of file diff --git a/examples/mouse-press.lua b/examples/mouse-press.lua index 4a358ef..d1422ee 100644 --- a/examples/mouse-press.lua +++ b/examples/mouse-press.lua @@ -4,8 +4,7 @@ Move the mouse to position the shape. Press the mouse button to invert the color - Adapted from Processing Examples website. - https://processing.org/examples/mousepress.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") @@ -20,7 +19,7 @@ function setup() end function draw() - if (mouseIsPressed) then + if mouseIsPressed then stroke(255) else stroke(0) diff --git a/examples/mouse-signals.lua b/examples/mouse-signals.lua index 0ceeab6..d49035b 100644 --- a/examples/mouse-signals.lua +++ b/examples/mouse-signals.lua @@ -6,8 +6,7 @@ the middle row is the signal from "mouseY", and the bottom row is the signal from "mousePressed". - Adapted from Processing Examples website. - https://processing.org/examples/mousesignals.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/mouse1d.lua b/examples/mouse1d.lua index 91ca815..8003ea0 100644 --- a/examples/mouse1d.lua +++ b/examples/mouse1d.lua @@ -5,8 +5,7 @@ The "mouseX" variable is used to control both the size and color of the rectangles. - Adapted from Processing Examples website. - https://processing.org/examples/mouse1d.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/mouse2d.lua b/examples/mouse2d.lua index 74680ae..0620a15 100644 --- a/examples/mouse2d.lua +++ b/examples/mouse2d.lua @@ -3,8 +3,7 @@ Moving the mouse changes the position and size of each box - Adapted from Processing Examples website. - https://processing.org/examples/mouse2d.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/examples/storing-input.lua b/examples/storing-input.lua index bb0630d..58dc919 100644 --- a/examples/storing-input.lua +++ b/examples/storing-input.lua @@ -7,8 +7,7 @@ frame, the newest value are added to the end of each array and the oldest value is deleted - Adapted from Processing Examples website. - https://processing.org/examples/storinginput.html + Adapted from Processing examples. Adapted to L5 2025. Licensed under CC BY-NC-SA 4.0. ]] -- require("L5") diff --git a/main.lua b/main.lua index 024f81d..dccc713 100644 --- a/main.lua +++ b/main.lua @@ -1,79 +1,18 @@ require("L5") - -local maxHeight = 40 -local minHeight = 20 -local letterHeight = maxHeight -local letterWidth = 20 - -local x = -letterWidth -local y = 0 - -local newletter = false - -local numChars = 26 -local colors = {} - function setup() - size(640, 360) - windowTitle("Keyboard Functions") - describe("Press letter keys to create forms in time and space") - + size(400, 400) + windowTitle('Hello L5') + background('white') noStroke() - colorMode(HSB, numChars) - background(numChars / 2) - - -- Set a hue value for each key - for i = 0, numChars - 1 do - colors[i] = color(i, numChars, numChars) - end + describe('A basic drawing program in L5. A random fill color each mouse press.') end -function draw() - if newletter == true then - -- Draw the "letter" - local y_pos - if letterHeight == maxHeight then - y_pos = y - rect(x, y_pos, letterWidth, letterHeight) - else - y_pos = y + minHeight - rect(x, y_pos, letterWidth, letterHeight) - fill(numChars / 2) - rect(x, y_pos - minHeight, letterWidth, letterHeight) - end - newletter = false - end +function mouseDragged() + -- Draw a circle that follows the mouse when held down + circle(mouseX, mouseY, 20) end -function textinput(text) - local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - - if string.match(key, "^[A-Z]$") then - keyIndex = string.find(alphabet, key) - 1 - letterHeight = maxHeight - fill(colors[keyIndex]) - elseif string.match(key, "^[a-z]$") then - keyIndex = string.find(alphabet, string.upper(key)) - 1 - letterHeight = minHeight - fill(colors[keyIndex]) - else - fill(0) - letterHeight = 10 - end - - newletter = true - - -- Update the "letter" position - x = x + letterWidth - - -- Wrap horizontally - if x > width - letterWidth then - x = 0 - y = y + maxHeight - end - - -- Wrap vertically - if y > height - letterHeight then - y = 0 - end +function mousePressed() + -- Pick a random color on mouse press + fill(random(255),random(255),random(255)) end \ No newline at end of file From 5e5c96ea3afeae6f703e85b0506ca05953d251d7 Mon Sep 17 00:00:00 2001 From: Yam Date: Tue, 17 Mar 2026 11:33:40 -0400 Subject: [PATCH 5/8] tweak: delete white space --- L5.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/L5.lua b/L5.lua index 62fbaad..2390c89 100644 --- a/L5.lua +++ b/L5.lua @@ -852,7 +852,6 @@ function define_env_globals() -- global color state L5_env.fill_mode="fill" --also: "line" L5_env.stroke_color = {0,0,0} - L5_env.currentTint = {1, 1, 1, 1} -- Default: no tint white L5_env.color_max = {255,255,255,255} L5_env.color_mode = RGB --also: HSB, HSL From 485c78c92e9862297850ef76377113b7dcbb6723 Mon Sep 17 00:00:00 2001 From: Yam Date: Tue, 17 Mar 2026 11:39:46 -0400 Subject: [PATCH 6/8] clean up to match main --- L5.lua | 8 +++----- main.lua | 21 +++++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/L5.lua b/L5.lua index 2390c89..66b0d30 100644 --- a/L5.lua +++ b/L5.lua @@ -144,9 +144,9 @@ function love.load() -- Clear both buffers initially love.graphics.setCanvas(L5_env.backBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) -- grey background + love.graphics.clear(0.5, 0.5, 0.5, 1) -- gray background love.graphics.setCanvas(L5_env.frontBuffer) - love.graphics.clear(0.5, 0.5, 0.5, 1) -- grey background + love.graphics.clear(0.5, 0.5, 0.5, 1) -- gray background love.graphics.setCanvas() initShaderDefaults() @@ -1673,10 +1673,8 @@ function background(_r,_g,_b,_a) if type(_r) == "userdata" and _r:type() == "Image" then image(_r,0,0,width,height) else - local bgColor = toColor(_r,_g,_b,_a) - L5_env.bgColor = bgColor -- Store normalized RGBA for buffer clearing local prevR, prevG, prevB, prevA = love.graphics.getColor() - love.graphics.setColor(unpack(bgColor)) + love.graphics.setColor(unpack(toColor(_r,_g,_b,_a))) love.graphics.rectangle("fill", 0, 0, width, height) love.graphics.setColor(prevR, prevG, prevB, prevA) L5_env.clearscreen = true diff --git a/main.lua b/main.lua index dccc713..6916282 100644 --- a/main.lua +++ b/main.lua @@ -1,18 +1,15 @@ require("L5") + function setup() - size(400, 400) - windowTitle('Hello L5') - background('white') - noStroke() - describe('A basic drawing program in L5. A random fill color each mouse press.') -end + size(400, 400) + + -- Set the program title + windowTitle("Basic sketch") -function mouseDragged() - -- Draw a circle that follows the mouse when held down - circle(mouseX, mouseY, 20) + describe('Draws a yellow background') end -function mousePressed() - -- Pick a random color on mouse press - fill(random(255),random(255),random(255)) +function draw() + -- Fills the background with the color yellow + background(255, 215, 0) end \ No newline at end of file From d9175c4e40a7ae0a803d233fa035119370eeef7d Mon Sep 17 00:00:00 2001 From: Yam Date: Wed, 18 Mar 2026 13:01:02 -0400 Subject: [PATCH 7/8] sync fork & main --- main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 6916282..bb7a226 100644 --- a/main.lua +++ b/main.lua @@ -12,4 +12,4 @@ end function draw() -- Fills the background with the color yellow background(255, 215, 0) -end \ No newline at end of file +end From d3fc0324c3743c5330692b0f04a73e83eb1acb2e Mon Sep 17 00:00:00 2001 From: Yam Date: Wed, 18 Mar 2026 13:02:45 -0400 Subject: [PATCH 8/8] tweak: fix whitespace --- main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.lua b/main.lua index bb7a226..6916282 100644 --- a/main.lua +++ b/main.lua @@ -12,4 +12,4 @@ end function draw() -- Fills the background with the color yellow background(255, 215, 0) -end +end \ No newline at end of file