From 50d6c374de23adebc7a3a2742c6c20dfd87010fb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 17 Oct 2024 09:39:34 -0700 Subject: fix other mandelbrot variants --- apps/mandelbrot-fixed.mu | 5 ++-- apps/mandelbrot-silhouette.mu | 4 +-- html/apps/mandelbrot-fixed.mu.html | 45 ++++++++++++++++----------------- html/apps/mandelbrot-silhouette.mu.html | 4 +-- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/apps/mandelbrot-fixed.mu b/apps/mandelbrot-fixed.mu index fc33aae1..186350aa 100644 --- a/apps/mandelbrot-fixed.mu +++ b/apps/mandelbrot-fixed.mu @@ -213,8 +213,8 @@ fn mandelbrot-y x-f: int, y-f: int, imaginary-f: int -> _/ebx: int { } # Scale (x, y) pixel coordinates to a complex plane where the viewport width -# ranges from -2 to +2. Viewport height just follows the viewport's aspect -# ratio. +# ranges from (scene-cx - scene-width/2) to (scene-cx + scene-width/2). +# Viewport height just follows the viewport's aspect ratio. fn viewport-to-real-f x: int, width: int, scene-cx-f: int, scene-width-f: int -> _/edx: int { # 0 in the viewport goes to scene-cx - scene-width/2 @@ -239,7 +239,6 @@ fn viewport-to-imaginary-f y: int, width: int, height: int, scene-cy-f: int, sce # height in the viewport goes to scene-cy + scene-width/2*height/width # Therefore: # y in the viewport goes to (scene-cy - scene-width/2*height/width) + y*scene-width/width - # scene-cy - scene-width/width * (height/2 + y) # At most two numbers being multiplied before a divide, so no risk of overflow. var result-f/eax: int <- int-to-fixed y result-f <- multiply-fixed result-f, scene-width-f diff --git a/apps/mandelbrot-silhouette.mu b/apps/mandelbrot-silhouette.mu index 0d9a137c..14c6e397 100644 --- a/apps/mandelbrot-silhouette.mu +++ b/apps/mandelbrot-silhouette.mu @@ -113,8 +113,8 @@ fn mandelbrot-y x: float, y: float, imaginary: float -> _/xmm3: float { } # Scale (x, y) pixel coordinates to a complex plane where the viewport width -# ranges from -2 to +2. Viewport height just follows the viewport's aspect -# ratio. +# ranges from (scene-cx - scene-width/2) to (scene-cx + scene-width/2). +# Viewport height just follows the viewport's aspect ratio. fn viewport-to-real x: int, width: int -> _/xmm0: float { # (x - width/2)*4/width diff --git a/html/apps/mandelbrot-fixed.mu.html b/html/apps/mandelbrot-fixed.mu.html index 36735482..acff5da0 100644 --- a/html/apps/mandelbrot-fixed.mu.html +++ b/html/apps/mandelbrot-fixed.mu.html @@ -277,8 +277,8 @@ if ('onhashchange' in window) { 213 } 214 215 # Scale (x, y) pixel coordinates to a complex plane where the viewport width -216 # ranges from -2 to +2. Viewport height just follows the viewport's aspect -217 # ratio. +216 # ranges from (scene-cx - scene-width/2) to (scene-cx + scene-width/2). +217 # Viewport height just follows the viewport's aspect ratio. 218 219 fn viewport-to-real-f x: int, width: int, scene-cx-f: int, scene-width-f: int -> _/edx: int { 220 # 0 in the viewport goes to scene-cx - scene-width/2 @@ -303,27 +303,26 @@ if ('onhashchange' in window) { 239 # height in the viewport goes to scene-cy + scene-width/2*height/width 240 # Therefore: 241 # y in the viewport goes to (scene-cy - scene-width/2*height/width) + y*scene-width/width -242 # scene-cy - scene-width/width * (height/2 + y) -243 # At most two numbers being multiplied before a divide, so no risk of overflow. -244 var result-f/eax: int <- int-to-fixed y -245 result-f <- multiply-fixed result-f, scene-width-f -246 var width-f/ecx: int <- copy width -247 width-f <- shift-left 8/fixed-precision -248 result-f <- divide-fixed result-f, width-f -249 result-f <- add scene-cy-f -250 var second-term-f/edx: int <- copy 0 -251 { -252 var _second-term-f/eax: int <- copy scene-width-f -253 _second-term-f <- shift-right 1 -254 var height-f/ebx: int <- copy height -255 height-f <- shift-left 8/fixed-precision -256 _second-term-f <- multiply-fixed _second-term-f, height-f -257 _second-term-f <- divide-fixed _second-term-f, width-f -258 second-term-f <- copy _second-term-f -259 } -260 result-f <- subtract second-term-f -261 return result-f -262 } +242 # At most two numbers being multiplied before a divide, so no risk of overflow. +243 var result-f/eax: int <- int-to-fixed y +244 result-f <- multiply-fixed result-f, scene-width-f +245 var width-f/ecx: int <- copy width +246 width-f <- shift-left 8/fixed-precision +247 result-f <- divide-fixed result-f, width-f +248 result-f <- add scene-cy-f +249 var second-term-f/edx: int <- copy 0 +250 { +251 var _second-term-f/eax: int <- copy scene-width-f +252 _second-term-f <- shift-right 1 +253 var height-f/ebx: int <- copy height +254 height-f <- shift-left 8/fixed-precision +255 _second-term-f <- multiply-fixed _second-term-f, height-f +256 _second-term-f <- divide-fixed _second-term-f, width-f +257 second-term-f <- copy _second-term-f +258 } +259 result-f <- subtract second-term-f +260 return result-f +261 } diff --git a/html/apps/mandelbrot-silhouette.mu.html b/html/apps/mandelbrot-silhouette.mu.html index 1ed40805..8c933466 100644 --- a/html/apps/mandelbrot-silhouette.mu.html +++ b/html/apps/mandelbrot-silhouette.mu.html @@ -175,8 +175,8 @@ if ('onhashchange' in window) { 113 } 114 115 # Scale (x, y) pixel coordinates to a complex plane where the viewport width -116 # ranges from -2 to +2. Viewport height just follows the viewport's aspect -117 # ratio. +116 # ranges from (scene-cx - scene-width/2) to (scene-cx + scene-width/2). +117 # Viewport height just follows the viewport's aspect ratio. 118 119 fn viewport-to-real x: int, width: int -> _/xmm0: float { 120 # (x - width/2)*4/width -- cgit 1.4.1-2-gfad0