forked from AbleOS/holey-bytes
72 lines
1.4 KiB
Plaintext
72 lines
1.4 KiB
Plaintext
log := fn(msg: ^u8): void return @eca(0, msg)
|
|
|
|
absf := fn(x: f32): f32 {
|
|
if (x < 0) {
|
|
return -x
|
|
}
|
|
return x
|
|
}
|
|
|
|
sqrt := fn(x: f32, low: f32, high: f32): f32 {
|
|
mid := (high - low)/2.0
|
|
if (absf(mid * mid - x) < 0.01) {
|
|
return mid
|
|
}
|
|
if (mid * mid > x) {
|
|
return sqrt(x, low, mid)
|
|
}
|
|
if (mid * mid < x) {
|
|
return sqrt(x, mid, high)
|
|
}
|
|
return -9999.0
|
|
}
|
|
|
|
is_filled := fn(x: uint, y: uint, center_x: f32, center_y: f32, inner_radius: f32, outer_radius: f32): bool {
|
|
x_f := @as(f32, @floatcast(@itf(@bitcast(x))))
|
|
y_f := @as(f32, @floatcast(@itf(@bitcast(y))))
|
|
x_diff := x_f - center_x
|
|
y_diff := x_f - center_y
|
|
dist := sqrt(x_diff * x_diff + y_diff * y_diff)
|
|
if (dist < outer_radius) {
|
|
if (dist > inner_radius) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
buffer := @as([u8; 61], idk)
|
|
|
|
render_row := fn(y: uint): void {
|
|
x := 0
|
|
loop {
|
|
if (x > 60) {
|
|
break
|
|
}
|
|
buffer[x] = 32
|
|
}
|
|
x = 0
|
|
loop {
|
|
if (x > 60) {
|
|
break
|
|
}
|
|
if (is_filled(x, y, 30.0, 30.0, 10.0, 20.0)) {
|
|
buffer[x] = 35
|
|
}
|
|
x = x + 1
|
|
}
|
|
log(buffer[0])
|
|
}
|
|
|
|
main := fn(): int {
|
|
y := 0
|
|
loop {
|
|
if (y > 60) {
|
|
break
|
|
}
|
|
render_row(y)
|
|
y = y + 1
|
|
}
|
|
return 0
|
|
}
|