sphere.py

Created by gianfranco-oddenino

Created on July 09, 2018

274 Bytes

The script draws a sphere with a radius of 100 pixels in the center of the screen. The shading is calculated using the scalar product of the normal vector at the surface and the direction (1,1,1)


from math import *
from kandinsky import *

for x in range(-160,160):
  for y in range(-111,112):
    r2=1E4-x**2-y**2
    if r2<0:
      c=0
    else:
      z=sqrt(r2)
      c=max(round((x+y+z)/(sqrt(3)*100)*200)+55,55)
    set_pixel(160+x,111-y,color(c,c,c))