Wiki

Changeset 2417

Show
Ignore:
Timestamp:
08/04/10 04:46:34 (18 months ago)
Author:
Chuck.Esterbrook
Message:

Code cleanup.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Samples/FractalBenchmark.cobra

    r2129 r2417  
    11""" 
     2FractalBenchmark.cobra - print an image of the Mandelbrot set 
     3 
    24See http://www.timestretch.com/FractalBenchmark.html 
    3 History 
     5 
     6== History 
     7 
    48    2009-03-09 Csaba Urbaniczky 
    5     2009-03-09 Test in SciTE  
     9    2009-03-09 Tests 
    610        With float:: 48-128 ms (in SciTE) 
    711        With  float & Try Catch  &:48-128 ms  = same! 
     
    1317@number float 
    1418 
    15 class Program  
     19class Program 
    1620 
    17     const bailOut = 16   
     21    const bailOut = 16 
    1822    const maxIterations = 1_000 
    1923     
    20     shared 
    21          
    22         def mandelbrot 
    23             for y in -39 : 39 
    24                 print 
    25                 for x in -39 : 39 
    26                     if .calc(x/40, y/40), c = '*' 
    27                     else, c = ' ' 
    28                     print c stop 
    29      
    30         def calc(ci as number, y as number) as bool 
    31             cr = y - 0.5 
    32             zr = 0.0 
    33             zi = 0.0 
    34             for i in 0 : .maxIterations 
    35                 zr2 = zr * zr 
    36                 zi2 = zi * zi 
    37                 if zi2 + zr2 > .bailOut, return false 
    38                 temp = zr * zi 
    39                 zr = zr2 - zi2 + cr 
    40                 zi = temp + temp + ci 
    41             return true 
    42      
    43         def main 
    44             sw = System.Diagnostics.Stopwatch() 
    45             sw.start 
    46             .mandelbrot 
    47             sw.stop 
     24    def mandelbrot 
     25        for y in -39 : 39 
    4826            print 
    49             print 'Cobra elapsed: [sw.elapsedMilliseconds] ms' 
     27            for x in -39 : 39 
     28                if .calc(x/40, y/40), c = '*' 
     29                else, c = ' ' 
     30                print c stop 
     31 
     32    def calc(ci as number, y as number) as bool 
     33        cr = y - 0.5 
     34        zr = zi = 0.0 
     35        for i in 0 : .maxIterations 
     36            zr2 = zr * zr 
     37            zi2 = zi * zi 
     38            if zi2 + zr2 > .bailOut, return false 
     39            temp = zr * zi 
     40            zr = zr2 - zi2 + cr 
     41            zi = temp + temp + ci 
     42        return true 
     43 
     44    def main 
     45        sw = System.Diagnostics.Stopwatch() 
     46        sw.start 
     47        .mandelbrot 
     48        sw.stop 
     49        print 
     50        print 'Cobra elapsed: [sw.elapsedMilliseconds] ms'