This video is titled 3D Point Matrix Spheres. Okay, so we finally made it to the point which we're going to start creating 3D surface geometry. We're going to work with our 3D point matrix system that I showed you in the last video over the next couple of videos. One of the, if I just generate this or 5 by 5 matrix, 5 by 5 by 5. One of the easiest primitives to start working with is a sphere. So, a sphere just needs a origin point, and it needs to know the radius, so it's very much like the circle which we started working with when we did the 2D point matrix. And so we're going to create a matrix of spheres. We can see what we can do with that. So back in our code. I've created another loop down here. In which I'm using the function AddSphere and using the dictionary points, and then I'm just going to give it a radius of 5 by default, and we'll see how that runs. So I still have the same structure here of the main and calling that point function and putting my i, j, k max. There's another function here, which I'll talk about in a second. Enter, Enter, Enter. Create my point grid and then create my spheres. So I get my mass of spheres. And then one question to ask like we did with the circles is, in what way can we start to sort of create variety in this? Of course, one way would be to manipulate the matrix like we did with the 2D point matrix. So I can change some of the values in there. So if I wanted to let's say just stretch it out in one direction, I might change my multiplier for K to 10 and that's going to give me a sort of stretched out tower of spheres. And then I could also apply a randomizer just to one direction. I don't necessarily have to apply it to all directions. See now I'm getting more overlaps between them. Now let's look at that function that I added. So, if we look back for a second at conditionals lesson from lesson two, I created this conditional statement in which I'm generating a random radius between 0 and 5. I'm then sort of determining out of that the limits of that using this conditional statement. And this is to affect the radius of a circle within this kind of range and delimit it. So what I've done is, I've sort of taken that snippet of code out of that lesson, out of that program. And I've made it into its own function, so called randomRadius. So here I'm clearing the radius variable like I did with the midpoint function, and it's just the same exact steps and then I'm returning that radius value. So, before I create my sphere I call up this function randomRadius. And I don't have to, it's not taking any arguments. It's just calling it up and asking it to generate something and return it. So it returns that value. It saves it in the variable radius here and then I can put it in here. So now I should get variable size spheres in my sphere tower. So let's run that. So, you can see too that, as I get more geometry in here, it sort of slows the machine down. It's taking time for it to generate. And then at one point it kind of like stops doing a redraw, and it just does the calculation in the background. And then it shows the final form. There is a function which actually allows me to turn off the redraw. And often I will use it down here. It's called enableRedraw. And if I set it to faults before I call my function, it's not going to redraw. And then when it's done with whatever the function is doing. It always comes back to where it was called from, and so it's going to run the next line of code after it. And now if I set EnableRedraw to True, it will redraw the scene. So it's going to run a lot faster and we'll see it's not going to show me anything and then all of a sudden everything is going to be produced. So it can be handy to use it, When you have a lot of geometry, so it's calculating, and then it just, bam, shows it. Okay, one last thing with this, another function I can introduce. And this is color, we started to maybe introduce color a little bit within the animation, [COUGH] by just changing the background and the line color. I can change an object's color by using the function ObjectColor and then giving the ID of that object. And then I need to give a tupple of three values and where that comes from, that's my RGB values. So, let's see if we click on a color square here in the layer. I'll see if I move this around or select a color here. My RGB values in numbers that go from 255 for white to 0 for black. And any combination in between those is going to give me a value for color. So if I want to sort of like purplish color, maybe I'll go 75, 75 and let's say 150. So it's going to change those, the colors of the spheres to that. So if we run this now, Now I get a sort of purpley sphere. Now here's something pretty nifty. I have a little equation here. And all this equation is doing, you could look at it, study it a bit and take it apart, but all it's doing is it's using IMAX, JMAX, and KMAX and using the loop variables as multipliers in this equation. So I'm going to get a range of values for my 0 to 255 across this and should give me a gradient of color. And you can play with this in different ways to get different levels of gradient depending on how big your matrix is. But this should work with any size matrix. So I'm going to replace this here with that section of code and then let's see what that produces. Let's take this out. And now I get this nice rainbow gradient of colors which is pretty cool. Okay, one last thing with this and you're in video exercise what you could do is I've added a line of code down here. So you could input an attractor point, you're going to need to pass that attractor point up to the point matrix function. And then [COUGH] look back at your attractor point code that we used with the circles and try to adapt that to change the radius of the sphere using an attractor point. So you're going to turn this random radius off to do that. And you're going to have to find the distance between each one of these points, right, and the attractor point and then use that value to change the radius. So, try that out.