{"id":204,"date":"2024-06-08T21:04:00","date_gmt":"2024-06-08T21:04:00","guid":{"rendered":"https:\/\/santiagomarquezsolis.com\/index.php\/2026\/04\/20\/exploring-creative-programming-with-rust-and-ggez-fire-effect\/"},"modified":"2026-04-20T16:13:10","modified_gmt":"2026-04-20T16:13:10","slug":"exploring-creative-programming-with-rust-and-ggez-fire-effect","status":"publish","type":"post","link":"https:\/\/santiagomarquezsolis.com\/index.php\/en\/2024\/06\/08\/exploring-creative-programming-with-rust-and-ggez-fire-effect\/","title":{"rendered":"Exploring Creative Programming with Rust and ggez. Fire Effect."},"content":{"rendered":"<p>Today I bring something a little different. Since Rust has become one of the trendy languages and one of my favorites for working with Blockchain, I&#8217;ve been wondering whether it would be a good idea to use it for some creative programming \u2014 in the style of the Demoscene that was popular in the days of the Spectrum or 16-bit computers. One of the most famous demos, for example, was \u00abPanic\u00bb by the FutureCrew group, which got the most out of the machines of that era. I think we can safely say that creative programming is an exciting discipline that combines programming with artistic expression. In this article, I&#8217;ll show you how to use Rust, a language known for its performance and safety, together with the <code>ggez<\/code> library to create creative programming projects.<\/p>\n<p>Creative programming is a form of programming where the main goal is to create something expressive rather than functional. It is an intersection of art and technology where the code is the medium for creating visual experiences. In this article, we will use Rust and the <code>ggez<\/code> library to implement a fire effect \u2014 one of the most iconic effects from the demoscene era.<\/p>\n<h2>What is ggez?<\/h2>\n<p><code>ggez<\/code> is a Rust library for creating games and multimedia applications. It provides a simple and lightweight framework for creating 2D graphics, audio, and input. We will use it to render our fire effect.<\/p>\n<h2>Fire Simulation Logic<\/h2>\n<p>Before diving into the code, let me explain how the fire simulation works. This is a classic algorithm to simulate fire effects using color palettes and 1D arrays in a fun and original way:<\/p>\n<ul>\n<li><strong>Fire Palette:<\/strong> A predefined color palette is used to represent different fire intensities, from dark colors (low intensity) to bright colors (high intensity).<\/li>\n<li><strong>Fire Array:<\/strong> A 1D array of u8 values stores the fire intensities for each pixel in a 2D grid.<\/li>\n<li><strong>Initialization:<\/strong> The fire array is initialized with zeros, and the bottom row of the array is set to maximum intensity to create the fire source.<\/li>\n<li><strong>Propagation:<\/strong> Each pixel&#8217;s fire intensity is updated based on the pixel directly below it. A random decay value is subtracted to simulate the cooling of fire as it rises.<\/li>\n<li><strong>Rendering:<\/strong> Each pixel is drawn as a rectangle on the screen, with its color determined by its intensity value from the fire palette.<\/li>\n<\/ul>\n<h2>Technical Implementation<\/h2>\n<p>To implement this fire effect in Rust with ggez, we need to manage the fire state and update it frame by frame. The code creates a grid of pixels and simulates the upward spread of fire with cooling and randomness to create a realistic effect.<\/p>\n<p>The implementation maintains a fire buffer where each cell represents the intensity of fire at that position. The bottom row is continuously set to maximum intensity (255) to act as the heat source. For each frame, we propagate the fire upward by averaging neighboring cells and subtracting a small random decay value.<\/p>\n<h2>Getting Started<\/h2>\n<p>To run this project, you need to have Rust and Cargo installed. Add the following dependencies to your <code>Cargo.toml<\/code>:<\/p>\n<pre><code>[dependencies]\nggez = \"0.9\"\nrand = \"0.8\"<\/code><\/pre>\n<p>The fire effect demonstrates how Rust&#8217;s performance characteristics make it ideal for real-time simulations. The combination of Rust&#8217;s safety guarantees and ggez&#8217;s simplicity makes it a great choice for creative programming projects.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we&#8217;ve explored how to create a classic demoscene fire effect using Rust and the ggez library. This example shows that Rust is not only powerful for systems programming and blockchain development but also for creative and artistic programming. The key concepts we covered include:<\/p>\n<ul>\n<li>Using color palettes to represent intensity values<\/li>\n<li>Implementing cellular automaton-style propagation<\/li>\n<li>Using ggez for real-time 2D rendering<\/li>\n<li>Leveraging Rust&#8217;s performance for frame-by-frame simulation<\/li>\n<\/ul>\n<p>I hope this inspires you to explore creative programming with Rust. The possibilities are endless \u2014 from particle systems to procedural art, Rust combined with ggez can bring your creative visions to life.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I bring something a little different. Since Rust has become one of the trendy languages and one of my favorites for working with Blockchain, I&#8217;ve been wondering whether it would be a good idea to use it for some creative programming \u2014 in the style of the Demoscene that was popular in the days [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[162,164],"tags":[166,168,170,172],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-blog-en","category-creative-coding-en","tag-creative-coding-en","tag-fire-effect-en","tag-pixel-art-en","tag-rust-en"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/posts\/204\/revisions\/230"}],"wp:attachment":[{"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/santiagomarquezsolis.com\/index.php\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}