1628 views|2 replies

1w

Posts

25

Resources
The OP
 

【RPi PICO】Calculate Mandelbrot Improved Version [Copy link]

 

The previous version of the program has been modified to use different characters to represent different colors (divergence speeds), which has a better effect.

from time import ticks_ms, ticks_diff

MAX_ITER = 60
MANDEL_CHAR = (
    ' ', '.', '`', ',', ':', ';', '|', 'o', '<', '>',
    '(', ')', '{', '}', '+', '~', '=', '-', '#', '@'
)

def run(func, param = None):
    t1 = ticks_ms()
    if param == None:
        func()
    else:
        func(param)
    t2 = ticks_ms()
    print('calc time:', ticks_diff(t2, t1), 'ms')


# @micropython.native
def calc_mandel(c):
    z = 0
    for i in range(MAX_ITER):
        z = z * z + c
        if abs(z) > 4:
            return i
    return MAX_ITER - 1

def mandelbrot():
    N = len(MANDEL_CHAR)
    print('')
    for v in range(31):
        for u in range(81):
            n = calc_mandel((u / 30 - 2) + (v / 15 - 1) * 1j)
            print(MANDEL_CHAR[(MAX_ITER - n - 1)%N], end='')
        print()

run(mandelbrot)

 
 

1w

Posts

25

Resources
2
 

Operation effect

-------------------------==================~~~~~~~++}}{>.(|< ++~~~~==========----
----------------------==================~~~~~~~~+++}}{)(o-<){}++~~~~~~=========--
-------------------==================~~~~~~~~++++}}{>oo:  ,>>(}+++~~~~~~========-
----------------=================~~~~~~~~++++++}}}{)<       .>{}}++++~~~~~=======
-------------================~~~~~~~~~~+++}}}{{{{))(o~      :(){{}}}+++++~~~=====
----------===============~~~~~~~~~~~++++})-@><((o>o :`=    .:|;< >){{{)`}+~~~====
-------==============~~~~~~~~~~~~+++++}}{)o.  ~,+                ,<<@:; :}+~~~===
-----=============~~~~~~~~~+++++++++}}}{)(>:                          `<{}+~~~~==
--=============~~~~~+++++++++++}}}}}}{)#:@`                          #o({}++~~~==
-===========~~~~~~++}{<({{}{{){{{{{{{)(<:;                             o>>)++~~==
==========~~~~~~~+++}{>o<<>(>`o((())((<=                                 #)++~~~=
========~~~~~~~+++}}}{)>|>  ;- ==~.<<<:-                                |(}++~~~=
=====~~~~~~~++++}}{{{(<| ;          ::{                                 <:}++~~~=
==~~~~~++++++}}}{)|>><;-             -                                  ~{}+~~~~=
~~~+++})}}}}{{{))>o=);-                                                >{}++~~~~=
                                                                    -o()}}++~~~~=
~~~+++})}}}}{{{))>o=);-                                                >{}++~~~~=
==~~~~~++++++}}}{)|>><;-             -                                  ~{}+~~~~=
=====~~~~~~~++++}}{{{(<| ;          ::{                                 <:}++~~~=
========~~~~~~~+++}}}{)>|>  ;- ==~.<<<:-                                |(}++~~~=
==========~~~~~~~+++}{>o<<>(>`o((())((<=                                 #)++~~~=
-===========~~~~~~++}{<({{}{{){{{{{{{)(<:;                             o>>)++~~==
--=============~~~~~+++++++++++}}}}}}{)#:@`                          #o({}++~~~==
-----=============~~~~~~~~~+++++++++}}}{)(>:                          `<{}+~~~~==
-------==============~~~~~~~~~~~~+++++}}{)o.  ~,+                ,<<@:; :}+~~~===
----------===============~~~~~~~~~~~++++})-@><((o>o :`=    .:|;< >){{{)`}+~~~====
-------------================~~~~~~~~~~+++}}}{{{{))(o~      :(){{}}}+++++~~~=====
----------------=================~~~~~~~~++++++}}}{)<       .>{}}++++~~~~~=======
-------------------==================~~~~~~~~++++}}{>oo:  ,>>(}+++~~~~~~========-
----------------------==================~~~~~~~~+++}}{)(o-<){}++~~~~~~=========--
-------------------------==================~~~~~~~++}}{>.(|< ++~~~~==========----

 
 
 

1w

Posts

25

Resources
3
 

However, I found a strange problem: the calculation time would increase each time on PICO, but not on other development boards.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list