vue3d.py

Created by schraf

Created on August 20, 2022

755 Bytes

Autre version ici


from kandinsky import set_pixel, fill_rect
from math import *
from random import random

for n in range(223):
  for m in range(320):
    x,y,z,u,v = 0,-.1,-3,(m-159.9)/160,(.8*n-92.9)/111
    w = 1/sqrt(u*u+v*v+1)
    u *= w
    v *= w
    i = 0 if u == 0 else copysign(1, u)
    b, k = 0, 1
    while k !=0:
      k,e,f = 0, x-i, y-i
      p = u*e+v*f+w*z
      d = p*p-e*e-f*f-z*z+1
      if d > 0:
        t = -p-sqrt(d)
        if t > 0:
          k, b = 1, 1
          x += t*u
          y += t*v
          z += t*w
          e,f,p = x-i,y-i,2*(u*e+v*f+w*z)
          u -= p*e
          v -= p*f
          w -= p*z
          i = -i
    if v < 0:
      p = (y+2)/v
      b = (int(x-u*p)+int(z-w*p)) % 2
    set_pixel(m, 222-n, (255*b,)*3)

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.