Tiny Code Christmas in MicroW8
If you’ve already completed Tiny Code Christmas with either TIC-80 or PICO-8 and you’re not quite sure where to go from here, Superogue has kindly ported the challenges to MicroW8! MicroW8 is a WebAssembly based fantasy console designed specifically for sizecoding with an optional language CurlyWAS that makes WebAssembly a little easier to deal with.
Check out this tiny intro for the MicroW8 by exoticorn, the creator of MicroW8:
And this even tinier one by Superogue:
Getting started⌗
Unlike TIC-80 and PICO-8, MicroW8 doesn’t have its own built in editor, so you can use the text editor of your choosing, and run MicroW8 from the command line, downloads are available on the MicroW8 site. Don’t forget to scroll down for the EXTRA challenges!
Day 1⌗
Go to Day 1 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(-16);
// draw tree
let i: i32;
loop lines {
let w = (i % 32 + i / 2) as f32;
let y = (i + 64) as f32;
line(160_f - w, y, 160_f + w, y, -20);
branch_if (i := i + 1) < 128: lines;
}
// draw trunk and snow bottom
rectangle(142_f,192_f,32_f,32_f,-26);
rectangle(0_f,224_f,320_f,16_f,-8);
}
Day 2⌗
Go to Day 2 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(-16);
// draw tree
let i: i32;
loop lines {
let inline w = (i % 32 + i / 2) as f32;
let inline y = (i + 64) as f32;
line(160_f - w, y, 160_f + w, y, -20);
branch_if (i := i + 1) < 128: lines;
}
// draw trunk and snow bottom
rectangle(142_f,192_f,32_f,32_f,-26);
rectangle(0_f,224_f,320_f,16_f,-8);
// draw snow
let inline t = (time()*60_f) as i32;
let i: i32 = 0;
loop drawsnow {
let inline snow_wiggle = (sin(i as f32 + time()) * 8_f) as i32;
let inline snow_x = (i * 931) % 320 + snow_wiggle;
let inline snow_y = (i * 357 + t) % 240;
setPixel(snow_x,snow_y,-8);
branch_if ( i:= i + 1) < 128: drawsnow;
}
}
Day 3⌗
Go to Day 3 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let x: i32;
let y: i32;
let inline t = (time() * 10_f) as i32;
loop drawloop {
let inline c = ((x+y) & (x-y)) / 8 + t;
setPixel(x, y, c as i32 - 32);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 4⌗
Go to Day 4 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let x: i32;
let y: i32;
let inline t = time() * 4_f;
loop drawloop {
let inline c = sin(x as f32 / 37_f - t) + sin(y as f32 / 23_f + t) + sin(x as f32 / 17_f - t) + t;
setPixel(x, y, c as i32 - 32);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 5⌗
Go to Day 5 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let x: i32;
let y: i32;
let inline t = time() * 4_f;
loop drawloop {
let inline xc = (x-160) as f32;
let inline yc = (y-120) as f32;
let inline u = atan2(xc,yc)*3 as f32;
let inline v = 9999_f / (xc*xc + yc*yc + 1_f);
let inline c = (u as f32) as i32 & (v+t) as i32;
setPixel(x, y, c as i32 - 32);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 6⌗
Go to Day 6 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let inline t = time()*60_f;
let i:i32;
loop textloop {
// calculate character position
let inline x = i * 10 - t as i32 % 10;
let inline y = (sin(x as f32 / 16_f) * 2_f * i as f32) as i32 + 100;
// set text to graphics mode and set character position
printChar(5);setCursorPosition(x,y);
// print character
let inline textofs = ((i+t as i32/10)%40);
printChar(textofs?0x20000);
branch_if i := (i + 1) % 40: textloop;
}
}
data 0x20000 {
"hello tiny code christmas 2024"
}
Day 7⌗
Go to Day 7 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let x: i32;
let y: i32;
let inline t = time() * 10_f;
loop drawloop {
let inline c = sin(x as f32 / 37_f - t) + sin(y as f32 / 23_f + t) + sin(x as f32 / 17_f - t) + t / 4_f;
setPixel(x, y, (sin(c)*7_f) as i32 + 72);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 2) % 240: drawloop;
}
// doublesize scroller
let inline tt = time()*60_f;
let i:i32;
loop textloop {
// calculate character position
let inline x = i * 20 - tt as i32 % 20;
let inline y = (sin(x as f32 / 16_f) * 3_f * i as f32) as i32 + 100;
// set text to graphics mode + set double text scale
printChar(5);printChar(30);printChar(2);
// print character with shadow
let inline textofs = ((i+tt as i32/20)%40);
setTextColor(0);setCursorPosition(x+2,y+2);printChar(textofs?0x20000);
setTextColor(i%8+36);setCursorPosition(x,y);printChar(textofs?0x20000);
branch_if i := (i + 1) % 40: textloop;
}
}
data 0x20000 {
"Hello Tiny Code Christmas 2024"
}
Day 8⌗
Go to Day 8 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
// cls(0);
let inline t = time();
let i:i32;
loop circloop {
// calculate character position
let inline x = (sin(i as f32 / 6_f + t) * 99_f) + 160_f;
let inline y = (sin(i as f32 / 7_f + t) * 99_f) + 120_f;
circle(x,y,8_f,i%10+66);
// set text to graphics mode and set character position
branch_if i := (i + 1) % 16: circloop;
}
let j:i32;
loop copyloop {
j?0x80 = j?0x82;
branch_if j := (j + 1) % (320*240): copyloop;
}
}
Day 9⌗
Go to Day 9 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
// cls(0);
let inline t = time();
let i:i32;
loop circloop {
// calculate character position
let inline sx = (sin(i as f32 + t) * 160_f) as i32 + 160;
let inline sy = (sin(i as f32 * 3_f - t) * 99_f) as i32 + 120;
let xi:i32;
let yi:i32;
loop shape {
setPixel(sx+xi,sy+yi,(getPixel(sx+xi,sy+yi)+1)%16);
branch_if xi := (xi + 1) % 16: shape;
branch_if yi := (yi + 1) % 16: shape;
}
// set text to graphics mode and set character position
branch_if i := (i + 1) % 16: circloop;
}
}
Day 10⌗
Go to Day 10 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let inline t = time() * 4_f;
let inline part = (time() as i32) / 4;
let inline fade = abs(sin(t*6.28/32_f));
let x: i32;
let y: i32;
loop drawloop {
let inline xc = (x-160) as f32;
let inline yc = (y-120) as f32;
// handle effect
let u: f32;
let v: f32;
if (part & 1) {
u = atan2(xc,yc)*18_f;
v = 19999_f / (xc*xc + yc*yc + 1_f);
} else {
let inline z = (sqrt(xc*xc+yc*yc)/16_f-1_f+0.1);
u = xc / z;
v = yc / z;
}
let inline c = ((u+t) as i32 & (v+t) as i32) & 15;
setPixel(x, y, (fade * c as f32) as i32 + part*16);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 11⌗
Go to Day 11 to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let inline t=time();
let xi: i32;
let yi: i32;
let zi: i32;
loop dots {
// dot positions
let inline X = (xi - 8) as f32;
let inline Y = (yi - 8) as f32;
let inline Z = (zi - 8) as f32;
// rotation angles
let inline xa = t;
let inline ya = cos(t);
// 3d rotation and projection
let inline x = X*cos(xa) - Y*sin(xa);
let inline z = (x*sin(ya) + Z*cos(ya)) + 16_f;
let inline cx = (x*cos(ya) - Z*sin(ya)) * 127_f/z + 160_f;
let inline cy = (X*sin(xa) + Y*cos(xa)) * 127_f/z + 120_f;
// radius & color
let inline r = 8_f-z/2_f;
let inline c = (r as i32)+176;
// fake z-buffer
let inline oldz = getPixel(cx as i32,cy as i32);
let inline rr = select(c>oldz,r,0_f);
// draw dot
circle(cx, cy, rr, c);
branch_if xi:=(xi+1) % 17: dots;
branch_if yi:=(yi+1) % 17: dots;
branch_if zi:=(zi+1) % 17: dots;
}
}
Day 1 Extra⌗
Go to Day 1 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
// set RGB palette
let p:i32;
loop palloop {
(p<<2)?0x13000= p;
(p<<2)?0x13001= p*2/4;
(p<<2)?0x13002= p/4;
branch_if p := (p+1) % 256: palloop;
}
// fire effect
let x:i32;
let y:i32;
loop drawloop {
let inline c=getPixel(x,y);
let inline cl=getPixel(x-1,y+1);
let inline cb=getPixel(x,y+1);
let inline cr=getPixel(x+1,y+1);
setPixel(x, 239, random());
setPixel(x, y, (c+cl+cb+cb+cr)/5);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 2 Extra⌗
Go to Day 2 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
let inline t = time();
let x:i32;
let y:i32;
loop drawloop {
// position of metaball 1
let inline x1 = (sin(t * 3_f) * 199_f) + 160_f;
let inline y1 = (sin(t * 4_f) * 99_f) + 120_f;
// position of metaball 2
let inline x2 = (sin(t * 2_f) * 199_f) + 160_f;
let inline y2 = (sin(t * 1_f) * 99_f) + 120_f;
// distance of the 2 metaballs to the pixel position
let inline dist1 = 399_f / sqrt(pow(x1-x as f32,2_f)+pow(y1-y as f32,2_f));
let inline dist2 = 399_f / sqrt(pow(x2-x as f32,2_f)+pow(y2-y as f32,2_f));
let inline c=min(dist1+dist2,15_f) as i32;
// draw pixel
setPixel(x, y, c + 64);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 3 Extra⌗
Go to Day 3 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
let i:i32;randomSeed(0x1111);
loop initloop {
i?0 = random();
branch_if i := (i + 1) % 64: initloop;
}
let j:i32;
let k:i32;
cls(0);
let inline t = time();
loop drawloop {
// check all points against all points
let inline x1 =((j?0)*2 + (0!TIME_MS / 16)) % 320;
let inline y1 =((j?1) + (0!TIME_MS / 24)) % 320;
let inline x2 = k?0;
let inline y2 = k?1;
let inline dist = sqrt( ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) as f32 ) ;
if (dist<30_f) {
line(x1 as f32, y1 as f32, x2 as f32, y2 as f32, k + 32);
}
branch_if j := (j + 1) % 63: drawloop;
branch_if k := (k + 1) % 63: drawloop;
}
}
Day 4 Extra⌗
Go to Day 4 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let x: i32;
let y: i32;
let inline t = time();
loop drawloop {
let inline xc = (x-160) as f32;
let inline yc = (y-120) as f32;
let inline u = (xc*cos(t)-yc*sin(t));
let inline v = (xc*sin(t)+yc*cos(t));
let inline c = (u as f32) as i32 & (v+t) as i32;
setPixel(x, y, c/8 + 80);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 5 Extra⌗
Go to Day 5 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let x: i32;
let y: i32;
let inline t = time();
loop drawloop {
// floor perspective
let inline z = abs(y as f32 - 100_f)+1_f;
let inline xc = (x-160) as f32 * 64_f / z;
let inline yc = (y-120) as f32 * 256_f / z;
// rotate floor
let inline u = (xc*cos(t)-yc*sin(t));
let inline v = (xc*sin(t)+yc*cos(t));
let inline floorcolor = ((u as i32 & (v+t) as i32) / 8 & 15) + 64;
let inline skycolor = y/8+y%3 + 32;
let inline c = select(y>100, floorcolor, skycolor);
setPixel(x, y, c);
branch_if x := (x + 1) % 320: drawloop;
branch_if y := (y + 1) % 240: drawloop;
}
}
Day 6 Extra⌗
Go to Day 6 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
cls(0);
let inline t = time();
// vertical rasters
let lx: i32;
let ly: i32;
loop rasterloop {
let inline sv = sin(ly as f32 / 4_f + t) * 64_f + lx as f32 + 64_f;
line(0_f, sv, 320_f, sv,(16*ly) + lx + 32);
branch_if lx := (lx + 1) % 16: rasterloop;
branch_if ly := (ly + 1) % 8: rasterloop;
}
// kefrens bars
let kx: i32;
let ky: i32;
loop kefrensloop {
let inline sv = sin(ky as f32 / 23_f + t) * sin(ky as f32 / 13_f + t * 3_f) * 128_f + kx as f32 + 160_f;
line(sv, ky as f32, sv, 240_f, kx-16);
branch_if kx := (kx + 1) % 16: kefrensloop;
branch_if ky := (ky + 1) % 240: kefrensloop;
}
}
Day 7 Extra⌗
Go to Day 7 Extra to see the challenge.
include "microw8-api.cwa"
export fn upd() {
let inline t = time();
let c: i32;
let i: i32;
loop snowflakeloop {
let inline r = 4_f * c as f32 * asin(cos(t+c as f32));
let inline x = (sin((i+c) as f32 -t + c as f32) * r) + 160_f;
let inline y = cos((i+c) as f32 - t + c as f32) * r + 120_f;
setPixel(x as i32, y as i32, -c);
branch_if i := (i + 18) % 360: snowflakeloop;
branch_if c := (c + 1) % 16: snowflakeloop;
}
}
Day 8 Extra⌗
Go to Day 8 Extra
include "microw8-api.cwa"
export fn upd() {
let inline n = 60;
let inline m = 120;
let inline t = time();
let i:i32;
let j:i32;
let x:f32;
let u:f32;
let v:f32;
cls(0);
loop drawloop {
let inline a = u + i as f32 * 12_f;
let inline b = v + i as f32;
u = sin(a)+sin(b);
v = cos(a)+cos(b);
setPixel((u*56_f) as i32 + 160,(v*56_f) as i32 +120, i+j%15+16);
u:=u+t;
branch_if j := (j + 1) % m: drawloop;
branch_if i := (i + 1) % n: drawloop;
}
}
Day 9 Extra⌗
Go to Day 8 Extra
include "microw8-api.cwa"
export fn upd() {
cls(17);
let x: i32;
let y: i32;
let inline t = time() * 8_f;
loop scapeloop {
let inline height = sin(x as f32 / 26_f ) + sin(y as f32 / 53_f + t / 20_f) + sin(x as f32 / 13_f);
let inline z = abs(y as f32 - 80.5) - (fmod(t,2_f)+0.001);
let inline X = (x-160) as f32 * 199_f / z + 160_f;
let inline Y = 999_f / z + 120_f;
circle(X, (Y-height*16_f), 16_f-z/4_f,(sin(height)*7_f) as i32 + 120);
branch_if x := (x + 1) % 320: scapeloop;
branch_if y := (y + 1) % 240: scapeloop;
}
}
Day 10 Extra⌗
Go to Day 8 Extra
include "microw8-api.cwa"
export fn upd() {
// draw background sky
let i:i32;
loop drawsky {
line(0_f,i as f32,320_f,i as f32,(i/16)+20+i%3);
branch_if i := (i + 1) % 240: drawsky;
}
let x: i32;
let y: i32;
let inline t = time() * 8_f;
loop scapeloop {
let inline height = randomf() + sin(x as f32 / 26_f ) + sin(y as f32 / 9_f + t/2_f) + sin(x as f32 / 13_f);
let inline z = abs(y as f32 - 120.5) - (fmod(t,0.5)+0.001);
let inline X = (x-320) as f32 * 64_f / z + 160_f;
let inline Y = 1999_f / z + 100_f;
circle(X, Y - height*3_f, 4_f-z/64_f, (sin(height)*7_f) as i32 + y / 32 + 126 + random()%2);
branch_if x := (x + 1) % 640: scapeloop;
branch_if y := (y + 1) % 240: scapeloop;
}
}
Day 11 Extra⌗
Go to Day 8 Extra
include "microw8-api.cwa"
export fn upd() {
cls(0);
let inline t=time();
let xi: i32;
let yi: i32;
let zi: i32;
loop dots {
// dot positions (torus)
let inline c = 4_f;
let inline a = 2_f;
let inline u = (yi-16) as f32 * 3.14 / 16_f;
let inline v = (xi-16) as f32 * 3.14 / 16_f;
let inline X = (c + a * cos(v)) * cos(u);
let inline Y = (c + a * cos(v)) * sin(u);
let inline Z = a * sin(v);
// rotation angles
let inline xa = t;
let inline ya = cos(t);
// 3d rotation and projection
let inline x = X*cos(xa) - Y*sin(xa);
let inline z = (x*sin(ya) + Z*cos(ya)) + 8_f;
let inline cx = (x*cos(ya) - Z*sin(ya)) * 127_f/z + 160_f;
let inline cy = (X*sin(xa) + Y*cos(xa)) * 127_f/z + 120_f;
// radius & color
let inline r = 8_f-z/2_f;
let inline c = (r as i32)+(xi&yi&(t*10_f) as i32);
// fake z-buffer
let inline oldz = getPixel(cx as i32,cy as i32);
let inline rr = select(c>oldz,r,0_f);
// draw dot
circle(cx, cy, rr, c + 32);
branch_if xi:=(xi+1) % 33: dots;
branch_if yi:=(yi+1) % 33: dots;
}
}
More coming soon!
Sharing is Caring!⌗
If you feel like it, why not share what you’ve done with us on the LoveByte Discord, #lovebyte on IRCnet, or share on Twitter and Mastodon using the hashtag #lovebytetcc