BEGIN {
print "P3\n200 200\n255"
pointx = 0.0
pointy = 0.0
pointz = 0.0
radius = 0.5
fromz = 3.0
tox = 0.0
toy = 0.0
toz = -1.0
for(fromy = -1.0; fromy < 1.0; fromy += 2.0/200)
{
for(fromx = -1.0; fromx < 1.0; fromx += 2.0/200)
{
vectorx = fromx - pointx
vectory = fromy - pointy
vectorz = fromz - pointz
b = tox * vectorx + toy * vectory + toz * vevtorz
c = vectorx * vectorx + vectory * vectory + vectorz * vevtorz - radius*radius
d = b * b - c
if(d < 0)
{
print "100 100 100 "
continue
}
det = sqrt(d)
t = -b + det
if(t < 0)
{
print "100 100 100 "
continue
}
# shading
lx = 0.5773
ly = -0.5773
lz = 0.5773
v1x = t * tox + fromx
v1y = t * toy + fromy
v1z = t * toz + fromz
v2x = v1x - pointx
v2y = v1y - pointy
v2z = v1z - pointz
len = sqrt(v2x*v2x + v2y*v2y + v2z*v2z)
v2x /= len
v2y /= len
v2z /= len
d = lx*v2x + ly*v2y + lz*v2z
col = 255.0*d + 50
if(col > 255){
col = 255
}
if(col < 0){
col = 0
}
printf("%d 0 0\n", col)
}
}
}