Home Artists Posts Import Register

Content

We are releasing one Bach Invention portrait every day for 15 days, with Chris (Gruber_music) who remade the musics in Pico-8. (I can't prove it yet, but I'm fairly certain he used some form of black magic)

Hi everyone!

We're starting the week with an effect super simple to implement and which is also a really great introduction to playing with Pico-8's memory buffer!

Pico-8 stores your sprites, the map, the sfx, the music and even what's on your Pico-8 screen in a buffer! This data takes the form of numeral integral values, going from 0 to 255 (each value is stored in one byte) and those values are disposed in very ordered manners, which makes it rather easy to manipulate them!

The Pico-8 manual has a section about the memory layout and the function you can use to affect it, (just look for "memory layout", it's towards the end) but today we're only looking at the screen portion of the memory, which starts at the address 0x6000 and ends at 0x8000. (those are hexadecimal numbers)

Here's everything you need to know: every byte in the screen memory contains the color of two pixels, every line of the screen is represented by 64 bytes, and of course there are 128 lines on the screen.

With the function 'memcpy(dst,src,len)', we can copy any portion of memory, with the length len and starting at the address src, to any other portion of the memory, starting at the address dst.

That means we can duplicate any line on the screen, by doing this: memcpy(0x6000+(y+1)*64, 0x6000+y, 64)

Or we can offset any line on the screen, like this: memcpy(0x6000+y*64, 0x6000+y*64+rnd(4)-2,64)

You may want to be careful though because the memory goes straight from one line of pixels to the next and you might unintentionally affect other lines.

But this last line of code is pretty much what we'll be using here! In this portrait, I used a 'for' loop with y going from 0 to 127, and in it we offset every line by '2.5*cos(y/32+time())'.

However, because one byte represents two pixels, we can only offset any line by multiples of 2 pixels. (sadly, we cannot offset bytes by 0.5) If you want to do odd offsets, you will have to code your own memcpy which would shift every byte onto the next one. It's very doable but we're not doing it today!

So instead, to make it look a little more natural, we'll use rnd()! Adding 'rnd(0.5)-0.25' to the offset will not do much but it should make the moving offsets look a little smoother!

Here's the final code:

<code>
for y=0,127 do
local a=0x6000+y*64+1
local ofs=flr(2.5*cos(y/32+t*2)+rnd(0.5)-0.25)
memcpy(a+ofs,a,60)
end
</code>

Yep, that's it! You'll note that we are moving only 60 bytes, rather than 64, so as not to overflow onto the other lines.

And if you take another look at the portrait, you'll see that I covered the sides of the screen so that you can't see the parts of the lines that are not being offset. If you don't want to be bothered cleaning up, just hide it away! ;D

That's it for today! My 5$ supporters can download the source files for this portrait and the others on this page!

Thank you for reading!

Take care!

TRASEVOL_DOG

Files

Invention No. 6 in E Major, BWV 777 (Pico-8 Edition)

Invention No. 6 in E Major, BWV 777 composed by J.S. Bach (1685-1750). Music arrangement by Gruber (@gruber_music) Artwork/Animation/Code by Trasevol_Dog (@TRASEVOL_DOG) Support us on Patreon! https://www.patreon.com/Gruber99 https://www.patreon.com/trasevol_dog Arranged and animated in Pico-8. Pico-8 is a fantasy console for making, sharing and playing tiny games and other computer programs. https://www.lexaloffle.com/pico-8.php

Comments

No comments found for this post.