v2 / vlib / v / fmt / tests / donut_card_input.vv
18 lines · 18 sloc · 1.25 KB · 0b0499b4253f85f4a5118619dd6b4907f4dd4e55
Raw
1import math as m; import term;import strings;import time{sleep}; const
2alt = '.,-~:;=!*#$@';[direct_array_access];fn rd(cs int, ls int,a f64,
3b f64) {tt_spacing, p_spacing:=0.07,0.02; r1,r2,k2 :=1,2,5; k1:=cs*k2*
42/(20*(r1+r2));c_a,s_a:=m.cos(a),m.sin(a);c_b,s_b:=m.cos(b), m.sin(b);
5mut 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;
7tt+=tt_spacing{c_tt,s_tt:=m.cos(tt),m.sin(tt);for phi:=f64(0);phi<2*m.
8pi;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*
10c_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+
11k1*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{
13continue};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++ {
16sb.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(
18cs, ls, a, b); a += 0.05 ; b += 0.07; sleep( 15 * time.millisecond )}}
19