Advertisement
uriid1

Sin Wave in term | lua

Sep 29th, 2022
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. --[[
  2.     ####--------------------------------####
  3.     #--# Author:   by uriid1            #--#
  4.     #--# License:  GNU GPLv3            #--#
  5.     #--# Telegram: @main_moderator      #--#
  6.     #--# E-mail:   appdurov@gmail.com   #--#
  7.     ####--------------------------------####
  8. --]]
  9.  
  10. local function printl(...)
  11.     io.stdout:write(...)
  12. end
  13.  
  14. local function sleep(t)
  15.     local sec = tonumber(os.clock() + t)
  16.     while os.clock() < sec do
  17.     end
  18. end
  19.  
  20. local function clear()
  21.     io.stdout:write('\027\091\072\027\091\050\074\027\091\051\074')
  22. end
  23.  
  24. local term = {
  25.     w = 64;
  26.     h = 25;
  27. }
  28.  
  29. local sin_map = {}
  30. for y = 1, term.h do
  31.     sin_map[y] = {}
  32.     for x = 1, term.w do
  33.         sin_map[y][x] = 0
  34.     end
  35. end
  36.  
  37. local new_x = 0
  38. while true do
  39.     local sin_step = 0
  40.     for y = 1, #sin_map do
  41.         for x = 1, #sin_map[1] do
  42.             sin_step = sin_step + (math.pi/8)
  43.             local sin_wave = math.sin(sin_step + new_x) + #sin_map/2
  44.             if sin_map[math.ceil(sin_wave)] then
  45.                 sin_map[math.ceil(sin_wave)][x] = 1
  46.             end
  47.         end
  48.     end
  49.  
  50.     new_x = new_x + 1
  51.  
  52.     for y = 1, #sin_map do
  53.         for x = 1, #sin_map[1] do
  54.             if sin_map[y][x] == 1 then
  55.                 printl('+')
  56.             else
  57.                 printl(' ')
  58.             end
  59.         end
  60.         printl('\n')
  61.     end
  62.  
  63.     for y = 1, #sin_map do
  64.         for x = 1, #sin_map[1] do
  65.             sin_map[y][x] = 0
  66.         end
  67.     end
  68.  
  69.     clear()
  70.     sleep(0.2)
  71. end
Tags: lua
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement