Saw the youtube video on this and saw a lot of places where I could optimize it, so I hopped on and made it a lot faster. I was getting around 9fps for 1000 triangles before, and now I'm hovering at about 18fps, so I've about doubled the framerate. There's some notes on how I optimized it in the notes section. If you're randomguy48, you're free to use this in your videos. If you have any questions, dm me-- I don't use scratch a lot though so I might not see it. This one also runs faster in turbowarp: https://turbowarp.org/885114016/
-Removed unnecessary 'Pen Up' and 'Pen Down' blocks. Due to the way scratch draws with the pen, you want to have as few of these as possible. Now, there's only one per triangle. -Precomputed a bunch of values-- if you're going to use something multiple times, may as well just calculate it once and store it. -Moved things OUT of the loop, if they were the same on each iteration. There's no reason to do the same calculation more than once. -Cleaned up unnecessary variables, rearranged terms to make the calculations simpler. -Used a more efficient calculation for the radius of the incircle -Removed slope representation. In general, it's good to use a vector with x/y components instead of slope-- 95% of the time, the calculations get simpler, and you don't need a special case for vertical lines. -Removed the distance checks from the incenter. If you think about it, the furthest one from the incenter is ALWAYS the one with the smallest angle-- since it's sharper, it's further away. And similarly, because of the law of sines, the smallest angle is the one across from the shortest side, which we already calculated. Most of the math, at this point, is very simplified and optimized. I've removed basically every square root except for a few I think are necessary, and most of the calculations have a lot fewer steps. The only place I still feel like optimizations can be made is on the if/else statement that defines d(a,D). If there's some way to remove the if/else statements entirely, this would likely speed up by a few more fps, due to how scratch handles branching (i think). If anyone can think of a formula that, for example, gets the distance of the furthest point to the incenter that takes in the lengths of the sides of the triangle, then we could pull that off, but I haven't gone and done that yet. Might give it a shot later.