From 444227b3c413c544f357f2b8b7e9394a59a7d839 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 16 May 2021 15:29:53 -0700 Subject: [PATCH] first bit of animation --- 509bezier.mu | 21 +++++++++++++++++++++ hest-life.mu | 27 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/509bezier.mu b/509bezier.mu index c915bbbb..5cbf23a6 100644 --- a/509bezier.mu +++ b/509bezier.mu @@ -293,3 +293,24 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i # plot the remaining straight line draw-line screen, x y, x2 y2, color } + +# 0 <= u <= 1 +fn bezier-point u: float, x0: int, x1: int, x2: int -> _/eax: int { + var one/eax: int <- copy 1 + var u-prime/xmm0: float <- convert one + u-prime <- subtract u + var result/xmm1: float <- convert x0 + result <- multiply u-prime + result <- multiply u-prime + var term2/xmm2: float <- convert x1 + term2 <- multiply u + term2 <- multiply u-prime + result <- add term2 + result <- add term2 + var term3/xmm2: float <- convert x2 + term3 <- multiply u + term3 <- multiply u + result <- add term3 + var result/eax: int <- convert result + return result +} diff --git a/hest-life.mu b/hest-life.mu index d3e4cc85..91d2d4cf 100644 --- a/hest-life.mu +++ b/hest-life.mu @@ -83,9 +83,32 @@ fn render0 screen: (addr screen), _self: (addr environment) { draw-rect screen, 0x1f0/xmin, 0x290/ymin, 0x210/xmax, 0x2b0/ymax, 0xf/alive draw-rect screen, 0x310/xmin, 0x170/ymin, 0x330/xmax, 0x190/ymax, 0xf/alive # clock - var tick/eax: (addr int) <- get self, tick + var tick-a/eax: (addr int) <- get self, tick set-cursor-position screen, 0x78/x, 0/y - draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, *tick, 7/fg 0/bg + draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, *tick-a, 7/fg 0/bg + # time-variant portion + var progress/eax: int <- copy *tick-a + progress <- and 7 + var u/xmm7: float <- convert progress + var eight/eax: int <- copy 8 + var eight-f/xmm0: float <- convert eight + u <- divide eight-f + # points on conveyers from neighboring cells + draw-bezier-point screen, u, 0xa0/x0 0x20/y0, 0x100/x1 0x160/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0xa0/x0 0x180/y0, 0x110/x1 0x160/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0xa0/x0 0x2e0/y0, 0x100/x1 0x160/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0x200/x0 0x20/y0, 0x180/x1 0x90/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0x200/x0 0x2e0/y0, 0x180/x1 0x200/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0x360/x0 0x20/y0, 0x180/x1 0xc0/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0x360/x0 0x180/y0, 0x300/x1 0x160/y1, 0x180/x2 0x160/y2, 7/color, 4/radius + draw-bezier-point screen, u, 0x360/x0 0x2e0/y0, 0x180/x1 0x200/y1, 0x180/x2 0x160/y2, 7/color, 4/radius +} + +fn draw-bezier-point screen: (addr screen), u: float, x0: int, y0: int, x1: int, y1: int, x2: int, y2: int, color: int, radius: int { + var _cy/eax: int <- bezier-point u, y0, y1, y2 + var cy/ecx: int <- copy _cy + var cx/eax: int <- bezier-point u, x0, x1, x2 + draw-disc screen, cx, cy, radius, color, 0xf/border-color=white } fn edit keyboard: (addr keyboard), _self: (addr environment) {