JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

Graphics

refactus' sphere 1 liner

another trick for more resolution...you can just set your font size to really tiny and jack the width way up. but it'll run waaay slower, O(n^2) with the width like you'd expect

I could get twice the resolution with unicode half or quarter blocks using both ansi foreground and background colors, and the jagged edges would get a lot smoother with anti-aliasing. but it's getting pretty loaded for a one-liner already

in real games, everything depends on the clock for ticks, so e.g. physics don't depend on the frame rate

11:54:32 PM - refactus: I totally could, but it'd be all the same things as other graphics/animation/game writing tutorials. the time stuff, the vector math, the shading, it's all the same concepts except really low res software rendering instead of hardware shaders and all that boilerplate everyone just copies and pastes and wraps away in some scary black box function I do full res the same way by outputting NetPBMs. no animation that way though 11:59:17 PM - refactus: isn't that cool!? bascially you just write a 3-string header with format, width, and height, and then a long list of decimal numbers for r g b values into a text file and it's a valid netpbm image. super easy if you don't want to depend on external modules for png or whatever

12:16:45 AM - refactus: if you like terminal graphics you should look up sixel too. you can basically draw arbitrary bitmaps in any terminal with VT340 support. I think it originally came from a feature of DEC printers with a special print head with a grid of 6 dots per character position or something, used for graphics output on like physical paper printer terminals

(def w 78)
(def b @"")
(var t 0)
(while (zero? (os/shell "clear"))
  (print b "Ctrl-C to interrupt")
  (buffer/clear b)
  (os/sleep (max 0 (+
    (/ 1 60)
    (-
      (+ 0 t)
      (set t (* 2 (os/clock)))))))
  (loop [y :range [0 (/ w 2)]]
    (loop [x :range [0 w]]
      (def x
        (/
          (- x (/ w 2))
          (* w .5 .9)))
      (def y
        (/
          (- (/ w 4) y)
          (* w .25 .9)))
      (def z
        (math/sqrt (-
          1
          (+ (* x x) (* y y)))))
      (buffer/push b (if
        (nan? z) "."
        ([" " "░" "▒" "▓" "█"]
          (max 0 (min 4 (math/floor (+
            (* 1.5 (math/random))
            -.5
            (* 4.5 (*
              (math/floor (+ 1
                (math/cos (* 10 (math/acos
                  (/
                    (+
                      (* x (math/cos t))
                      y
                      (* z (math/sin t)))
                    (math/sqrt 2)))))))
              (/
                (+ x y z)
                (math/sqrt 3))))))))))))
    (buffer/push b "\n")))