From 2e6065717d6297072ac23023583c218246ac7916 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 9 May 2021 08:36:37 -0700 Subject: [PATCH] . --- html/mandelbrot.mu.html | 72 ++++++++++++++++++++++------------------- mandelbrot.mu | 4 +++ 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/html/mandelbrot.mu.html b/html/mandelbrot.mu.html index ee2b8483..a70db941 100644 --- a/html/mandelbrot.mu.html +++ b/html/mandelbrot.mu.html @@ -79,12 +79,12 @@ if ('onhashchange' in window) { 21 { 22 compare y, height 23 break-if->= - 24 var imaginary/xmm1: float <- viewport-to-imaginary y, width, height + 24 var imaginary/xmm1: float <- viewport-to-imaginary y, width, height 25 var x/edx: int <- copy 0 26 { 27 compare x, width 28 break-if->= - 29 var real/xmm0: float <- viewport-to-real x, width + 29 var real/xmm0: float <- viewport-to-real x, width 30 var iterations/eax: int <- mandelbrot-iterations-for-point real, imaginary, 0x400/max 31 compare iterations, 0x400/max 32 { @@ -165,38 +165,42 @@ if ('onhashchange' in window) { 107 return result 108 } 109 -110 fn viewport-to-real x: int, width: int -> _/xmm0: float { -111 # (x - width/2)*4/width -112 var result/xmm0: float <- convert x -113 var width-f/xmm1: float <- convert width -114 var two/eax: int <- copy 2 -115 var two-f/xmm2: float <- convert two -116 var half-width-f/xmm2: float <- reciprocal two-f -117 half-width-f <- multiply width-f -118 result <- subtract half-width-f -119 var four/eax: int <- copy 4 -120 var four-f/xmm2: float <- convert four -121 result <- multiply four-f -122 result <- divide width-f -123 return result -124 } -125 -126 fn viewport-to-imaginary y: int, width: int, height: int -> _/xmm1: float { -127 # (y - height/2)*4/width -128 var result/xmm0: float <- convert y -129 var height-f/xmm1: float <- convert height -130 var half-height-f/xmm1: float <- copy height-f -131 var two/eax: int <- copy 2 -132 var two-f/xmm2: float <- convert two -133 half-height-f <- divide two-f -134 result <- subtract half-height-f -135 var four/eax: int <- copy 4 -136 var four-f/xmm1: float <- convert four -137 result <- multiply four-f -138 var width-f/xmm1: float <- convert width -139 result <- divide width-f -140 return result -141 } +110 # Scale (x, y) pixel coordinates to a complex plane where the viewport width +111 # ranges from -2 to +2. Viewport height just follows the viewport's aspect +112 # ratio. +113 +114 fn viewport-to-real x: int, width: int -> _/xmm0: float { +115 # (x - width/2)*4/width +116 var result/xmm0: float <- convert x +117 var width-f/xmm1: float <- convert width +118 var two/eax: int <- copy 2 +119 var two-f/xmm2: float <- convert two +120 var half-width-f/xmm2: float <- reciprocal two-f +121 half-width-f <- multiply width-f +122 result <- subtract half-width-f +123 var four/eax: int <- copy 4 +124 var four-f/xmm2: float <- convert four +125 result <- multiply four-f +126 result <- divide width-f +127 return result +128 } +129 +130 fn viewport-to-imaginary y: int, width: int, height: int -> _/xmm1: float { +131 # (y - height/2)*4/width +132 var result/xmm0: float <- convert y +133 var height-f/xmm1: float <- convert height +134 var half-height-f/xmm1: float <- copy height-f +135 var two/eax: int <- copy 2 +136 var two-f/xmm2: float <- convert two +137 half-height-f <- divide two-f +138 result <- subtract half-height-f +139 var four/eax: int <- copy 4 +140 var four-f/xmm1: float <- convert four +141 result <- multiply four-f +142 var width-f/xmm1: float <- convert width +143 result <- divide width-f +144 return result +145 } diff --git a/mandelbrot.mu b/mandelbrot.mu index 3017ec20..84310a0d 100644 --- a/mandelbrot.mu +++ b/mandelbrot.mu @@ -107,6 +107,10 @@ fn mandelbrot-y x: float, y: float, imaginary: float -> _/xmm3: float { return result } +# 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. + fn viewport-to-real x: int, width: int -> _/xmm0: float { # (x - width/2)*4/width var result/xmm0: float <- convert x