| 1 | import math as m; import term;import strings;import time{sleep}; const |
| 2 | alt = '.,-~:;=!*#$@';[direct_array_access];fn rd(cs int, ls int,a f64, |
| 3 | b f64) {tt_spacing, p_spacing:=0.07,0.02; r1,r2,k2 :=1,2,5; k1:=cs*k2* |
| 4 | 2/(20*(r1+r2));c_a,s_a:=m.cos(a),m.sin(a);c_b,s_b:=m.cos(b), m.sin(b); |
| 5 | mut o:=[][]rune{len:cs, init:[]rune{len:ls,init:` `}}; mut z_buffer := |
| 6 | [][]f64{len:cs, init:[]f64{ len:ls,init: 0}};for tt:=f64(0);tt<2*m.pi; |
| 7 | tt+=tt_spacing{c_tt,s_tt:=m.cos(tt),m.sin(tt);for phi:=f64(0);phi<2*m. |
| 8 | pi;phi+=p_spacing{c_p,s_p:=m.cos(phi),m.sin(phi); c_x,c_y:= r2+r1*c_tt |
| 9 | ,r1*s_tt;x:=c_x*(c_b*c_p+s_a*s_b*s_p)-c_y*c_a*s_b;y:=c_x*(s_b*c_p-s_a* |
| 10 | c_b*s_p)+c_y*c_a*c_b;z:=k2+c_a*c_x*s_p+c_y*s_a;ooz:=1/z;xp:= int(cs/2+ |
| 11 | k1*ooz*x);yp:=int(ls/2-k1*ooz*y);l:=c_p*c_tt*s_b-c_a*c_tt*s_p-s_a*s_tt |
| 12 | +c_b*(c_a*s_tt-c_tt*s_a*s_p);if l>0{ if xp<0 || yp<0 ||xp>=cs||yp>=ls{ |
| 13 | continue};if ooz>z_buffer[int(xp)][int(yp)]{ z_buffer[xp][yp]=ooz; lui |
| 14 | := int(l*8);o[xp][yp] = alt[lui]}}}};mut sb:=strings.new_builder(ls*cs |
| 15 | );;;; print('\x1b[H');;;;; for j:=0; j<ls; j++ { for i:=0; i<cs; i++ { |
| 16 | sb.write_rune(o[i][j])};sb.write_rune(`\n`);}print(sb.str())};fn main( |
| 17 | ){ term.clear(); cs,ls := 80,25; mut a,mut b := f64(0), f64(0);for{rd( |
| 18 | cs, ls, a, b); a += 0.05 ; b += 0.07; sleep( 15 * time.millisecond )}} |
| 19 | |