# What is the \*most efficient\* way to draw a single pixel to the screen?

**URL:** https://forum.makecode.com/t/what-is-the-most-efficient-way-to-draw-a-single-pixel-to-the-screen/35451
**Category:** Help
**Tags:** graphics-and-math
**Created:** [April 8, 2025, 6:23pm UTC](https://forum.makecode.com/t/what-is-the-most-efficient-way-to-draw-a-single-pixel-to-the-screen/35451 "2025-04-08T18:23:53Z")
**Posts on this page:** 1
**Showing post:** 13

<div class="post-metadata">

### Author: ![MrJones](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mrjones/32/21218_2.png) [@MrJones](https://forum.makecode.com/u/MrJones)
#### Post date: [April 11, 2025, 4:39pm UTC](https://forum.makecode.com/t/what-is-the-most-efficient-way-to-draw-a-single-pixel-to-the-screen/35451/13 "2025-04-11T16:39:14Z")

</div>

@richard  
I was actually curious what that looked like, I spent an hour trying to find all the native implementations but got lost in the nest. With my current shaded triangle, I tried replacing my setpixel with the native one and it halved my framerate, but maybe I can find a clever way to use the native line drawer instead of ever touching setpixel. This is what my implementation looks like right now

 ![](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/b/d/bdbfa89cf78426ae64baec2094c96b10e83cf578.png)  
I replaced my array of buffers with a single buffer of size 19200 that contains the color for every pixel on the screen. I use math to set it at the correct location, assuming the center of the screen is 0,0 (more or less). Then this is what my update loop looks like  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/5/f/5f18e70ad07590aba65e476f3772df8f79c5ff20.png)  
I don’t intend on storing points like this in the long run, though I haven’t decided definitively how I’d like to. I know each {} allocation is pretty hefty per @mmoskal’s [post](https://forum.makecode.com/t/makecode-kart/5787/58) in the MakeCode Kart thread  
As I mentioned in my response to @kwx, I also intend on removing the function calls and placing the code directly into my update loop, to remove a little bit of overhead. I have them separate for now for convenience. I’ve also done my best to avoid floating point math where possible, but I’m sure there are a few equations sneaking around that I’ve missed.

Here’s the shaded triangle code I have right now, as I’m starting the perspective projection code.  
A toggles wireframe, B randomized point locations and h values

> **[ShadedTriangle](https://arcade.makecode.com/27344-29459-48923-46280)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

_[View the full topic](https://forum.makecode.com/t/what-is-the-most-efficient-way-to-draw-a-single-pixel-to-the-screen/35451)._
