math changes & compiler update
This commit is contained in:
parent
eff1323e94
commit
3506c83535
|
@ -38,9 +38,9 @@ Label := struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
||||||
// if label.is_dirty {
|
if label.is_dirty {
|
||||||
// render.clear(label.surface, label.bg)
|
label.surface.clear(label.bg)
|
||||||
// render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
|
label.surface.put_text(font, .(0, 0), label.fg, label.text)
|
||||||
// }
|
}
|
||||||
// render.put_surface(surface, label.surface, pos, false)
|
surface.put_surface(label.surface, pos, false)
|
||||||
}
|
}
|
|
@ -33,7 +33,6 @@ $sign := fn($T: type, x: T): i8 {
|
||||||
sign_bit := @as(float_bytes(T), @bitcast(x)) >> @sizeof(T) * 8 - 1
|
sign_bit := @as(float_bytes(T), @bitcast(x)) >> @sizeof(T) * 8 - 1
|
||||||
return (1 - 2 * @intcast(sign_bit)) * (x != 0)
|
return (1 - 2 * @intcast(sign_bit)) * (x != 0)
|
||||||
}
|
}
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
log := fn($T: type, base: T, x: T): T {
|
log := fn($T: type, base: T, x: T): T {
|
||||||
if integer(T) {
|
if integer(T) {
|
||||||
|
@ -47,6 +46,19 @@ log := fn($T: type, base: T, x: T): T {
|
||||||
return ln(T, x) / ln(T, base)
|
return ln(T, x) / ln(T, base)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pow := fn($T: type, base: T, x: T): T {
|
||||||
|
if integer(T) {
|
||||||
|
result := base
|
||||||
|
i := 1
|
||||||
|
loop if i == x break else {
|
||||||
|
result *= x
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
} else if float(T) {
|
||||||
|
return exp(T, x * ln(T, base))
|
||||||
|
}
|
||||||
|
}
|
||||||
$lerp := fn($T: type, v0: T, v1: T, t: T): T {
|
$lerp := fn($T: type, v0: T, v1: T, t: T): T {
|
||||||
if float(T) {
|
if float(T) {
|
||||||
return v0 + t * (v1 - v0)
|
return v0 + t * (v1 - v0)
|
||||||
|
@ -90,19 +102,29 @@ tan := fn(theta: f32): f32 {
|
||||||
|
|
||||||
exp := fn($T: type, x: T): T {
|
exp := fn($T: type, x: T): T {
|
||||||
if float(T) {
|
if float(T) {
|
||||||
result := @as(T, 1.0)
|
if x == 0.0 return 1.0
|
||||||
|
if x > 709.0 return 100000000000000000000000.0
|
||||||
|
if x < -709.0 return 0.0
|
||||||
|
|
||||||
|
sum := @as(T, 1.0)
|
||||||
term := @as(T, 1.0)
|
term := @as(T, 1.0)
|
||||||
|
c := @as(T, 0.0)
|
||||||
|
|
||||||
n := @as(int, 1)
|
n := @as(int, 1)
|
||||||
|
|
||||||
loop if n == 20 break else {
|
loop if n == 20 break else {
|
||||||
|
prev_term := term
|
||||||
term = term * x / @itf(n)
|
term = term * x / @itf(n)
|
||||||
result += term
|
|
||||||
|
|
||||||
if abs(T, term) < 0.0000000001 break
|
y := term - c
|
||||||
|
t := sum + y
|
||||||
|
c = t - sum - y
|
||||||
|
sum = t
|
||||||
|
|
||||||
|
if abs(T, term) < 0.00000000000001 * abs(T, sum) break
|
||||||
n += 1
|
n += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return sum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,32 +135,33 @@ ln := fn($T: type, x: T): T {
|
||||||
if x == E return 1.0
|
if x == E return 1.0
|
||||||
|
|
||||||
scale := @as(T, 0.0)
|
scale := @as(T, 0.0)
|
||||||
scaled_x := x
|
|
||||||
|
|
||||||
if scaled_x > 2.0 {
|
if x > 2.0 {
|
||||||
loop if scaled_x <= 2.0 break else {
|
loop if x <= 2.0 break else {
|
||||||
scaled_x = scaled_x / E
|
x /= E
|
||||||
scale += 1.0
|
scale += 1.0
|
||||||
}
|
}
|
||||||
} else if scaled_x < 1.0 {
|
} else if x < 1.0 {
|
||||||
loop if scaled_x >= 1.0 {
|
loop if x >= 1.0 break else {
|
||||||
scaled_x = scaled_x * E
|
x *= E
|
||||||
scale -= 1.0
|
scale -= 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guess := (scaled_x - 1.0) / (scaled_x + 1.0)
|
y := x - 1.0
|
||||||
|
z := y / (x + 1.0)
|
||||||
|
z2 := z * z
|
||||||
|
|
||||||
|
guess := z * (1.0 + z2 * (1.0 / 3.0 + z2 * (1.0 / 5.0 + z2 * 1.0 / 7.0)))
|
||||||
|
|
||||||
max_iter := 30
|
|
||||||
i := 0
|
i := 0
|
||||||
loop if i == max_iter break else {
|
loop if i == 10 break else {
|
||||||
exp_g := exp(T, guess)
|
exp_val := exp(T, guess)
|
||||||
f := exp_g - scaled_x
|
f := exp_val - x
|
||||||
f_prime := exp_g
|
f_prime := exp_val
|
||||||
|
|
||||||
delta := f / (f_prime * (1.0 - 0.5 * f * f_prime / (f_prime * f_prime)))
|
delta := f / (f_prime * (1.0 - 0.5 * f * f_prime / (f_prime * f_prime)))
|
||||||
|
guess -= delta
|
||||||
guess = guess - delta
|
|
||||||
|
|
||||||
if abs(T, delta) < 0.0000000001 break
|
if abs(T, delta) < 0.0000000001 break
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
@ -31,17 +31,13 @@ main := fn(): void {
|
||||||
pos1 := Vec2(uint).(1, 1)
|
pos1 := Vec2(uint).(1, 1)
|
||||||
pos2 := Vec2(uint).(1, 20)
|
pos2 := Vec2(uint).(1, 20)
|
||||||
pos3 := Vec2(uint).(1, 40)
|
pos3 := Vec2(uint).(1, 40)
|
||||||
// render.clear(window.surface, render.black)
|
|
||||||
render_label_to_surface(window.surface, text_label, font, pos1)
|
render_label_to_surface(window.surface, text_label, font, pos1)
|
||||||
render_label_to_surface(window.surface, text_label_2, font, pos2)
|
render_label_to_surface(window.surface, text_label_2, font, pos2)
|
||||||
render_label_to_surface(window.surface, text_label_3, font, pos3)
|
render_label_to_surface(window.surface, text_label_3, font, pos3)
|
||||||
loop {
|
loop {
|
||||||
// stn.log.info("AAAA\0")
|
// stn.log.info("AAAA\0")
|
||||||
// render.put_text(text_label.surface, font, pos1, text_label.fg, text_label.text)
|
|
||||||
// render.put_text(text_label_2.surface, font, pos2, text_label_2.fg, text_label_2.text)
|
|
||||||
// render.put_text(text_label_3.surface, font, pos3, text_label_3.fg, text_label_3.text)
|
|
||||||
|
|
||||||
_ = sunset.client.send_frame(window)
|
_ = sunset.client.send_frame(window)
|
||||||
// stn.sleep.sleep_until_interrupt(100)
|
// stn.sleep.sleep_until_interrupt(100)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,30 +3,25 @@ sunset := @use("lib:sunset_proto");
|
||||||
.{math, log} := @use("stn")
|
.{math, log} := @use("stn")
|
||||||
|
|
||||||
// full mandelbrot
|
// full mandelbrot
|
||||||
$X_MIN := -2.0
|
// $X_MIN := -2.0
|
||||||
$X_MAX := 0.47
|
// $X_MAX := 0.47
|
||||||
$Y_MIN := -1.12
|
// $Y_MIN := -1.12
|
||||||
$Y_MAX := 1.12
|
// $Y_MAX := 1.12
|
||||||
|
|
||||||
// a minibrot
|
// a minibrot
|
||||||
// $X_MIN := -0.94
|
$X_MIN := -0.94
|
||||||
// $X_MAX := -0.93
|
$X_MAX := -0.93
|
||||||
// $Y_MIN := 0.31
|
$Y_MIN := 0.31
|
||||||
// $Y_MAX := 0.306
|
$Y_MAX := 0.306
|
||||||
|
|
||||||
$MAX_ITERATION := 300
|
$MAX_ITERATION := 300
|
||||||
|
|
||||||
$USE_SUNSET := false
|
$USE_SUNSET := true
|
||||||
|
|
||||||
palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_GREEN, render.LIGHT_CYAN, render.LIGHT_BLUE, render.LIGHT_MAGENTA)
|
palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_GREEN, render.LIGHT_CYAN, render.LIGHT_BLUE, render.LIGHT_MAGENTA)
|
||||||
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
|
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
|
||||||
|
|
||||||
example := fn(): void {
|
example := fn(): void {
|
||||||
z := math.log(f32, 10.0, 100.0)
|
|
||||||
z2 := math.sign(f32, 10.0)
|
|
||||||
z = math.min(f32, 10.0, 100.0)
|
|
||||||
z = math.max(f32, 10.0, 100.0)
|
|
||||||
|
|
||||||
screen := @as(render.Surface, idk)
|
screen := @as(render.Surface, idk)
|
||||||
window := @as(?sunset.Window, null)
|
window := @as(?sunset.Window, null)
|
||||||
if USE_SUNSET {
|
if USE_SUNSET {
|
||||||
|
@ -91,4 +86,7 @@ example := fn(): void {
|
||||||
_ = sunset.client.send_frame(window)
|
_ = sunset.client.send_frame(window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if USE_SUNSET loop {
|
||||||
|
_ = sunset.client.send_frame(window)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,15 @@
|
||||||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
sunset := @use("lib:sunset_proto")
|
||||||
render := @use("../../../libraries/render/src/lib.hb")
|
render := @use("lib:render")
|
||||||
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
intouch := @use("lib:intouch")
|
||||||
|
|
||||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
horizon_api := @use("lib:horizon_api");
|
||||||
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
||||||
|
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
stn := @use("stn");
|
||||||
.{Vec2} := stn.math
|
.{Vec2} := stn.math
|
||||||
|
|
||||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||||
img := @embed("../../../assets/wallpaper.qoi")
|
img := @embed("sysdata:assets/wallpaper.qoi")
|
||||||
|
|
||||||
Mouse := struct {
|
Mouse := struct {
|
||||||
x: uint,
|
x: uint,
|
||||||
|
@ -119,8 +119,8 @@ main := fn(): int {
|
||||||
|
|
||||||
// Mouse cursor
|
// Mouse cursor
|
||||||
{
|
{
|
||||||
render.put_filled_circle(screen, .(mouse.x, mouse.y), mouse.cursor_width, sunset.server.DECO_COLOUR_DARKER)
|
screen.put_filled_circle(.(mouse.x, mouse.y), mouse.cursor_width, sunset.server.DECO_COLOUR_DARKER)
|
||||||
render.put_circle(screen, .(mouse.x, mouse.y), mouse.cursor_width, sunset.server.DECO_COLOUR)
|
screen.put_circle(.(mouse.x, mouse.y), mouse.cursor_width, sunset.server.DECO_COLOUR)
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.sync()
|
screen.sync()
|
||||||
|
|
|
@ -25,13 +25,11 @@ resolution = "1024x768x24"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.render_example]
|
[boot.limine.ableos.modules.render_example]
|
||||||
path = "boot:///render_example.hbf"
|
path = "boot:///render_example.hbf"
|
||||||
|
|
||||||
|
|
||||||
[boot.limine.ableos.modules.sunset_server]
|
[boot.limine.ableos.modules.sunset_server]
|
||||||
path = "boot:///sunset_server.hbf"
|
path = "boot:///sunset_server.hbf"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.ps2_mouse_driver]
|
[boot.limine.ableos.modules.ps2_mouse_driver]
|
||||||
# path = "boot:///ps2_mouse_driver.hbf"
|
path = "boot:///ps2_mouse_driver.hbf"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||||
|
|
Loading…
Reference in a new issue