2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
42
Task/Death-Star/Q/death-star-1.q
Normal file
42
Task/Death-Star/Q/death-star-1.q
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/ https://en.wikipedia.org/wiki/BMP_file_format
|
||||
/ BITMAPINFOHEADER / RGB24
|
||||
|
||||
/ generate a header
|
||||
|
||||
genheader:{[w;h]
|
||||
0x424d, "x"$(f2i4[54+4*h*w],0,0,0,0,54,0,0,0,40,0,0,0,
|
||||
f2i4[h],f2i4[w],1,0,24,0,0,0,0,0,
|
||||
f2i4[h*((w*3)+((w*3)mod 4))],
|
||||
19,11,0,0,19,11,0,0,0,0,0,0,0,0,0,0)};
|
||||
|
||||
/ generate a raster line at a vertical position
|
||||
|
||||
genrow:{[w;y;fcn]
|
||||
row:enlist 0i;xx:0i;do[w;row,:fcn[xx;y];xx+:1i];row,:((w mod 4)#0i);1_row};
|
||||
|
||||
/ generate a bitmap
|
||||
|
||||
genbitmap:{[w;h;fcn]
|
||||
ary:enlist 0i;yy:0i;do[h;ary,:genrow[w;yy;fcn];yy+:1i];"x"$1_ary};
|
||||
|
||||
/ deal with endianness
|
||||
/ might need to reverse last line if host computer is not a PC
|
||||
|
||||
f2i4:{[x] r:x;
|
||||
s0:r mod 256;r-:s0; r%:256;
|
||||
s1:r mod 256;r-:s1; r%:256;
|
||||
s2:r mod 256;r-:s2; r%:256;
|
||||
s3:r mod 256;
|
||||
"h"$(s0,s1,s2,s3)}
|
||||
|
||||
/ compose and write a file
|
||||
|
||||
writebmp:{[w;h;fcn;fn]
|
||||
fn 1: (genheader[h;w],genbitmap[w;h;fcn])};
|
||||
|
||||
/ / usage example:
|
||||
/ w:400;
|
||||
/ h:300;
|
||||
/ fcn:{x0:x-w%2;y0:y-h%2;r:175;$[(r*r)>((x0*x0)+(y0*y0));(0;0;255);(0;255;0)]};
|
||||
/ fn:`:demo.bmp;
|
||||
/ writebmp[w;h;fcn;fn];
|
||||
38
Task/Death-Star/Q/death-star-2.q
Normal file
38
Task/Death-Star/Q/death-star-2.q
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
w:400; h:300; r:150; l:-0.5 0.7 0.5
|
||||
sqrt0:{$[x>0;sqrt x;0]};
|
||||
|
||||
/ get x,y,z position of point on sphere given x,y,r
|
||||
|
||||
z:{[x;y;r]sqrt0((r*r)-((x*x)+(y*y)))};
|
||||
|
||||
/ get diffused light at point on sphere
|
||||
|
||||
is:{[x;y;r]
|
||||
z0:z[x;y;r];
|
||||
s:(x;y;z0)%r;
|
||||
$[z0>0;i:0.5*1+(+/)(s*l);i:0];
|
||||
i};
|
||||
|
||||
/ get pixel value at given image position
|
||||
|
||||
fcn:{[xpx;ypx]
|
||||
x:xpx-w%2;
|
||||
y:ypx-h%2;
|
||||
z1:z[x;y;r];
|
||||
x2:x+190;
|
||||
z2:170-z[x2;y;r];
|
||||
$[(r*r)<((x*x)+(y*y));
|
||||
$[y>-50;
|
||||
i:3#0;
|
||||
i:200 100 50];
|
||||
$[z2>z1;
|
||||
i:3#is[x;y;r]*140;
|
||||
i:3#is[(-1*x2);(-1*y);r]*120]
|
||||
];
|
||||
"i"$i};
|
||||
|
||||
/ do it ...
|
||||
|
||||
\l bmp.q
|
||||
fn:`:demo.bmp;
|
||||
writebmp[w;h;fcn;fn];
|
||||
Loading…
Add table
Add a link
Reference in a new issue