Skip to content

Commit 70754fa

Browse files
committed
adjusted L8 to TPs and TCs
1 parent 8cf67b9 commit 70754fa

6 files changed

Lines changed: 73 additions & 104 deletions

File tree

L8_case-study_mandelbrot/Fractal_tier1.sac

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export all;
88

99
/** <!--*******************************************************************-->
1010
*
11-
* @fn : complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
11+
* @fn : complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
1212
*
1313
* @brief generates an array of complex numbers with shape "shp" and
1414
* linearly increasing/decreasing values between "cmin" and "cmax".
@@ -17,13 +17,12 @@ export all;
1717
*
1818
*****************************************************************************/
1919
inline
20-
complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
20+
complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
2121
{
22-
res = with {
23-
( . <= iv <= .) : cmin + toc( reverse( (tod(iv) / tod(shp))
24-
* reverse( todv(cmax-cmin))));
25-
} : genarray( shp, toc( 0,0));
26-
return( res);
22+
diff = cmax - cmin;
23+
delta = [imag (diff) / tod( shp[0]) , real (diff) / tod (shp[1])];
24+
25+
return { iv -> cmin + toc (tod (iv) * delta) | iv < shp };
2726
}
2827

2928

@@ -41,31 +40,27 @@ complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
4140
inline
4241
int escapeTime(complex z, int depth)
4342
{
44-
i=0; c=z;
43+
i=0; c=z;
4544

46-
while( (normSq( c) <= 4d) && (i <= depth)) {
47-
c=c*c+z; i++;
48-
}
45+
while( (normSq( c) <= 4d) && (i <= depth)) {
46+
c=c*c+z; i++;
47+
}
4948

50-
return(i);
49+
return(i);
5150
}
5251

5352
/** <!--*******************************************************************-->
5453
*
55-
* @fn int[*] escapeTime(complex[*] z, int depth)
54+
* @fn int[n:shp] escapeTime(complex[n:shp] z, int depth)
5655
*
5756
* @brief maps escapeTime to an entire array of complex numbers
5857
*
5958
*****************************************************************************/
6059

6160
inline
62-
int[*] escapeTime( complex[*] plane, int depth)
61+
int[n:shp] escapeTime( complex[n:shp] plane, int depth)
6362
{
64-
values = with {
65-
( . <= iv <= .) : escapeTime( plane[iv], depth);
66-
} : genarray( shape( plane), 0);
67-
68-
return( values);
63+
return { iv -> escapeTime (plane[iv], depth) };
6964
}
7065

7166
/** <!--*******************************************************************-->
@@ -78,13 +73,11 @@ int[*] escapeTime( complex[*] plane, int depth)
7873
inline
7974
Color8::color[.,.] intArrayToMonochrome( int[.,.] a)
8075
{
81-
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
76+
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
8277

83-
a = (a * 255) / maxval(a);
78+
a = (a * 255) / maxval(a);
8479

85-
d = with {
86-
( .<= iv <= .) : clut[ a[ iv]];
87-
} : genarray( shape(a), Color8::black());
80+
return { iv -> clut[ a[ iv]] };
8881

8982
return( d);
9083
}

L8_case-study_mandelbrot/Fractal_tier1_empty.sac

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ export all;
88

99
/** <!--*******************************************************************-->
1010
*
11-
* @fn : complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
11+
* @fn : complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
1212
*
1313
* @brief generates an array of complex numbers with shape "shp" and
1414
* linearly increasing/decreasing values between "cmin" and "cmax".
15-
* The element at index [0,0] should be "cmin". Increases in the
15+
* The element at index [0,0] should be "cmin". Increases in the
1616
* 2nd index (!) should reflect increases in the real values!
1717
*
1818
*****************************************************************************/
1919
inline
20-
complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
20+
complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
2121
{
22-
/**
23-
* fill in here...
24-
*/
22+
/**
23+
* fill in here...
24+
*/
2525
}
2626

2727

@@ -39,24 +39,25 @@ complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
3939
inline
4040
int escapeTime(complex z, int depth)
4141
{
42-
/**
43-
* fill in here...
44-
*/
42+
/**
43+
* fill in here...
44+
*/
4545
}
4646

4747
/** <!--*******************************************************************-->
4848
*
49-
* @fn int[*] escapeTime(complex[*] z, int depth)
49+
* @fn int[n:shp] escapeTime(complex[n:shp] z, int depth)
5050
*
5151
* @brief maps escapeTime to an entire array of complex numbers
5252
*
5353
*****************************************************************************/
5454

55-
inline int[*] escapeTime( complex[*] plane, int depth)
55+
inline
56+
int[n:shp] escapeTime( complex[n:shp] plane, int depth)
5657
{
57-
/**
58-
* fill in here...
59-
*/
58+
/**
59+
* fill in here...
60+
*/
6061
}
6162

6263
/** <!--*******************************************************************-->
@@ -69,13 +70,11 @@ inline int[*] escapeTime( complex[*] plane, int depth)
6970
inline
7071
Color8::color[.,.] intArrayToMonochrome( int[.,.] a)
7172
{
72-
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
73+
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
7374

74-
a = (a * 256) / maxval(a);
75+
a = (a * 255) / maxval(a);
7576

76-
d = with {
77-
( .<= iv <= .) : clut[ a[ iv]];
78-
} : genarray( shape(a), Color8::black());
77+
return { iv -> clut[ a[ iv]] };
7978

8079
return( d);
8180
}

L8_case-study_mandelbrot/Fractal_tier2.sac

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export all;
77

88
/** <!--*******************************************************************-->
99
*
10-
* @fn complex escapeValue(complex z, int depth)
10+
* @fn int, complex escapeTimeAndValue (complex z, int depth)
1111
*
1212
* @brief iteratively computes c = c*c + z starting from c=z.
1313
* terminates either when |c| > 2 or depth iterations
@@ -16,46 +16,34 @@ export all;
1616
*
1717
* @return final complex value
1818
*****************************************************************************/
19-
int, complex escapeTimeAndValue(complex z, int depth)
19+
int, complex escapeTimeAndValue (complex z, int depth)
2020
{
21-
i=0; c=z;
21+
i=0; c=z;
2222

23-
while( (normSq( c) <= 4d) && (i <= depth)) {
24-
c=c*c+z; i++;
25-
}
23+
while( (normSq( c) <= 4d) && (i <= depth)) {
24+
c=c*c+z; i++;
25+
}
2626

27-
return(i, c);
27+
return(i, c);
2828
}
2929

3030
/** <!--*******************************************************************-->
3131
*
32-
* @fn complex[*] escapeValue(complex[*] z, int depth)
32+
* @fn int[m,n], complex[m,n] escapeTimeAndValue (complex[m,n] z, int depth)
3333
*
3434
* @brief maps escapeValue to an entire array of complex numbers
3535
*
3636
*****************************************************************************/
3737
inline
38-
int[.,.], complex[.,.] escapeTimeAndValue( complex[.,.] plane, int depth)
38+
int[m,n], complex[m,n] escapeTimeAndValue ( complex[m,n] plane, int depth)
3939
{
40-
times = with {
41-
( . <= x <= .) {
42-
t, v = escapeTimeAndValue( plane[x], depth);
43-
} : t;
44-
} : genarray( shape( plane), 0);
45-
46-
values = with {
47-
( . <= x <= .) {
48-
t, v = escapeTimeAndValue( plane[x], depth);
49-
} : v;
50-
} : genarray( shape( plane), toc(0));
51-
52-
return( times, values);
40+
return { iv -> escapeTimeAndValue (plane[iv]) };
5341
}
5442

5543

5644
/** <!--*******************************************************************-->
5745
*
58-
* @fn double normalizedIterationCount(int n, complex zn)
46+
* @fn double[d:shp] normalizedIterationCount (int[d:shp] n, complex[d:shp] zn)
5947
*
6048
* @brief normalizes the iteration counts in "n" taking the distance of the
6149
* corresponding final complex numbers from the origin into account.
@@ -66,15 +54,15 @@ int[.,.], complex[.,.] escapeTimeAndValue( complex[.,.] plane, int depth)
6654
* @return the normalized iteration counts
6755
*****************************************************************************/
6856
inline
69-
double[*] normalizedIterationCount(int[*] n, complex[*] zn)
57+
double[d:shp] normalizedIterationCount(int[d:shp] n, complex[d:shp] zn)
7058
{
7159
return( where( (norm( zn) <= 2d) , 0d , tod(n+1) - log2( log2( norm( zn)))));
7260
}
7361

7462

7563
/** <!--*******************************************************************-->
7664
*
77-
* @fn color[.,.] doubleArrayToRGB( double[.,.] a)
65+
* @fn color[d:shp] doubleArrayToRGB( double[d:shp] a)
7866
*
7967
* @brief transforms an array of doubles into RGB values, by
8068
* FIRST scaling them into values between 0.0 and 360.0, and
@@ -85,7 +73,7 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn)
8573
* @return RGB values
8674
*****************************************************************************/
8775
inline
88-
Color8::color[.,.] doubleArrayToRGB( double[.,.] a)
76+
Color8::color[d:shp] doubleArrayToRGB( double[d:shp] a)
8977
{
9078
max = maxval( a);
9179
min = minval( a);

L8_case-study_mandelbrot/Fractal_tier2_empty.sac

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export all;
77

88
/** <!--*******************************************************************-->
99
*
10-
* @fn complex escapeValue(complex z, int depth)
10+
* @fn int, complex escapeTimeAndValue (complex z, int depth)
1111
*
1212
* @brief iteratively computes c = c*c + z starting from c=z.
1313
* terminates either when |c| > 2 or depth iterations
@@ -16,39 +16,34 @@ export all;
1616
*
1717
* @return final complex value
1818
*****************************************************************************/
19-
inline
20-
complex escapeValue(complex z, int depth)
19+
int, complex escapeTimeAndValue (complex z, int depth)
2120
{
22-
i=0; c=z;
21+
i=0; c=z;
2322

24-
while( (normSq( c) <= 4d) && (i <= depth)) {
25-
c=c*c+z; i++;
26-
}
23+
while( (normSq( c) <= 4d) && (i <= depth)) {
24+
c=c*c+z; i++;
25+
}
2726

28-
return(c);
27+
return(i, c);
2928
}
3029

3130
/** <!--*******************************************************************-->
3231
*
33-
* @fn complex[*] escapeValue(complex[*] z, int depth)
32+
* @fn int[m,n], complex[m,n] escapeTimeAndValue (complex[m,n] z, int depth)
3433
*
3534
* @brief maps escapeValue to an entire array of complex numbers
3635
*
3736
*****************************************************************************/
3837
inline
39-
complex[.,.] escapeValue( complex[.,.] plane, int depth)
38+
int[m,n], complex[m,n] escapeTimeAndValue ( complex[m,n] plane, int depth)
4039
{
41-
values = with {
42-
( . <= x <= .) : escapeValue( plane[x], depth);
43-
} : genarray( shape( plane), toc(0));
44-
45-
return( values);
40+
return { iv -> escapeTimeAndValue (plane[iv]) };
4641
}
4742

4843

4944
/** <!--*******************************************************************-->
5045
*
51-
* @fn double normalizedIterationCount(int n, complex zn)
46+
* @fn double[d:shp] normalizedIterationCount (int[d:shp] n, complex[d:shp] zn)
5247
*
5348
* @brief normalizes the iteration counts in "n" taking the distance of the
5449
* corresponding final complex numbers from the origin into account.
@@ -59,17 +54,17 @@ complex[.,.] escapeValue( complex[.,.] plane, int depth)
5954
* @return the normalized iteration counts
6055
*****************************************************************************/
6156
inline
62-
double[*] normalizedIterationCount(int[*] n, complex[*] zn)
57+
double[d:shp] normalizedIterationCount(int[d:shp] n, complex[d:shp] zn)
6358
{
64-
/**
65-
* fill in here...
66-
*/
59+
/**
60+
* fill in here...
61+
*/
6762
}
6863

6964

7065
/** <!--*******************************************************************-->
7166
*
72-
* @fn color[.,.] doubleArrayToRGB( double[.,.] a)
67+
* @fn color[d:shp] doubleArrayToRGB( double[d:shp] a)
7368
*
7469
* @brief transforms an array of doubles into RGB values, by
7570
* FIRST scaling them into values between 0.0 and 360.0, and
@@ -80,11 +75,11 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn)
8075
* @return RGB values
8176
*****************************************************************************/
8277
inline
83-
Color8::color[.,.] doubleArrayToRGB( double[.,.] a)
78+
Color8::color[d:shp] doubleArrayToRGB( double[d:shp] a)
8479
{
85-
/**
86-
* fill in here...
87-
*/
80+
/**
81+
* fill in here...
82+
*/
8883
}
8984

9085

L8_case-study_mandelbrot/mandelbrot.sac

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ use Fractal_tier2 : all;
1717
use Stencil_tier3 : all;
1818

1919
inline
20-
color[.,.] stretchRgb( color[.,.] pic, int stretch)
20+
color[ms,ns] stretchRgb( color[m,n] pic, int stretch)
2121
{
22-
res = with {
23-
(. <= iv <= .): pic[ iv / stretch];
24-
} : genarray( shape(pic) * stretch, black());
25-
return( res);
22+
return { iv -> pic[ iv / stretch] | iv < shape(pic) * stretch };
2623
}
2724

2825
/* Main ******************************************************************** */

L8_case-study_mandelbrot/mandelbrot_simple.sac

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ use Fractal_tier1 : all;
1212
use Fractal_tier2 : all;
1313

1414
inline
15-
color[.,.] stretchRgb( color[.,.] pic, int stretch)
15+
color[ms,ns] stretchRgb( color[m,n] pic, int stretch)
1616
{
17-
res = with {
18-
(. <= iv <= .): pic[ iv / stretch];
19-
} : genarray( shape(pic) * stretch, black());
20-
return( res);
17+
return { iv -> pic[ iv / stretch] | iv < shape(pic) * stretch };
2118
}
2219

2320
/* Main ******************************************************************** */

0 commit comments

Comments
 (0)