Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

I tried to create donut.mojo. is there a way to print in mojo without going to the new line? and is there a way to clear the screen like in python

$
0
0
from python import Python# from tensor import Tensor, TensorSpec, TensorShape# from utils.index import Indexfrom math import sin,cosfrom python import Pythonfn main() raises:    let warn=Python.import_module("warnings")    let np = Python.import_module("numpy")    let bd=Python.import_module("builtins")    let os=Python.import_module("os")    let sys=Python.import_module('sys')    var a: Float64=0    var b: Float64=0    let height: Int64=24    let width: Int64=80    let window=np.array([".", ",", "-", "~", ":", ";", "=", "!", "*", "$", "#", "@"])#".,-~:;=!*#$@"    var clear: String = "clear"    _=os.system(clear)    var x=False    while True:        var z = np.full(4*24*80,0)        var screen= np.full(24*80,'')        var j: Float64=0        while j<6.28:            j+=0.07            var i: Float64=0            while i<6.28:                i+=0.02                var sinA:Float64=sin(a)                var cosA: Float64=cos(a)                var cosB: Float64=cos(b)                var sinB: Float64=sin(b)                var sini: Float64=sin(i)                var cosi: Float64=cos(i)                var cosj: Float64=cos(j)                var sinj: Float64=sin(j)                var cosj2: Float64=cosj+2                var mess: Float64=1/(sini*cosj2*sinA+sinj*cosA+5)                var t: Float64=sini*cosj2*cosA-sinj* sinA                var x: Int64 = int(40+30*mess*(cosi*cosj2*cosB-t*sinB))                var y: Int64 = int(11+15*mess*(cosi*cosj2*sinB +t*cosB))                var o: Int64 = int(x+width*y)                var N: Int64 = int(8*((sinj*sinA-sini*cosj*cosA)*cosB-sini*cosj*sinA-sinj*cosA-cosi *cosj*sinB))                if  y>0 and y<height and x>0 and x<width and z[o] < mess:                    #print("!!")                    var temp=np.insert(z,o,mess)                    z=temp                    if N>0:                        let temps=window[N]                        temp=np.insert(screen,o,temps)                        screen=temp                    else:                        let temps=window[0]                        temp=np.insert(screen,o,temps)                        screen=temp        _=os.system(clear)        for i in range(screen.shape[0]):            var char = screen[i]            if np.remainder(i,width) == 0:                 print()            else:                #print(char)                _=sys.stdout.write(char)        a+=0.04        b+=0.02

i tried different libraries and print("",end="") doesn't work in mojo

also is there an alternative to os.system("clear") in mojo?

the result was that it is calculating the surface normal and the other values correctly but because of these 2 limitations i am not able to get that donut.mojo to work


Viewing all articles
Browse latest Browse all 13921

Trending Articles