Assembly Language for Beginners

(Jeff_L) #1

8.13. DEMOS


Re(sum) =Re(a) +Re(b)

Im(sum) =Im(a) +Im(b)


  • Multiplication:(a+bi)(c+di) = (ac−bd) + (bc+ad)i


In other words:

Re(product) =Re(a)⋅Re(c)−Re(b)⋅Re(d)

Im(product) =Im(b)⋅Im(c) +Im(a)⋅Im(d)


  • Square:(a+bi)^2 = (a+bi)(a+bi) = (a^2 −b^2 ) + (2ab)i


In other words:

Re(square) =Re(a)^2 −Im(a)^2

Im(square) = 2⋅Re(a)⋅Im(a)

How to draw the Mandelbrot set


The Mandelbrot set is a set of points for which thezn+1=zn^2 +crecursive sequence (wherezandcare
complex numbers andcis the starting value) does not approach infinity.


In plain English language:



  • Enumerate all points on screen.

  • Check if the specific point is in the Mandelbrot set.

  • Here is how to check it:

    • Represent the point as a complex number.

    • Calculate the square of it.

    • Add the starting value of the point to it.

    • Does it go off limits? If yes, break.

    • Move the point to the new place at the coordinates we just calculated.

    • Repeat all this for some reasonable number of iterations.



  • The point is still in limits? Then draw the point.

  • The point has eventually gone off limits?

    • (For a black-white image) do not draw anything.

    • (For a colored image) transform the number of iterations to some color. So the color shows the
      speed with which point has gone off limits.




Here is Pythonesque algorithm for both complex and integer number representations:


Listing 8.24: For complex numbers

def check_if_is_in_set(P):
P_start=P
iterations=0


while True:
if (P>bounds):
break
P=P^2+P_start
if iterations > max_iterations:
break
iterations++

return iterations

black-white


for each point on screen P:
if check_if_is_in_set (P) < max_iterations:
draw point

Free download pdf