You are browsing as a guest. Sign up (or log in) to start making projects!

Open comments for this post

2h 9m 32s logged

Devlog #1.2: Adding Elements One Shape at a Time!

Hey everyone, devlog #2! This week I added the first real drawing tools to the engine: lines,rectangles, and circles, all from scratch, no graphics library. Here’s how each shape works:

Lines

Lines use the Bresenham algorithm, which is an algorithm which finds the best way to create a straight line between two points. At first, I tried using the built-in SDL2 Line function, but it would produce choppy lines that wouldn’t be a straight, full line (see screenshot below). But, after implementing the Bresenham algorithm, it worked perfectly! Lines can be called using the line() function.

Rectangles

For Rectangles, I created two new functions. rectfill() and rect(). For rectfill(), I just hand to numpy to fill a whole block at once. For rect(), I just use the line() function 4 times to create the rectangle.

Circles

Circles use the midpoint method. The circles gave me the most trouble. My filled circle used different math than the outline, so it grew these weird single-pixel spikes around the edge (before pic). The fix was making the fill reuse the exact same midpoint math as the outline, so they finally match (after pic).

What’s Next?

In order for a game to work, we need the player to control something. So, the next step is adding movement. See you in the next devlog!

1
15

Comments 0

No comments yet. Be the first!