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))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.