Interactive Raylib with Common Lisp
Comments
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
All right, so let's do some graphics in Common Lisp today. So, this video, just as a preamble, uh is a is a result of a conversation I've been having with a couple of people, and I thought it was a good idea to make a video on the subject where I touch on a specific point they asked, which is uh what do I like in a interactive living system, and what is what the hell is that, right? So, the idea is that I'm trying here today to bring something that is more approachable to the average programmer. Um the point is I raised that this argument
I wouldn't even say argument, but I raised this I touched on this topic on my new Shepherd video where I was talking about this idea of having Emacs, right? So, when you think of an operating system, an interactive system where you click on stuff, um you actually are not really invited to explore the internals, right? So, Windows, when you open Windows, uh you can't just go to the kernel of Windows and like modify stuff and >> [snorts] >> uh on the fly, right? That that doesn't happen. You can make drivers and etc. That's true. Uh but you are not actively a participant of the execution of the program.
And I think that's a different story with tools like Emacs. I'm sorry. With tools like Emacs because they do actively invite you to explore things around. And uh I want to bring something using Raylib. So, there's this project here I've been working with a couple of friends, and essentially what it is that's too big uh is a visual novel, okay? Uh for a promotional as promotional material for a couple of projects that we are running right now. And uh we're telling we're trying to tell the story of the thing and like uh have a good time developing a game uh that we can be proud of in uh on telling our journey uh on designing this database and this language for the B that we've been working on.
Um it's been going for more than a year by now. So, anyway and I felt like Raylib is a perfect example because most people nowadays they're familiar with the thing. It became very popular because it's very easy to port, right? Uh it's just C so you can just embed everywhere. And I somebody was kind enough to provide Common Lisp bindings for Raylib.
So, let's just use that. I already have it all set up. And I just made this file called cube like apart from everything else. And uh what it does is that it essentially tries to design that rotating cube you can see squished on the like above. Let's connect here. So, let's do this.
And let's change to VN because that's a package where it And let me clear this up and zoom in a little bit. So, you can see here that we have this class that is a cube. So, that defines the size, angle, speed,
color in RGB RGBA. Uh X Y and Z coordinates and it's as well as it's accessors. Right, so if we see we have here defined this variable that is exposed to us. I mind you, I just connected as a REPL uh with a REPL. This guy is connected on this thing here. So uh I can actually inspect things that are in there. So, if I do this, that is the cube and then if I click I can see all the properties of that cube, right? So I can see like oh, okay. So, the speed of this guy is this thing. So, you can modify, you can browse around. Uh we can also access with those accessors up there. So, we can do let's pick speed.
And uh we're going to do on the variable with your mouse. And we get 45, right? Uh but we can do also set F. So, we're going to set on that region. Let's put like a 100. So, that increased a little bit. Let's put 500. That's much faster. 10,000. Well, 1,000. That's much faster. So, you can actually modify on the fly the object that is already defined, right? So, you can do that with basically every object that is in here. We have the camera defined. We have this thing that calls the update. So, for every frame, it keeps updating. Um then there's this code here that draws the scene, right? And what it's doing is that it's basically picking the sizes, uh setting the wires. So, you can Let me spin Let me spin something that we can actually see, right? Uh so, for example, it has wires, like white wires. We can omit that. And if we recompile, there we go. So, the wires are are gone, right? So, you can actually explore the thing and do your stuff. But, I think this is extremely valuable, especially for this kind of task. Um then you need some sort of uh adaptability, right? So, this gives you a very fast feedback loop uh to interact with things.
Um So, let's try to do something to actually command the thing, like to um make a control the cube, right? So, let's first do a function here that we're going to call, I guess, control cube. And there we go. And uh control cube will essentially receive a key. Uh and we're going to do a cond, like condition. And uh we're going to check if it's equal, and that is just a symbol, so I think it should be safe to do this. And I think Realm has a bunch of keys, right? So, if we there's this function here. I'll stick a look. Uh and then get key pressed.
That gives you just a key that is pressed. Right now, I didn't press anything, so that's going to be null, right? But that is the function. So, we're going to use that. Uh let me leave that here. Oops. Let me leave that here. Uh so, if we press right,
uh yeah. So, if you press right, that will be equal, so that will fire this condition. And uh what we're going to do is essentially just do a set F
of the uh if we're pressing right, we need to increase the uh the X. Let's just do the X. Uh I mean, the camera is rotated, so we would have to transform the thing. But let's just do one thing at a time, right? So, we're going to set the cube X. Uh and then we're going to need the cube. It's a global variable I have there. And we're going to actually increment that. So, there's an increment function in Cath, if I'm not mistaken. So, if we pass uh Actually, let's do I'll do I'll be very explicit. So, let me do this cuz uh people might not know this.
So, we're going to access that, and we're going to have to update the value. So, we're going to have to pick that up again. Right? So, we're going to pick that up here. So, that's going to pick the value and increment with one, right? So, if we see this, that is one. So, the value is zero, I believe. It's on the center. And uh we're just increasing. So, if you put 10 here, that's 10. Cool. So, it's going to increase one in one and set on that position. Nothing really extraordinary there. Uh Okay. So, the idea here is very simple. So, let's let's make another condition for the right, right?
So, let's do that here. Let me actually cut this. And then paste it here. I swear I deleted Oh, right. It's cutting. It's word wrapping, but that's fine. So, let's do left. And instead of increasing, we're going to decrease. So, if you go to the right, we increase. Left, we decrease. Or maybe I mean, yeah, that that looks okay. It's just going to rotate, change the position. It's rotating, right? Uh and that's it. So, that's our function. We can define it. Control cube. And we can call this control cube uh function on the drawing scene, right? So, right before we draw, we need to find a a place to put that event, right? Because we're going to get that event coming, and we need to actually set uh the thing before. So, we need to actually pick that before we pick the X, Y, and Z here. So,
we could do something like this.
Uh we need we need to call control cube.
This probably not the best way to do it, but we're going to do it anyway. And we're going to call that funny function. So, E uh get key pressed. So, that would pass the key, and that's going to set the the values mutably, and we're going to render this block of this let here, this lexical scope, and uh this is scope is going to get the values updated, right? So, if we do this now, and what did I do? And uh I think I blew up. Let's do a thing here. program
Let's do program. So, that is like to make a procedural block, and we're going to print. So, format I think we can format with nil, so like that prints, if I'm recall correctly. And uh we're going to do right.
That's it. Yeah. Uh and we're going to do the same here. So, now let's put here. Uh and left. And I think I forgot the other case, which is the true, right? So, if it is nothing that I'm pressing, see? We're not going to do anything. We're just going to print something to see if it's calling this function. So, we can just paste format nil default. So, that's going to print ferociously. Uh I hope.
There we go. Wrong number of arguments passed to the function EQ. Uh that is actually true. Uh So, I didn't pass the key to compare. That is very silly. Uh so, we should pass the key here. So, I'm comparing if this guy is equivalent to the key, right? That makes sense. There we go. So, it's back, and it's not complaining anymore.
There we go. Uh Let me actually put this. That's better to read, I guess.
Oh, much better. All right. So, we can actually now do stuff. So, let me switch here to this. And if I press right, it's going further from the center, right? If I press left, it goes here.
Isn't that cool? That is very cool. So, like you That's the idea. I mean, I can keep going, but I think the point is already there. So,
there's more stuff you can play around like there is probably is key down, is key
pressed, is key released. So, you can like find the right place to put these things in the uh place and actually modify them. I could do all sorts of stuff like for example, I did a set F here on the speed, but we can do like uh size, I think. And uh just set the the thing enormously, right? I think it 10 is already big. Let's put five. So, you can change the size. Oops. You can modify the thing however you want. Um that's what I mean with a living system, right? Things are here available
and you can inspect them and modify them as they run. This is extremely valuable when you have something uh when you have something that is um that requires your attention, right? So, right now we're so used to this look to this big uh feedback loop uh feedback loops that we have that we hardly notice how harmful it is to
actually take a long time to switch your context uh to actually understand what's going on on whatever, right? Uh I think there was this article I saw recently. If I find that out, I'll put it on on the description. But, it was an article of a guy talking about uh uh how long your CI should take to run, right? And I think the idea is very much the same. It is um the longer it takes, the slower the feedback loop is. And the more probable it is for you to lose context of the task, right? Uh you start to lose context inevitably. Um And I'm not talking about like an LLM context, obviously. I'm talking about somebody uh like memory, like losing memory and losing track of the subject. We If we If we change subjects like 10 times a day during work, that's going to be very hard to focus on any of those tasks. So, the tighter you can make the feedback loop to your programming, I think the better.
Uh because that that will be invariably help you to test the code as you do it. And I think that's very valuable because then allows a lot of brainstorming, a lot of uh ideas can come out of that and so on. So, anyway, uh that was it. That was a short video. I think in the next one that I'm making is uh I was doing this just as a peek.
I was doing this um I was working on this project here. Uh Let me actually go to the readme and I don't remember where I put it. Yeah, you also the tools. And I was doing Pearl, right? So, the next thing is like a why you shouldn't use Python and you study is just Pearl. I know that sounds crazy, but anyway. That's it. Um thank you for watching and see you next time.