i wrote a crude pong in L5. maybe i still need a better title for this library of Processing API in Lua with Love2d. (any suggestions?)
(music by Hildegard Von Bingen of course)
ok, i'm stopping for the night. the next things to do are to add typography functions, full mouse functions, and color modes, then I think that will be most of the API complete. I will still need to do bug testing.
Tonight I ran up against a problem I couldn't quite solve. I am using @Alexjgriffith suggestion to modify love2d's love.run() game loop and modified the default loop to not clear the screen between draw calls. Unfortunately, when drawing graphics from events (such as keyPressed(), keyTyped() ) the screen flickers, I think because of double drawing. I tried half a dozen different solutions but never quite found a satisfactory one unfortunately.
added frameRate() function.
while working on all this, had a bit of a think. i believe my flickering screen problem is a result of me hacking Love2d to work more like processing/p5. in the processing model, the approach is a synchronous model. draw runs once per frame. if too much processing happens, it slows down/frame rate drops. love2d takes the approach of drawing as many times as needed per game loop. logic is separated out into update(), while drawing is rendered in a separate thread, so game logic doesn't block rendering and realtime logic can be processed. In love2d, the emphasis is on realtime game processes.:
Don't want to jinx myself but I think I'm nearing completion of what I've set for my first run implementation of Processing API in Lua (via Love2d). I need to add in typography styling, some input/output options, and then probably have some drawing buffer debugging to do (which has been the most difficult thing for me to work through so far).
Today I added in describe() mode from p5.js and decided to try having it output text to the console for CLI screenreaders, but I need to look into more best practices for this.
I also implemented color tables, getting and setting colors, screenshotting (save() ) , smoothing/noSmoothing, strokeCaps, strokeJoins, displayWidth, displayHeight, millis(), mouseWheel() function.
i had temporarily for a day or two jinxed myself but i was able to figure out font loading and textSize, and other typography functions to emulate the processing api / flow (maintaining state).
next i turn to input/output (importing and exporting strings/json/tables?).
completed! loadStrings(), saveStrings(), loadTable(), and saveTable() complete. And current data formats are csv, tsv and lua.
I considered adding in a loadJSON() function, and still could at some point, but didn't think it made sense to DIY build a basic JSON parser or drop in something now. Could always be added later.
And with that, i've pretty much finished most of this first draft of implementing the API. there's a few remaining color modes to add in: HSB, a noise function, some vertex functions, and then lots of debugging and refactoring. notably, i have not tested on a Mac or Windows machine yet, or any computer other than my own! I also need to review how i'm implementing drawing from setup(). my current method is a bit dumb and draws twice. but ultimately, feeling pretty good about the library so far.
fiinished up a heckuva of a lot of the API and have been doing some tests (still need to do some more). I still need to add in colormodes HSB, HSA and a few related functions and then that'll be the first draft of L5. i am ignoring vertex functions for now (I could'nt quite wrap my head around it yet) and need to fix arcs.
I started building out intro documentation yesterday. I saw Casey and Lauren today and told them about the project and will share it with them hopefully soon. Lauren asked me about what if it catches on and I'm working on this for years and years lol.
Now I'm starting to think through documentation and reference sites. I looked at how they build the sites for Processing and p5 and I don't quite want to have to learn JSX and MDX. It's probably not too bad but I'm hoping for something much simpler at first. I can always build it out further later.
Anyone have a suggestion for building a programming language documentation and reference site? particularly that's beginner-friendly, emphasizes the reference, and makes it easy to handle/build a reference page for all of the language's functions? written in markdown, produces static pages, and can be hosted on a git forge and collaboratively built with others.
I am currently looking at:
* hugo documentation themes
* MKDocs
* adapting my own static site generator again - though this may not be robust enough over time
* i keep reading about documentation generators but i don't really grok the idea yet
there's not too much to this sketch, but it's fun trying out rapid code sketching with the language now
code:
require("L5")
function setup()
size(1920,1280)
windowTitle("Flag Thing")
noStroke()
createPage()
frameRate(1)
end
function draw()
createPage()
end
function createPage()
background(random(255),random(255),random(255))
fill(random(255),random(255),random(255))
circle(width/2,height/2,2/3*height)
end
with a bit of a whimper at the end of a friday night here i have implemented 99% of the API to an unpolished, un-refactored state. I've also assembled a bit of a TODO list so I can go in and start cleaning things up.
Today I added in colorMode() which lets you change between RGB, HSB and HSL. I thought I had it, but since I'm trying to emulate Processing and p5.js I always test against their outcomes and was dismayed to learn that using a html color name in p5.js even in another color mode should always output in RGB. And while this makes complete sense, I kept getting strange color output when rendering "orange" in HSL mode for example. I'm guessing my color juggling is off somewhere because it goes like this:
code:
colormode(HSL)
fill("orange")
square(0,0,100)
behind the scenes:
1. change global color mode state to HSL and max vals for HSLA are 360,100,100,100 default
2. retrieve orange as RGB(A) values. convert that to "orange" in HSL.
3. draw the square in that fill color
..
4. Hmm, yellow appears instead?
The problem exists between 2 and 3 (as well as between my ears).
just wasting time.
coded a basic chess set with manual placement of pieces, so not a really playable game yet, though maybe hexapawn soon though? (no promises!)
some bug fixin' of L5 today. I tracked down a bug that was messing up the origin point location for shapes and in the process fixed some shape drawing modes. In the evening I visited Offline for the Show Us Your Screens event, which was really nice, a totally packed crowed. Alex McLean gave a cool demo of new functions coming to Strudel, Tidal and other uzu-langs https://uzu.lurk.org/
I presented my work on L5 (it's first pubilc showing) and recent work in a bit of a hodge podge. It was really nice to hear others' talks and see/hear what they're working on.
Hmmmm, on a flight of fancy I decided to add in filters. I did it through adding in shaders, which I am really a dilettante in. But.....it's working. Took me 3 hours tonight. Not happy with gaussian blur but the rest are ok. Again, a bit of a hacky approach. Essentially i have a flag checking for whether if a filter is on. if so, set the shader, send optional parameter if available, draw canvas to screen, then set to no shader and turn shader flag off. currently prevents switching filters but i think i could solve that.
next i went back to my own artwork i had turned in for an exhibit and revisited the alternate version in L5 (i had sent the work as a p5.js project). now with the filters working my L5 version is fairly comparable to the p5 version. one weird timing issue in that L5 cycles the background color fade much faster. so i'll look at debugging that later.
pretty happy with things in L5 now. need to look at error() messaging, testing on Mac/Windows/any other computer besides my own, and documentation and testing next.
So glad I added filters! I'm able to just drop into L5 and work on some interactive artworks.
I started with some of the source images from the previous artwork I was working on, but made a different kind of variation. I may actually like this one better.
Code:
require("L5")
function setup()
--size(400, 400)
fullscreen(true)
windowTitle("The L5 logo")
imageMode(CENTER)
face={}
for i=1,30 do
face[i] = loadImage("face/"..i..".png")
end
drawFaces()
frameRate(1.7)
end
function draw()
drawFaces()
filter(THRESHOLD)
end
function mousePressed()
end
function drawFaces()
for i=1,100 do
image(random(face),random(height),random(height),width,height)
end
end
working on documentation website and a logo for L5. could this be it?
i am trying out mkdocs with the material theme. pretty mainstream i know. typical problem: was easy to get started and easy to render pages but customizing it is a pain since you have to figure out how they've done it and override their choices.
i made a batch of reference pages today. it's slow going because it lets me do bug testing and for each one i'm drafting the page by hand, converting processing or p5.js's reference examples to L5, then running the example code, screenshotting, converting to webp, formatting, etc. My friend told me "don't you have a student that can do that for you?" but i don't really work that way, and i don't have students to work on my projects! we don't have grad students at my school, for one. maybe i can write some automated script to run through the processing or p5 examples, do a brute force conversion to L5 and dump them into a templated page that i could then go through and clean up. it might make things faster. but writing that script could take me a couple hours.
I'm getting closer to being ready to build the website for the lang and think i'll likely use ye olde GitHub because of the pages feature, easy to collaborate, accept issues, even from beginners, and that's where Processing and p5.js are. But if I want to make a new organization the name L5 is already taken. So what to do: L5-Lua? L5-processing? L5-sketch? something else?
while i feel pretty great about my progress, i can see that hand retyping out the reference pages (and later the example pages, and my own p5.js code saved from the past decade of teaching) makes no sense.
And i don't have time/money/energy to recruit a volunteer or student so i reached for bash and sed and have a pretty good converter in less than 100 lines of code! i've tested it on a half dozen p5.js scripts so far and all have come out well. added a warning on the output of things to check.
https://gist.github.com/lee2sman/f84e03ef5e5209a9466d2c0795c2d50a
today i moved apartments so not a ton of coding. moving was half done by subway and half done by bike.
in the evening was the Creative Code Berlin meetup. before heading out i sent the latest L5 to Dan to check on his Mac. The horror, error! I could'nt understand it. (solution later...)
At the Creative Code Stammtisch i showed my work on L5 and other projects, and mentioned i need to test on Mac/PC hoping someone would say, here's my old Mac for testing purposes! Alas.
Presentation was fun and I got some good questions, including about later adding a 3d library. Maybe!
Back home at 11:30 and decided to see if i could figure out the Mac problem Dan had earlier. Ohoho: it seems that between Lua 5.1 and 5.2 they switched from unpack to table.unpack, however, Love uses LuaJIt and it might be the mac one compiles a different version of Lua?
Hmm, what to do about not having a Mac for testing. And Dan is 6 hours behind me, out with his family at dinner.
Well, I do have an iPad mini. And there is a Love2d Studio program. After I converted all table.unpack to unpack globally it solved that error. But now I get a bug that seems to result from shader code not working the same on iOS/Mac as on Linux. So I axed the shader code section temporarily on iOS (only used in my filters) and then I was able to get my sample programs to run. Phew, if not a total solution i'm at least glad things compile and work. I'll have to look into how to write shaders differently, or else have a mac and pc and linux version of the library. hmmmm.
this weekend was more social than coding but i did find a little time to do some work. the positive was that i solved one of the cross-platform bugs, and it was way simpler than i had feared. The other one seems to be a difference between how shaders are written on Linux vs Mac (and probably PC?) due to different renderers I think? I've not really delved into shaders much previously because i thought it didn't interest me, but since it's useful here i'm spending some time trying to understand at least the basics. i need to rewrite some of the shaders so they work on mac but i feel like i'm monkey-patching everything all the time. i am still "in-progress" on this but think i'll get it. honestly, so far the shaders are only used for filter() which is only a single function, but it's so very useful (threshold, grayscale, invert colors, blur) that i want to get it to work.
On the domain side, i purchased L5lua.org though not plopped anything down yet. i wanna try to get the reference done this week, then soft-launch, then add in more examples, tutorials and maybe even a video intro. I particularly think a video for "how to install" could be useful as i think that's the hardest part of getting started for non-command line users.
Feeling good: Mac bugs seem to be squashed now too, so the L5 library is cross-platform again.
I am going to transition back to continuing work on the Reference pages trying to finish up in the next week so that the L5 site can be ready to soft-launch, and then I can do a first round of testing L5 with friends.
I will try to devise a crazy bash script tomorrow that uses my p5.js -> to L5 bash script to convert the hundreds of reference pages examples and then test and modify them.
Somehow almost 2 weeks have gone by. Well, took a break from writing code (mostly) for the week since I had a friend in town and a series of concerts and such, and i started German classes last week, but that's no excuse!
After meeting with Stef and Raphael Friday to talk Processing we talked L5 too. I showed them my prototype and asked some questions.
Haha, they confirmed that blur is not gaussian blur as described on the reference but is exponential blur. And for example the perlin noise is actually Value Noise but mis-labeled and they may switch to Perlin or Simplex (which is what L5 is using due to its implementation in Love2d). They showed some tricks for automating converting the p5 reference pages from mdx (React) to my simple Markdown without frontmatter. I re-worked on this pipeline at home tonight and had an initial success converting them! Phew, the idea is to cut out a large time sink. I combined this with my bash script that converts p5.js code to L5 code. Finally, i worked on a script to screenshot all the example code and place in an assets directory, matching the reference page, but this will need some more work and need to be done after completing migrating p5 reference pages to L5 and removing any unused pages (and WEBGL examples). Excited to get back into this.
Ok, Using the brute force node script to convert p5.js's reference website (in react-markdown .mdx files with frontmatter) to simple markdown, and then using my sed/bash-script to convert the p5 reference examples to L5 code.
I'm doing this while watching the August WordHack event streaming on Twitch.
Ah, I just remembered Kit told me the p5js reference is also available as a json file. hmmmm. well, i already have my brute force method and seems to work for now to get my own reference pages started. i converted 105 pages that i hadn't written yet.
my next step will be to try to get a script to automate taking screenshots of running reference code examples with scrot, and saving them correctly to the assets folder with the right name and number.
and here's an example page from that process:
I did not write this page. It's a port of the p5.js "movedY" reference page here: https://p5js.org/reference/p5/movedY/
As with all of the other 105 pages, this page is originally in react-markdown, ported with my script to markdown. And the reference example code is converted from p5.js to L5 code. But I still need to have an image screenshot generated and review (and potentially edit) and text for things that are changed or different.
almost a month has passed and i am finishing up some other work this week so have time to get back into this.
on a whim i decided to write a turtle graphics library in L5 tonight and it was pretty fast and fun.
by the way, i am using the "Studies" approach to working that I think I gained from working in the Lines / Monome community and specifically the Teletype Studies. in this approach, you start using the tool/instrument from basics, creating a variety of projects and little experiments along the way. it's a way to learn the tool, like Drawtober or "everydays". (feel free to pipe in if you think i'm describing this incorrectly!)
My previous "Puzzlescript Studies" can be found here for example:
https://leetusman.com/puzzlescript-studies/
My work on "L5 studies" is a way for me to both bug test as well as find its affordances and limitations, but thankfully, since it's an implementation of the Processing language API, it's very front of mind to me.
In doing "L5 Studies" tonight I made a simple reimplementation of my posterer generator. The idea is it grabs a folder of images then generates 1 up, 2 up, 4 up, overlaid, etc layouts procedurally. In that process I realized I was missing the int() function from L5. How had I missed that from the Processing API? I added it, which wasn't quite as easy as leveraging the math.tointeger() function since that's been added in Lua 5.4 but Love2d uses an earlier version.
Next I finished the posterer program and now I'm ready for bed.
While doing L5 Studies tonight I wanted to draw to an offscreen buffer. The reason for this is because I wanted to draw freehand but have the underlying background color change randomly only once each time the mouse is pressed. To do this requires allowing continuous drawing on an offscreen buffer that then gets applied on top of the background. This meant it was time to implement offscreen buffers in the L5 library, so I created the createGraphics() function (that's what it's called in Processing API).
Added and tested. In this example I created a drawing program that lets me draw with photographs. The background only changes when the mouse is pressed down, but the drawn photos are persistent due to...the new createGraphics() function.
For my L5 Studies tonight I took on a bit of a challenge to make a collection of microgames in the style of beloved Warioware D.I.Y. I was looking earlier today to see if such a thing existed for Playdate. It seems like it should exist, no?! There was evidently a microgames jam with that idea in mind.
In any case, for my L5 programming tonight i ended up making some confused hacker mini game system with 3 different games. it's 'complete' in the sense that you can play it. it took me a couple hours and is a couple hundred lines of sloppy improvised coding. i've been using my own reference pages from the as-yet-unpublished L5 reference docs website (they still need work, more pages and polishing before going live), which has been helpful.
anyway, here's some gameplay of my silly microgames.
some work on L5 tonight.
i updated blur filter shader code from gaussian to exponential and dialed in some good defaults. now it more closely lines up with processing/p5.js.
i also started building out a table of processing family langs, inspired by the uzulangs page https://uzu.lurk.org/
lastly i tried some initial work to fix my setup / load system but didn’t get to a solution yet. essentially i am currently running setup twice, the first time to grab the set global vars like width and height among other things, the second time to run any graphics code. this is a modification of love’s library which normally only allows graphics code in draw. the problem is that running setup twice can cause issues.
i tried setting default sizing that dynamically changes when draw runs the first time but for example this won’t work for fullscreen programs. i will have to step through my modified love.run() to better understand exactly how and where various globals need to be set before graphics draw. there must be a simple solution but i can’t seem to get it yet.
Tonight in L5 studies (which i began working on AFTER I was already supposed to be asleep), I coded a simple toothbrush timer. It shows a moon or sun smiling depending on time of day, and a rotating toothbrush. Every 30 seconds the toothbrush moves to a different position to remind you to move to a different quadrant of your teeth. When you're done, it just says "Donezo" but maybe it should stick out its tongue? dunno. I need to go to bed or else I'd have the animation be smarter (toothbrush motion, and more precisely moving through the quadrants. maybe i'll finish that part tomorrow).
Anyway, this was a good task because it reminded me I should add hour() minute() and second() functions (trivially easy in Lua).
Also, earlier in the night I went out with Fletcher and Grayson, who both wanted to know why they or other folks that already use Processing or p5 would want to use L5. (or even vs TouchDesigner, OpenFrameworks, etc for that matter). Good question! I gave some answers! To be presented later, but here's a few Answers:
- works on old/ancient computers (need to define this)
- stable, fast, consistent
- cross-platform
- consistent cohesive syntax
- long term reliability of Lua and Love2d
- small (size)
- can package up sketches into application
- advantages of compiled languages, advantages (and disadvantages) of scripting language, advantages (and disadvantages) of dynamic typing
- desktop-oriented though same code can (likely) be packaged for browsers via love.js (Emscripten)
- works offline - doesn't require Browser
- more TBA
I'm participating in the Creative Code Lab at MotionLab in Berlin today and am working on L5. I cleaned up the comments in L5, then implemented custom shapes - adding beginShape(), vertex() and endShape() functions - copying most of the functionality from p5.js.
and in L5 Studies tonight before bed I decided to use the new functions to draw a grid of random polygon shapes and colors
Warning: fast flickering frames in video.
Lots of fun today: woke late, read in the cafe for two hours, took a long walk, cooked with friends, then two hours of no-input-mixer-board music with friends in the studio (and on clarinet).
I also worked on L5 for a couple hours and implemented a lot:
* I fixed looping! loop(), noLoop() and isLooping() should all work correctly now
* I added default width and height to the offscreen buffer for createGraphics
* I added the ability to draw textures to (custom) shapes with newly implemented functions texture(), textureMode() and textureWrap()
* I added a bunch of reference pages, example code and screenshots
Then implemented a rapid L5 studies test drawing randomly selected textures to screen.
a further iteration testing out the functionality added. i tried adding a folder of 50 JPGs to load but found it crashed the computer. i resized them to screen size instead of 4MB files and worked fine.
not sure what speed i should run this "screen saver" at or whether i should do the abstract or more clear version. here's a medium speed abstract one using graff images.
During my dogfooding process of creating little art and code projects ("L5 Studies") while working on the L5 language, tonight I added in a basic loadVideo function and created a minimal example showing how to play a video in L5.
Unfortunately, it can only play ogg theora (.ogv) video files, which means mov, mp4, mkv, avi files need to be converted prior to running. This is a limitation that results from the underlying Love2d library architecture as well as licensing issues, as far as I understand. While it is currently a requested feature, it does not look like mp4 and other video codecs will be added to the library too soon: https://github.com/love2d/love/issues/2089
To consider, shipping a little video converter tool or linking to one, just as Processing has a color selector and video recorder.
Processing: video requires a separate library. Can be any codec video. API differs from main Processing.
p5.js: video requires loading via DOM, then some trickery to hide from the screen and then to draw to canvas. not hard, but maybe a pain since a different workflow.
L5: video can only be Ogg Theora ogv file (so videos must be converted prior to being added to the sketch), but loading and playing video is trivial.
was encouraged by @dantescanline to keep going on the quasi-broughlike roguelike i started yesterday while watching the Roguelike Celebration @roguelike_con
i added a bit more functionality, but this is still far from a fun/playable game
@yhancik oh that's useful info, thank you. i did some research and found a lot here in their documentation. same issues as Love2d, interesting.
They have some good example ffmpeg commands here: https://docs.godotengine.org/en/stable/tutorials/animation/playing_videos.html#recommended-theora-encoding-settings
@exquisitecorp I hope you showed this