Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -3,12 +3,12 @@ import std.stdio, std.math, std.numeric, std.algorithm;
|
|||
struct V3 {
|
||||
double[3] v;
|
||||
|
||||
@property V3 normalize() pure nothrow const {
|
||||
@property V3 normalize() pure nothrow const @nogc {
|
||||
immutable double len = dotProduct(v, v).sqrt;
|
||||
return [v[0] / len, v[1] / len, v[2] / len].V3;
|
||||
}
|
||||
|
||||
double dot(in ref V3 y) pure nothrow const {
|
||||
double dot(in ref V3 y) pure nothrow const @nogc {
|
||||
immutable double d = dotProduct(v, y.v);
|
||||
return d < 0 ? -d : 0;
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ void drawSphere(in double k, in double ambient, in V3 light) nothrow {
|
|||
static bool hitSphere(in ref Sphere sph,
|
||||
in double x0, in double y0,
|
||||
out double z1,
|
||||
out double z2) pure nothrow {
|
||||
out double z2) pure nothrow @nogc {
|
||||
immutable double x = x0 - sph.cx;
|
||||
immutable double y = y0 - sph.cy;
|
||||
immutable double zsq = sph.r ^^ 2 - (x ^^ 2 + y ^^ 2);
|
||||
|
|
|
|||
41
Task/Death-Star/JavaScript/death-star.js
Normal file
41
Task/Death-Star/JavaScript/death-star.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body style="margin:0">
|
||||
<canvas id="myCanvas" width="250" height="250" style="border:1px solid #d3d3d3;">
|
||||
Your browser does not support the HTML5 canvas tag.
|
||||
</canvas>
|
||||
<script>
|
||||
var c = document.getElementById("myCanvas");
|
||||
var ctx = c.getContext("2d");
|
||||
//Fill the canvas with a dark gray background
|
||||
ctx.fillStyle = "#222222";
|
||||
ctx.fillRect(0,0,250,250);
|
||||
|
||||
// Create radial gradient for large base circle
|
||||
var grd = ctx.createRadialGradient(225,175,190,225,150,130);
|
||||
grd.addColorStop(0,"#EEEEEE");
|
||||
grd.addColorStop(1,"black");
|
||||
//Apply gradient and fill circle
|
||||
ctx.fillStyle = grd;
|
||||
ctx.beginPath();
|
||||
ctx.arc(125,125,105,0,2*Math.PI);
|
||||
ctx.fill();
|
||||
|
||||
// Create linear gradient for small inner circle
|
||||
var grd = ctx.createLinearGradient(75,90,102,90);
|
||||
grd.addColorStop(0,"black");
|
||||
grd.addColorStop(1,"gray");
|
||||
//Apply gradient and fill circle
|
||||
ctx.fillStyle = grd;
|
||||
ctx.beginPath();
|
||||
ctx.arc(90,90,30,0,2*Math.PI);
|
||||
ctx.fill();
|
||||
|
||||
//Add another small circle on top of the previous one to enhance the "shadow"
|
||||
ctx.fillStyle = "black";
|
||||
ctx.beginPath();
|
||||
ctx.arc(80,90,17,0,2*Math.PI);
|
||||
ctx.fill();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/*REXX program to draw a "deathstar", a sphere with another subtracted. */
|
||||
signal on syntax; signal on novalue /*handle REXX program errors. */
|
||||
signal on syntax; signal on noValue /*handle REXX program errors. */
|
||||
numeric digits 20 /*use a fair amount of precision.*/
|
||||
lightSource = norm('-50 30 50')
|
||||
call drawSphereM 2, .5, lightSource
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────drawSphereM subroutine──────────────*/
|
||||
/*──────────────────────────────────DRAWSPHEREM subroutine──────────────*/
|
||||
drawSphereM: procedure; parse arg k,ambient,lightSource
|
||||
z1=0; z2=0
|
||||
parse var lightSource s1 s2 s3 /*break-apart the light source. */
|
||||
|
|
@ -21,7 +21,7 @@ ship= 20 20 0 20 ; parse var ship ship.cx ship.cy ship.cz ship.radius
|
|||
hole=' 1 1 -6 20'; parse var hole hole.cx hole.cy hole.cz hole.radius
|
||||
|
||||
do i=floor(ship.cy-ship.radius) to ceil(ship.cy+ship.radius)+1; y=i+.5; aLine=
|
||||
do j=trunc(floor(ship.cx - 2*ship.radius) ) to,
|
||||
do j=trunc(floor(ship.cx - 2*ship.radius) ) to ,
|
||||
trunc( ceil(ship.cx + 2*ship.radius) +1)
|
||||
x=.5*(j-ship.cx) + .5 + ship.cx; !bg=0; !pos=0; !neg=0; z1=0; z2=0
|
||||
?=hitSphere(ship, x, y); zb1=z1; zb2=z2
|
||||
|
|
@ -52,7 +52,7 @@ hole=' 1 1 -6 20'; parse var hole hole.cx hole.cy hole.cz hole.radius
|
|||
end /*i*/
|
||||
|
||||
return
|
||||
/*──────────────────────────────────hitSphere subroutine────────────────*/
|
||||
/*──────────────────────────────────HITSPHERE subroutine────────────────*/
|
||||
hitSphere: procedure expose z1 z2; parse arg $.cx $.cy $.cz $.radius, x0, y0
|
||||
x=x0-$.cx
|
||||
y=y0-$.cy
|
||||
|
|
@ -61,15 +61,15 @@ hitSphere: procedure expose z1 z2; parse arg $.cx $.cy $.cz $.radius, x0, y0
|
|||
z1=$.cz-_
|
||||
z2=$.cz+_
|
||||
return 1
|
||||
/*──────────────────────────────────"1-liner" subroutines───────────────*/
|
||||
V3: procedure; parse arg v; return norm(v)
|
||||
/*──────────────────────────────────one─liner subroutines────────────────────────────────────────────────────────────────────────────────────────────────────────*/
|
||||
dot.: procedure; parse arg x,y; d=dot(x,y); if d<0 then return -d; return 0
|
||||
dot: procedure; parse arg x,y; s=0; do j=1 for words(x); s=s+word(x,j)*word(y,j); end; return s
|
||||
err: say; say; say center(' error! ',max(40,linesize()%2),"*"); say; do j=1 for arg(); say arg(j); say; end; say; exit 13
|
||||
novalue: syntax: call err 'REXX program' condition('C') "error", condition('D'),'REXX source statement (line' sigl"):",sourceline(sigl)
|
||||
ceil: procedure; parse arg x; _=trunc(x); return _ + (x>0) * (x\=_)
|
||||
floor: procedure; parse arg x; _=trunc(x); return _ - (x<0) * (x\=_)
|
||||
norm: parse arg _1 _2 _3; _=sqrt(_1**2+_2**2+_3**2); return _1/_ _2/_ _3/_
|
||||
noValue: syntax: call err 'REXX program' condition('C') "error", condition('D'),'REXX source statement (line' sigl"):",sourceline(sigl)
|
||||
sqrt: procedure; parse arg x; if x=0 then return 0; return .sqrt(x)/1
|
||||
.sqrt: d=digits();numeric digits 11;g=.sqrtG();do j=0 while p>9;m.j=p;p=p%2+1;end;do k=j+5 by -1 to 0;if m.k>11 then numeric digits m.k;g=.5*(g+x/g);end;return g
|
||||
.sqrtG: numeric form; m.=11; p=d+d%4+2; v=format(x,2,1,,0) 'E0'; parse var v g 'E' _ .; return g*.5'E'_%2
|
||||
V3: procedure; parse arg v; return norm(v)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue