11import Utilities as utils;
22
3+
34export proc square(x: int ): int {
45 writeln (x, " * " , x, " = " , x * x);
56 return x * x;
@@ -15,29 +16,35 @@ export proc sumArray(a: [] int): int {
1516export proc printArray(a: [] int ): void {
1617 writeln (a);
1718}
18- export proc getNewFrame(ref frame: [] real (32 ),height: int , width: int ,channels: int ): [] real (32 ) {
19- // const dom = {0..<height,0..<width,0..<channels};
20- // const rgb: [dom] real(32) = reshape(frame,dom);
21- // const ret = reshape(rgb,{0..<dom.size});
22- // return ret;
23- // return [x in frame] x * 1.2;
2419
25- // const dom = {0..<height,0..<width,0..<channels} ;
26- // const rgb: [dom] real(32) = reshape(frame,dom) ;
20+ use Time ;
21+ use Math ;
2722
28- // const m = max reduce frame;
29- // return [x in frame] m;
3023
24+ proc getTime() {
25+ const tm = timeSinceEpoch();
26+ const sec = tm.chpl_seconds : real (64 );
27+ const us = tm.chpl_microseconds : real (64 );
28+ const t = sec + (us/ 1000000.0 );
29+ return t;
30+ }
31+
32+ const startTime = getTime();
33+
34+ export proc getNewFrame(ref frame: [] real (32 ),height: int , width: int ,channels: int ): [] real (32 ) {
35+
36+ const t = getTime() - startTime;
3137 const shape = (height,width,channels);
3238 forall i in 0 ..< frame.size {
3339 const idx = utils.indexAt(i,(...shape));
3440 const (h,w,c) = idx;
35- // const color = frame[i];
41+ const (u,v) = (h: real (64 )/ height,w: real (64 )/ width);
42+ const color = frame[ i] ;
3643 // if h < width {
3744 // frame[utils.linearIdx(shape,(h,w,c))] = frame[utils.linearIdx(shape,(h,w,c-1))];
3845 // }
3946 if h < width {
40- frame[ utils.linearIdx(shape,(h,w,0 ))] = 1.0 ;
47+ frame[ utils.linearIdx(shape,(h,w,0 ))] *= Math.sin( 2.0 * t + 5.0 * u) : real ( 32 ) ;
4148 }
4249 }
4350 return frame;
0 commit comments