Sine Wave

Priskribo de la ĉi-paĝa enhavo

Konvertado de Sine Wave al pluri program-lingvoj.

Etikedoj:

Sine Wave ofte estas la tria programo konvertita en la projektoj Basics off.

Ĉi-tiu programo estas konvertita en 30 program-lingvojn.

Vidu ankaŭ: Grando de la ekzekutebla dosiero de Sine Wave.

Originalo

Origin of sine_wave.bas:

Anonymous, 1978.

Creative Computing's BASIC Games.

- https://www.atariarchives.org/basicgames/showpage.php?page=146
- http://vintage-basic.net/games.html
- http://vintage-basic.net/bcg/sinewave.bas
- http://www.retroarchive.org/cpm/games/ccgames.zip

5 rem PRINT CHR$(26):WIDTH 80
10 PRINT TAB(30);"SINE WAVE":PRINT
20 PRINT TAB(15);"CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
30 PRINT:PRINT:PRINT
32 INPUT "ENTER TWO WORDS SEPARATED BY A COMMA ";F$,S$
34 PRINT
36 INPUT "ENTER 'RETURN' TO START THE PROGRAM. ";RESP$
38 PRINT CHR$(26)
40 REM ARKABLE PROGRAM BY DAVID AHL
50 B=0
100 REM  START LONG LOOP
110 FOR T=0 TO 40 STEP .25
120 A=INT(26+25*SIN(T))
130 PRINT TAB(A);
140 IF B=1 THEN 180
150 PRINT F$
160 B=1
170 GOTO 200
180 PRINT S$
190 B=0
200 NEXT T

En 8th

\ Sine Wave

\ Original version in BASIC:
\   Anonymous, 1978.
\   Creative Computing's BASIC Games.
\   - https://www.atariarchives.org/basicgames/showpage.php?page=146
\   - http://vintage-basic.net/games.html
\   - http://vintage-basic.net/bcg/sinewave.bas
\   - http://www.retroarchive.org/cpm/games/ccgames.zip

\ This version in 8th:
\   Copyright (c) 2023, Marcos Cruz (programandala.net)
\   SPDX-License-Identifier: Fair

\ Written in 2023-03, 2023-09.

\ Last modified 20251204T2247+0100.

needs console/loaded

13 constant enter_key_code

: press_enter \ --
  repeat con:key enter_key_code n:= until! ;
  \ Wait for the Enter key be pressed.

var word0
var word1
32 constant max_word_len

: get_words \ --
  con:cls
  "Enter the first word: " .
  max_word_len null con:accept word0 !
  "Enter the second word: " .
  max_word_len null con:accept word1 ! ;
  \ Clear the screen, ask the user to enter two words and store them.

: print_credits \ --
  con:cls
  "Sine Wave\n\n" .
  "Original version in BASIC:\n" .
  "    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n\n" .
  "This version in 8th:\n" .
  "    Marcos Cruz (programandala.net), 2023.\n\n" .
  "Press Enter to start the program.\n" .
  press_enter ;
  \ Clear the screen, print the credits and wait for a keypress.

\ Print _n_ spaces.
: spaces \ n --
  repeat space n:1- while drop ;

var even \ flag used to select the word

: draw \ --
  con:cls
  true even !
  0.0 \ angle
  repeat
    dup n:sin 25.0 * 26.0 + n:int spaces
        even @ dup if word0 else word1 then @ . cr
                   not even !
        0.25 + dup 40.0 n:> not
  while! ;
  \ Draw the sine wave.

: app:main \ --
  print_credits get_words draw ;

En Ada

-- Sine Wave

-- Original version in BASIC:
--      Anonymous, 1978.
--      Creative Computing's BASIC Games.
--      - https://www.atariarchives.org/basicgames/showpage.php?page=146
--      - http://vintage-basic.net/games.html
--      - http://vintage-basic.net/bcg/sinewave.bas
--      - http://www.retroarchive.org/cpm/games/ccgames.zip

-- This version in Ada:
--      Copyright (c) 2025, Marcos Cruz (programandala.net)
--      SPDX-License-Identifier: Fair

-- Written in 2025-03.
--
-- Last modified: 20251204T2300+0100.

with ada.numerics.elementary_functions;
use ada.numerics.elementary_functions;

with ada.strings.fixed;
use ada.strings.fixed;

with ada.strings.unbounded;
use ada.strings.unbounded;

with ada.text_io;
use ada.text_io;

procedure sine_wave is

    type pair_of_words is array (0 .. 1) of unbounded_string;

    procedure clear_screen is
        escape : constant character := character'val (16#1B#); -- 0x1B
    begin
        put (escape & "[0;0H" & escape & "[2J");
    end clear_screen;

    procedure wait_for_a_keypress is
        char : character;
        available : boolean := false;
    begin
        while not available loop
            get_immediate (char, available);
        end loop;
    end wait_for_a_keypress;

    procedure print_credits is
    begin
        clear_screen;
        put_line ("Sine Wave");
        new_line;
        put_line ("Original version in BASIC:");
        put_line ("    Creative computing (Morristown, New Jersey, USA), ca. 1980.");
        new_line;
        put_line ("This version in Ada:");
        put_line ("    Copyright (c) 2025, Marcos Cruz (programandala.net)");
        put_line ("    SPDX-License-Identifier: Fair");
        new_line;
        put ("Press Enter to start the program. ");
        wait_for_a_keypress;
    end print_credits;

    procedure draw is

        angle : float;
        even : boolean := false;
        words : pair_of_words;

        procedure get_words is
        begin
            clear_screen;
            for n in 0 .. 1 loop
                put (
                    "Enter the "
                    & (if n = 0 then "first" else "second")
                    & " word: "
                );
                words (n) := to_unbounded_string (get_line);
            end loop;
        end get_words;

    begin

        clear_screen;
        get_words;
        clear_screen;

        angle := 0.0;
        while angle <= 40.0 loop
            put (
                integer (
                    float'floor (26.0 + 25.0 * sin (angle))
                )
                * " "
            );
            put_line (to_string (words (if even then 1 else 0)));
            even := not even;
            angle := angle + 0.25;
        end loop;

    end draw;

begin

    print_credits;
    draw;

end sine_wave;

En Arturo

; Sine Wave

; Original version in BASIC:
;   Anonymous, 1978.
;   Creative Computing's BASIC Games.
;   - https://www.atariarchives.org/basicgames/showpage.php?page=146
;   - http://vintage-basic.net/games.html
;   - http://vintage-basic.net/bcg/sinewave.bas
;   - http://www.retroarchive.org/cpm/games/ccgames.zip

; This version in Arturo:
;   Copyright (c) 2023, Marcos Cruz (programandala.net)
;   SPDX-License-Identifier: Fair
;
; Written on 2023-10-17.
; 
; Last modified: 20251205T0051+0100.

word: array ["" ""]

; Ask the user to enter two words and store them.
getWords: function [] [
    order: array ["first" "second"]
    loop 0 .. 1 'n [
        word\[n]: input ~"Enter the |order\[n]| word: "
    ]
]

printCredits: function [] [
    print "Sine Wave\n"
    print "Original version in BASIC:"
    print "    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n"
    print "This version in Arturo:"
    print "    Copyright (c) 2023, Marcos Cruz (programandala.net)"
    print "    SPDX-License-Identifier: Fair\n"
    input "Press Enter to start the program. "
]

draw: function [] [
    even: false
    angle: 0
    while [ lessOrEqual? angle 40 ] [
        prints repeat " " floor add 26 mul 25 sin angle
        print word\[to :integer even]
        'even: not? even
        add 'angle 0.25
    ]
]

clear
printCredits
clear
getWords
clear
draw

En C#

// Sine Wave

// Original version in BASIC:
//  Anonymous, 1978.
//  Creative Computing's BASIC Games.
//  - https://www.atariarchives.org/basicgames/showpage.php?page=146
//  - http://vintage-basic.net/games.html
//  - http://vintage-basic.net/bcg/sinewave.bas
//  - http://www.retroarchive.org/cpm/games/ccgames.zip

// This version in C#:
//  Copyright (c) 2024, Marcos Cruz (programandala.net)
//  SPDX-License-Identifier: Fair
//
// Written on 2024-12-20.
//
// Last modified: 20251205T1548+0100.

using System;

class SineWave
{
    static string[] word = {"", ""};

    // Ask the user to enter two words and store them into the `word` array.
    //
    static void getWords()
    {
        string[] order = {"first", "second"};

        int n = 0;
        while (n < 2)
        {
            while (word[n] == "")
            {
                Console.Write($"Enter the {order[n]} word: ");
                word[n] = Console.ReadLine();
            }
            n++;
        }
    }

    static void printCredits()
    {
        Console.WriteLine("Sine Wave\n");
        Console.WriteLine("Original version in BASIC:");
        Console.WriteLine("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n");
        Console.WriteLine("This version in C#:");
        Console.WriteLine("    Copyright (c) 2024, Marcos Cruz (programandala.net)");
        Console.WriteLine("    SPDX-License-Identifier: Fair\n");
        Console.Write("Press Enter to start. ");
        Console.ReadKey();
    }

    static void draw()
    {
        bool even = false;
        double angle = 0.0;

        while (angle <= 40.0)
        {
            int i = 0;
            while (i < (int) (26 + 25 * Math.Sin(angle)))
            {
                Console.Write(" ");
                i++;
            }
            Console.WriteLine(word[even ? 1 : 0]);
            even = ! even;
            angle += 0.25;
        }
    }

    static void Main()
    {
        Console.Clear();
        printCredits();
        Console.Clear();
        getWords();
        Console.Clear();
        draw();
    }
}

En C3

// Sine Wave
//
// Original version in BASIC:
//  Creative Computing (Morristown, New Jersey, USA), ca. 1980.
//
// This version in C3:
//  Copyright (c) 2025, Marcos Cruz (programandala.net)
//  SPDX-License-Identifier: Fair
//
// Written on 2025-03-07.
//
// Last modified: 20250731T1954+0200.

import std::io;

fn void clearScreen() {
    io::print("\e[0;0H\e[2J");
}

fn String acceptString(String prompt = "") {
    io::print(prompt);
    String! s = io::readline();
    if (catch excuse = s) {
        return "";
    } else {
        return s;
    }
}

fn void pressEnter(String prompt = "") {
    String discard = acceptString(prompt);
    free(discard);
}

fn String[2] getWords() {

    clearScreen();

    String[2] word = {"", ""};
    String[2] order = {"first", "second"};

    for (int n = 0; n <= 1; n += 1) {
        while (word[n] == "") {
            io::printf("Enter the %s word: ", order[n]);
            word[n] = acceptString();
        }
    }

    return word;

}

fn void printCredits() {

    clearScreen();
    io::printn("Sine Wave\n");
    io::printn("Original version in BASIC:");
    io::printn("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n");
    io::printn("This version in C3:");
    io::printn("    Copyright (c) 2025, Marcos Cruz (programandala.net)");
    io::printn("    SPDX-License-Identifier: Fair\n");
    pressEnter("Press Enter to start the program. ");

}

fn void draw() {
    clearScreen();
    String[2] word = getWords();
    bool even = false;
    for (double angle = 0.0; angle <= 40.0; angle += 0.25) {
        int spaces = (int)(26.0 + $$floor(25.0 * $$sin(angle)));
        for (int i = 0; i < spaces; i += 1) {
            io::print(" ");
        }
        io::printn(word[(int)even]);
        even = !even;
    }
    free(word[0]);
    free(word[1]);
}

fn void main() {
    printCredits();
    draw();
}

En Chapel

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Chapel:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-03.
Updated to Chapel 2.3.0 on 2025-01-19.

Last modified 20250405T2002+0200.
*/

import IO;
import Math;

var word: [0 .. 1] string;

// `clear` clears the screen and moves the cursor to its home position,
// by printing ANSI codes.
proc clear() {
    write("\x1B[2J\x1B[H");
}

proc printCredits() {
    clear();
    writeln("Sine Wave\n");
    writeln("Original version in BASIC:");
    writeln("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n");
    writeln("This version in Chapel:");
    writeln("    Copyright (c) 2023, Marcos Cruz (programandala.net)");
    writeln("    SPDX-License-Identifier: Fair\n");
    writeln("Press Enter to start the program.");
    IO.readLine();
}

proc getWords() {
    const order = ("first", "second");
    clear();
    for w in 0 .. 1 {
        write("Enter the ", order[w], " word ");
        IO.readLine(word[w]);
        // N.B. The input includes the carriage return character.
    }
}

proc draw() {
    clear();
    var even = false;
    var angle = 0.0;
    while angle <= 40.0 {
        // N.B. `write` is used because the word has a trailing carriage return
        // character.
        write((26.0 + 25.0 * Math.sin(angle)):int * " ", word[even:int]);
        even = !even;
        angle += 0.25;
    }
}

printCredits();
getWords();
draw();

En Crystal

# Sine Wave

# Original version in BASIC:
#     Creative Computing (Morristown, New Jersey, USA), ca. 1980.

# This version in Crystal:
#     Copyright (c) 2023, Marcos Cruz (programandala.net)
#     SPDX-License-Identifier: Fair
#
# Written in 2023-09, 2023-11.
#
# Last modified: 20241213T2300+0100.

def clear_screen
  print "\e[0;0H\e[2J"
end

def print_credits
  puts "Sine Wave"
  puts
  puts "Original version in BASIC:"
  puts "    Creative computing (Morristown, New Jersey, USA), ca. 1980."
  puts
  puts "This version in Crystal:"
  puts "    Copyright (c) 2023, Marcos Cruz (programandala.net)"
  puts "    SPDX-License-Identifier: Fair"
  puts
  print "Press Enter to start the program. "
  gets
end

# Returns a string array containing 2 words typed by the user.
def words : Array(String)
  word = ["", ""]
  (0..1).each do |n|
    while word[n] == ""
      print "Enter the ", n == 0 ? "first" : "second", " word: "
      word[n] = gets.not_nil!
    end
  end
  word
end

# Returns the y position correspondent to the given angle.
def y(angle : Float) : Int
  (26 + 25 * Math.sin angle).to_i
end

# Draws the wave using the given array containing 2 strings.
def draw(word : Array(String))
  even = true
  angle = 0.0
  while angle <= 40
    print " " * y(angle), word[even ? 0 : 1], "\n"
    even = !even
    angle += 0.25
  end
end

clear_screen
print_credits
clear_screen
draw words

En D

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in D:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-03, 2023-09.

Last modified 20251219T2130+0100.
*/

module sine_wave;

// Erase the screen, reset the attributes and move the cursor to the home
// position.

void clear()
{
    import std.stdio : write;

    write("\033[2J\033[0m\033[H");
}

void printCredits()
{
    import std.stdio : readln;
    import std.stdio : writeln;

    clear();
    writeln("Sine Wave\n");
    writeln("Original version in BASIC:");
    writeln("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n");
    writeln("This version in D:");
    writeln("    Copyright (c) 2023, Marcos Cruz (programandala.net)");
    writeln("    SPDX-License-Identifier: Fair\n");
    writeln("Press Enter to start the program.");
    readln();
}

string[2] word; // user words

void getWords()
{
    import std.stdio : readln;
    import std.stdio : writef;
    import std.string : strip;

    clear();
    string[2] order = ["first", "second"];
    for (int i = 0; i < word.length; i++)
    {
        writef("Enter the %s word: ", order[i]);
        word[i] = strip(readln());
    }

}

void draw()
{
    import std.conv : to;
    import std.math : sin;
    import std.range : repeat;
    import std.stdio : write;
    import std.stdio : writeln;

    clear();
    bool even = false;
    double angle = 0.0;
    for (angle = 0.0; angle <= 40.0; angle += 0.25)
    {
        write(repeat(' ', to!int(26 + 25 * sin(angle))));
        writeln(word[to!int(even)]);
        even = !even;
    }
}

void main()
{
    printCredits();
    getWords();
    draw();
}

En FreeBASIC

/'

Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in FreeBASIC:
    Copyright (c) 2023, 2024, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-02, 2024-11.

Last modified 20250505T2350+0200.

'/

cls
print "Sine Wave"
print
print "Original version in BASIC:"
print tab(4);"Creative computing (Morristown, New Jersey, USA), ca. 1980."
print
print "This version in FreeBASIC:"
print tab(4);"Copyright (c) 2023, Marcos Cruz (programandala.net)"
print tab(4);"SPDX-License-Identifier: Fair"
print

print "Press any key to start the program."
sleep
do while inkey <> ""
loop

cls

dim word(0 to 1) as string
input "Enter the first word:  ",word(0)
input "Enter the second word: ",word(1)

cls

dim dot as integer = 0

for angle as single = 0 to 40 step .25
    print tab(int(26+25*sin(angle)));word(dot and 1)
    dot += 1
next angle

' vim: filetype=freebasic

En Go

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Go:
    Copyright (c) 2024, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written on 2024-12-28.

Last modified: 20250105T1150+0100.
*/

package main

import "fmt"
import "math"
import "strings"

func clearScreen() {

    fmt.Print("\x1B[0;0H\x1B[2J")

}

func input(prompt string) string {

    fmt.Print(prompt)
    var s = ""
    fmt.Scanf("%s", &s)
    return s

}

var word [2]string

// Ask the user to enter two words and store them.
func getWords() {

    var order = [2]string{"first", "second"}
    clearScreen()
    for n := 0; n <= 1; n++ {
        for word[n] == "" {
            word[n] = input(fmt.Sprintf("Enter the %v word: ", order[n]))
        }
    }

}

// Display the credits and wait for a keypress.
func printCredits() {

    fmt.Println("Sine Wave\n")
    fmt.Println("Original version in BASIC:")
    fmt.Println("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
    fmt.Println("This version in Go:")
    fmt.Println("    Copyright (c) 2024, Marcos Cruz (programandala.net)")
    fmt.Println("    SPDX-License-Identifier: Fair\n")
    input("Press Enter to start the program. ")

}

func draw() {

    var even = true
    for angle := 0.0; angle <= 40.0; angle += 0.25 {
        fmt.Print(strings.Repeat(" ", int(26+25*math.Sin(angle))))
        if even {
            fmt.Println(word[0])
        } else {
            fmt.Println(word[1])
        }
        even = !even
    }

}

func main() {

    clearScreen()
    printCredits()
    getWords()
    clearScreen()
    draw()

}

En Hare

// Sine Wave
//
// Original version in BASIC:
//      Creative Computing (Morristown, New Jersey, USA), ca. 1980.
//
// This version in Hare:
//      Copyright (c) 2024, 2025, Marcos Cruz (programandala.net)
//      SPDX-License-Identifier: Fair
//
// Written on 2024-12-15, 2025-02-12, 2025-02-15.
//
// Last modified: 20260213T1645+0100.

use bufio;
use encoding::utf8;
use fmt;
use io;
use math;
use os;
use strings;

fn clear_screen() void = {
        fmt::print("\x1B[0;0H\x1B[2J")!;
};

fn print_prompt(prompt: str = "") void = {
        fmt::print(prompt)!;
        bufio::flush(os::stdout)!;
};

fn accept_string(prompt: str = "") str = {
        print_prompt(prompt);
        const buffer = match (bufio::read_line(os::stdin)!) {
                case let buffer: []u8 =>
                        yield buffer;
                case =>
                        return "";
                };
        defer free(buffer);
        return strings::dup(strings::fromutf8(buffer)!)!;
};

fn press_enter(prompt: str = "") void = {
        free(accept_string(prompt));
};

fn get_words() [2]str = {
        clear_screen();

        let word: [2]str = ["", ""];
        let order: [2]str = ["first", "second"];

        for (let n = 0; n <= 1; n += 1) {
                for (word[n] == "") {
                        fmt::printfln("Enter the {} word: ", order[n])!;
                        word[n] = accept_string();
                };
        };

        return word;
};

fn print_credits() void = {
        clear_screen();
        fmt::println("Sine Wave\n")!;
        fmt::println("Original version in BASIC:")!;
        fmt::println("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")!;
        fmt::println("This version in Hare:")!;
        fmt::println("    Copyright (c) 2024, 2025, Marcos Cruz (programandala.net)")!;
        fmt::println("    SPDX-License-Identifier: Fair\n")!;
        press_enter("Press Enter to start the program. ");
};

fn bool_to_int(flag: bool) int = {
        return if (flag) 1 else 0;
};

fn draw(word: [2]str) void = {
        clear_screen();
        let even = false;
        for (let angle = 0.0; angle <= 40.0; angle += 0.25) {
                let spaces = (26.0 + math::floorf64(25.0 * math::sinf64(angle))): int;
                for (let i = 0; i < spaces; i += 1) {
                        fmt::print(' ')!;
                };
                fmt::println(word[bool_to_int(even)])!;
                even = !even;
        };
};

export fn main() void = {
        print_credits();
        draw(get_words());
};

En Icon

# Sine Wave
#
# Original version in BASIC:
#   Creative Computing (Morristown, New Jersey, USA), ca. 1980.
#
# This version in Icon:
#   Copyright (c) 2023, Marcos Cruz (programandala.net)
#   SPDX-License-Identifier: Fair
#
# Written in 2023-03-02/21.
#
# Last modified 20231103T2342+0100.

link iscreen # clear()

global word

procedure print_credits()
    write("Sine Wave\n")
    write("Original version in BASIC:")
    write("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
    write("This version in Icon:")
    write("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
    write("    SPDX-License-Identifier: Fair\n")
    write("Press Enter to start the program.")
    read()
end

procedure get_words()
    word := ["", ""]
    every w := (1 | 2) do {
        write("Enter the " || ["first", "second"][w] || " word ")
        word[w] := read()
    }
end

procedure draw()
    step := 2
    every angle := 0 to 4000 by 25 do
        write(repl(" ", 26 + 25 * sin(angle/100.0)), word[step := [2, 1][step]])
end

procedure main()
    clear()
    print_credits()
    clear()
    get_words()
    clear()
    draw()
end

En Janet

# Sine Wave

# Original version in BASIC:
#   Anonymous, 1978.
#   Creative Computing's BASIC Games.
#   - https://www.atariarchives.org/basicgames/showpage.php?page=146
#   - http://vintage-basic.net/games.html
#   - http://vintage-basic.net/bcg/sinewave.bas
#   - http://www.retroarchive.org/cpm/games/ccgames.zip

# This version in Janet:
#  Copyright (c) 2025, Marcos Cruz (programandala.net)
#  SPDX-License-Identifier: Fair
#
# Written on 2025-12-23.
#
# Last modified 20260215T1957+0100.

(defn move-cursor-home []
  (prin "\x1B[H"))

(defn clear-screen []
  (prin "\x1B[2J")
  (move-cursor-home))

(defn print-credits []
  (clear-screen)
  (print "Sine Wave\n")
  (print "Original version in BASIC:")
  (print "  Anonymous, 1978.")
  (print "  Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
  (print "This version in Janet:")
  (print "  Copyright (c) 2025, Marcos Cruz (programandala.net)")
  (print "  SPDX-License-Identifier: Fair\n")
  (prin "Press Enter to start the program. ")
  (getline))

(def word @["" ""])

(defn get-words []
  (def order @["first" "second"])
  (clear-screen)
  (for w 0 2
    (prin "Enter the " (get order w) " word: ")
    (put word w (string/trim (getline)))))

(defn boolean->integer [b]
  (if b 1 0))

(defn draw []
  (var even false)
  (loop [a :range [0 40.25 0.25]]
    (prin (string/repeat " " (math/floor (+ (* (math/sin a) 25) 26))))
    (print (get word (boolean->integer even)))
    (set even (not even))))

(defn main [& args]
  (clear-screen)
  (print-credits)
  (get-words)
  (print)
  (draw))

En Julia

# Sine Wave

# Original version in BASIC:
#     Creative Computing (Morristown, New Jersey, USA), ca. 1980.

# This version in Julia:
#     Copyright (c) 2023, 2024, Marcos Cruz (programandala.net)
#     SPDX-License-Identifier: Fair

# Last modified: 20250319T1933+0100.

word = ["", ""]
order = ["first", "second"]

function clear()
    print("\e[0;0H\e[2J")
end

function print_credits()
    clear()
    println("Sine Wave\n")
    println("Original version in BASIC:")
    println("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
    println("This version in Julia:")
    println("    Copyright (c) 2023, 2024, Marcos Cruz (programandala.net)")
    println("    SPDX-License-Identifier: Fair\n")
    println("Press Enter to start the program.")
    _ = readline()
end

function get_words()
    global order
    global word
    clear()
    for n = 1 : 2
        print(string("\nEnter the ", order[n], " word "))
        word[n] = readline()
    end
end

function draw()
    global word
    clear()
    even = false
    for angle = 0 : 0.25 : 40
        print(repeat(" ", Int(floor(26 + 25 * sin(angle)))))
        println(word[Int(even) + 1])
        even = !even
    end
end

print_credits()
get_words()
draw()

En Kotlin

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Kotlin:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-08, 2023-09, 2023-10.

Last modified: 20250419T2224+0200.
*/

fun home() {
    print("\u001B\u005B\u0048")
}

fun clear() {
    print("\u001B\u005B\u0032\u004A")
    home()
}

val order = arrayOf("first", "second")

var word = arrayOfNulls<String>(2)

fun getWords() {
    for (w in word.indices) {
        print("Enter the ${order[w]} word: ")
        word[w] = readln()
    }
}

fun showCredits() {
    println("Sine Wave\n")
    println("Original version in BASIC:")
    println("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
    println("This version in Kotlin:")
    println("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
    println("    SPDX-License-Identifier: Fair\n")
    println("Press Enter to start the program.")
    readln()
}

fun draw() {
    var even = true
    var angle = 0.0
    while (angle <= 40) {
        print(" ".repeat((26 + 25 * kotlin.math.sin(angle)).toInt()))
        println(word[if (even) 0 else 1])
        even = ! even
        angle += 0.25
    }
}

fun main() {
    clear()
    showCredits()
    clear()
    getWords()
    clear()
    draw()
}

En Lua

--[[
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Lua:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Last modified 20231103T2310+0100.
]]

function tab(spaces)
    for i = 1, spaces do
        io.write(" ")
    end
end

os.execute("clear")
print("Sine Wave\n")
print("Original version in BASIC:")
print("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
print("This version in Lua:")
print("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
print("    SPDX-License-Identifier: Fair\n")
print("Press Enter to start the program.")
io.read()
os.execute("clear")

word = { "", "" }
io.write("Enter the first word:  ")
word[0] = io.read()
io.write("Enter the second word: ")
word[1] = io.read()
os.execute("clear")

step = 0
for t = 0, 40 , .25 do
    tab(26 + 25 * math.sin(t))
    print(word[step])
    step = (step == 1) and 0 or 1
end

En Nelua

--[[
Sine Wave

Original version in BASIC:
  Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Nelua:
  Copyright (c) 2023, Marcos Cruz (programandala.net)
  SPDX-License-Identifier: Fair

Last modified 20231103T2257+0100.
]]

require 'io'
require 'math'
require 'os'

local function tab(spaces: float64)
  for i = 1, spaces do
    io.write(" ")
  end
end

os.execute("clear")
print("Sine Wave\n")
print("Original version in BASIC:")
print("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
print("This version in Nelua:")
print("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
print("    SPDX-License-Identifier: Fair\n")
print("Press Enter to start the program.")
io.read()
os.execute("clear")

-- local word = {"", ""} -- XXX TODO Not supported yet by Nelua
io.write("Enter the first word:  ")
local word0 = io.read()
io.write("Enter the second word: ")
local word1 = io.read()
os.execute("clear")

local step = 0
for t = 0.0, 40.0, 0.25 do
  tab(26 + 25 * math.sin(t))
  -- print(word[step]) -- XXX TODO Not supported yet by Nelua
  if step == 0 then
    print(word0)
  else
    print(word1)
  end
  step = (step == 1) and 0 or 1
end

En Nim

#[
Sine Wave

Original version in BASIC:
  Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Nim:
  Copyright (c) 2023, Marcos Cruz (programandala.net)
  SPDX-License-Identifier: Fair

Written in 2023-01, 2023-08, 2023-09.

Last modified: 20250405T0304+0200.
]#

import std/math
import std/strutils
import std/terminal

proc cursorHome() =
  setCursorPos 0, 0

proc clearScreen() =
  eraseScreen()
  cursorHome()

proc showCredits() =
  echo "Sine Wave\n"
  echo "Original version in BASIC:"
  echo "    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n"
  echo "This version in Nim:"
  echo "    Copyright (c) 2023, Marcos Cruz (programandala.net)"
  echo "    SPDX-License-Identifier: Fair\n"
  echo "Press any key to start the program."
  discard getch()

var word: array[2, string] = ["", ""]

proc getWords() =
  for i in 0 .. 1:
    while word[i] == "":
      write(stdout, "Enter the ", if (i == 0 ): "first" else: "second", " word: ")
      word[i] = strip(readLine(stdin))

proc draw() =
  var even = false
  var angle = 0.0
  while angle <= 40.0:
    write(stdout, repeat(' ', int(26 + 25 * sin(angle))))
    echo word[ord(even)]
    even = not even
    angle += 0.25

clearScreen()
showCredits()
clearScreen()
getWords()
clearScreen()
draw()

En Odin

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Odin:
    Copyright (c) 2023, 2025, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-02/03, 2023-08/09, 2023-11, 2023-12, 2025-02.

Last modified: 20250226T2323+0100.
*/

package sine_wave

import "../lib/anodino/src/read"
import "../lib/anodino/src/term"
import "core:fmt"
import "core:math"
import "core:strings"

word : [2]string = {"", ""}

// Ask the user to enter two words and store them.
//
get_words :: proc() {

    order : [2]string = {"first", "second"}
    term.clear_screen()
    for n in 0 ..= 1 {
        for word[n] == "" {
            word[n] = read.a_prompted_string(fmt.tprintf("Enter the %v word: ", order[n])) or_else ""
        }
    }

}

// Display the credits and wait for a keypress.
//
print_credits :: proc() {

    fmt.println("Sine Wave\n")
    fmt.println("Original version in BASIC:")
    fmt.println("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
    fmt.println("This version in Odin:")
    fmt.println("    Copyright (c) 2023, 2025, Marcos Cruz (programandala.net)")
    fmt.println("    SPDX-License-Identifier: Fair\n")
    read.a_prompted_string("Press Enter to start the program. ")

}

draw :: proc() {

    even := false
    for angle := 0.0; angle <= 40.0; angle += 0.25 {
        margin := strings.repeat(" ", int(26 + 25 * math.sin(angle)))
        defer delete(margin)
        fmt.print(margin)
        fmt.println(word[int(even)])
        even = ! even
    }

}

delete_words :: proc() {

    delete(word[0])
    delete(word[1])

}

main :: proc() {

    term.clear_screen()
    print_credits()
    get_words()
    term.clear_screen()
    draw()
    delete_words()

}

En Pike

#! /usr/bin/env pike

// Sine Wave

// Original version in BASIC:
//  Creative Computing (Morristown, New Jersey, USA), ca. 1980.

// This version in Pike:
//  Copyright (c) 2024, Marcos Cruz (programandala.net)
//  SPDX-License-Identifier: Fair
//
// Written on 2024-12-17.
//
// Last modified: 20250313T0101+0100.

void clear_screen() {
    write("\x1B[0;0H\x1B[2J");
}

array(string) word = ({"", ""});

void set_words() {
    clear_screen();
    array(string) order = ({"first", "second"});
    for (int n = 0; n <= 1; n += 1) {
        while (word[n] == "") {
            write("Enter the " + order[n] + " word: ");
            word[n] = Stdio.stdin->gets();
        }
    }
}

void print_credits() {
    clear_screen();
    write("Sine Wave\n\n");
    write("Original version in BASIC:\n");
    write("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n\n");
    write("This version in Pike:\n");
    write("    Copyright (c) 2024, Marcos Cruz (programandala.net)\n");
    write("    SPDX-License-Identifier: Fair\n\n");
    write("Press Enter to start the program. ");
    Stdio.stdin->gets();
}

void draw() {
    clear_screen();
    bool even = false;
    for (float angle = 0.0; angle <= 40.0; angle += 0.25) {
        int spaces = (int) (26.0 + floor(25.0 * sin(angle)));
        for (int i = 0; i < spaces; i += 1)
            write(" ");
        write(word[even] + "\n");
        even = !even;
    }
}

void main() {
    print_credits();
    set_words();
    draw();
}

En Python

# Sine Wave

# Original version in BASIC:
#     Creative Computing (Morristown, New Jersey, USA), ca. 1980.

# This version in Python:
#     Copyright (c) 2024, Marcos Cruz (programandala.net)
#     SPDX-License-Identifier: Fair
#
# Written on 2024-10-29.
#
# Last modified: 20241203T2231+0100.

import math
import os

word = ["", ""]
order = ["first", "second"]

def clear():
    if os.name == 'nt':
        _ = os.system('cls')
    else:
        # on mac and linux, `os.name` is 'posix'
        _ = os.system('clear')

def print_credits():
    clear()
    print("Sine Wave\n")
    print("Original version in BASIC:")
    print("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
    print("This version in Julia:")
    print("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
    print("    SPDX-License-Identifier: Fair\n")
    _ = input ("Press Enter to start the program.")

def get_words():
    clear()
    for n in range(0, 2):
        word[n] = input("Enter the " + order[n] + " word: ")

def draw():
    clear()
    even = False
    angle = 0
    while angle <= 40:
        print(" " * int(26 + 25 * math.sin(angle)), end = "")
        print(word[int(even)])
        even = not even
        angle += 0.25

print_credits()
get_words()
draw()

En Racket

#! /usr/bin/env racket

#|

Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Racket:
    Copyright (c) 2023, 2024, 2026, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-08, 2023-09, 2024-12, 2026-01.

Last modified 20260106T0922+0100.

|#

#lang racket

(define (move-cursor-home)
    (display "\e[H"))

(define (clear-screen)
    (display "\e[2J")
    (move-cursor-home))

(define (display-credits)
    (clear-screen)
    (displayln "Sine Wave\n")
    (displayln "Original version in BASIC:")
    (displayln "    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
    (displayln "This version in Racket:")
    (displayln "    Copyright (c) 2023, 2024, Marcos Cruz (programandala.net)")
    (displayln "    SPDX-License-Identifier: Fair\n")
    (display "Press Enter to start the program. ")
    (void (read-line)))

(define word (vector "" ""))

(define order (vector "first" "second"))

(define (get-words)
    (clear-screen)
    (for ([w (in-range 0 2)])
            (printf "Enter the ~a word: " (vector-ref order w))
            (vector-set! word w (read-line))))

(define (boolean->integer b)
    (count values (list b)))

(define (draw)
    (clear-screen)
    (define even #f)
    (for ([a (in-range 0.0 40.25 0.25)])
        (display (make-string (exact-floor (+ (* (sin a) 25) 26)) #\space))
        (displayln (vector-ref word (boolean->integer even)))
        (set! even (not even))))

(display-credits)
(get-words)
(displayln "")
(draw)

En Raku

# Sine Wave

# Original version in BASIC:
#   Creative Computing (Morristown, New Jersey, USA), ca. 1980.

# This version in Raku:
#   Copyright (c) 2024, Marcos Cruz (programandala.net)
#   SPDX-License-Identifier: Fair

# Written on 2024-12-03.

# Last modified: 20241203T1832+0100.

sub clear_screen {

    print "\e[0;0H\e[2J";

}

my @word = '', '';

sub get_words {

    my @order = 'first', 'second';
    for 0, 1 -> $n {
        while @word[$n] == '' {
            @word[$n] = prompt "Enter the @order[$n] word: ";
        }
    }

}

sub print_credits {

    put "Sine Wave\n";
    put 'Original version in BASIC:';
    put "    Creative Computing (Morristown, New Jersey, USA, ca. 1980.\n";
    put 'This version in Raku:';
    put '    Copyright (c 2024, Marcos Cruz (programandala.net)';
    put "    SPDX-License-Identifier: Fair\n";
    prompt 'Press Enter to start the program. ';

}

sub draw {

    my $even = False;
    loop (my $angle = 0.0; $angle <= 40.0; $angle += 0.25) {
        print ' ' x (26 + 25 * sin($angle)).Int;
        put @word[$even.Int];
        $even = not $even;
    }

}

clear_screen;
print_credits;
clear_screen;
get_words;
clear_screen;
draw;

En Ring

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Ring:
    Copyright (c) 2023, 2024, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Last modified 20250731T1954+0200.
*/

// global variables
word1 = ""
word2 = ""

func showCredits
    system("clear")
    put "Sine Wave" + nl + nl
    put "Original version in BASIC:" + nl
    put "    Creative Computing (Morristown, New Jersey, USA), ca. 1980." + nl + nl
    put "This version in Ring:" + nl
    put "    Copyright (c) 2023, 2024, Marcos Cruz (programandala.net)" + nl
    put "    SPDX-License-Identifier: Fair" + nl + nl
    put "Press Enter to start the program." + nl
    getChar()
end

func getWords
    system("clear")
    put "Enter the first word  : "
    get word1
    put "Enter the second word : "
    get word2
    put "Press any key to start. "
    getchar()
end

func draw
    even = false
    for angle = 0 to 40 step 0.25
        put copy(" ", 26 + 25 * sin(angle))
        if even
            put word1 + nl
        else
            put word2 + nl
        end
        even = not even
    next
end

func main
    showCredits()
    getWords()
    draw()
end

En Rust

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Rust:
    Copyright (c) 2024, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2024-12-27/28.

Last modified: 20241228T2054+0100.
*/

use std::io;
use std::io::Write;

fn move_cursor_home() {

    print!("\x1B[H")

}

fn erase_screen() {

    print!("\x1B[2J")

}

fn clear_screen() {

    erase_screen();
    move_cursor_home();

}

fn read_string(prompt: &str) -> String {

    print!("{prompt}");
    io::stdout().flush().unwrap(); // print pending text

    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("");
    return input;

}

// Display the credits and wait for a keypress.
//
fn print_credits() {

    println!("Sine Wave\n");
    println!("Original version in BASIC:");
    println!("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n");
    println!("This version in Rust:");
    println!("    Copyright (c) 2024, Marcos Cruz (programandala.net)");
    println!("    SPDX-License-Identifier: Fair\n");
    let _ = read_string("Press Enter to start the program. ");

}

fn draw() {

    let mut even = false;
    let mut angle = 0.0;

    const ORDER: [&str; 2]  = ["first", "second"];
    let mut word: [String; 2] = ["".into(), "".into()];

    for n in 0 ..= 1 {
        while word[n].is_empty() {
            let prompt = format!("Enter the {} word: ", ORDER[n]);
            word[n] = read_string(&prompt).trim().to_string();
        }
    }

    while angle <= 40.0 {
        let margin = 26 + f64::floor(25.0 * f64::sin(angle)) as isize;
        for _ in 0 .. margin {
            print!(" ");
        }
        println!("{}", word[even as usize]);
        even = ! even;
        angle += 0.25;
    }

}

fn main() {

    clear_screen();
    print_credits();
    clear_screen();
    draw();

}

En Scala

/*
Sine Wave

Original version in BASIC:
  Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Scala:
  Copyright (c) 2023, Marcos Cruz (programandala.net)
  SPDX-License-Identifier: Fair

Written in 2023-08, 2023-09.

Last modified: 20231103T2352+0100.
*/

def home() =
  print("\u001B[H")

def clear() =
  print("\u001B[2J")
  home()

val order = Array("first", "second")

var word = Array("", "")

def getWords() =
  clear()
  for w <- Seq(0, 1) do
    word(w) = io.StdIn.readLine(s"Enter the ${order(w)} word: ")

def showCredits() =
  clear()
  println("Sine Wave\n")
  println("Original version in BASIC:")
  println("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
  println("This version in Scala:")
  println("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
  println("    SPDX-License-Identifier: Fair\n")
  println("Press Enter to start the program.")
  io.StdIn.readLine("")

def draw() =
  clear()
  var even = true
  var angle = 0.0
  while angle <= 40 do
    print(" " * (26 + 25 * math.sin(angle)).toInt)
    println(word(if even then 0 else 1))
    even = !even
    angle += 0.25

@main def main() =
  showCredits()
  getWords()
  draw()

En Scheme

; Sine Wave

; Original version in BASIC:
;   Anonymous, 1978.
;   Creative Computing's BASIC Games.
;   - https://www.atariarchives.org/basicgames/showpage.php?page=146
;   - http://vintage-basic.net/games.html
;   - http://vintage-basic.net/bcg/sinewave.bas
;   - http://www.retroarchive.org/cpm/games/ccgames.zip

; This version in Scheme (Bigloo):
;   Copyright (c) 2025, Marcos Cruz (programandala.net)
;   SPDX-License-Identifier: Fair
;
; Written in 2025-12-02/03.
;
; Last modified 20251223T1811+0100.

(module sine-wave)

(define (move-cursor-home)
    (display "\x1B[H"))

(define (clear-screen)
    (display "\x1B[2J")
    (move-cursor-home))

(define (display-credits)
    (clear-screen)
    (display "Sine Wave\n\n")
    (display "Original version in BASIC:\n")
    (display "  Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n\n")
    (display "This version in Scheme (Bigloo):\n")
    (display "  Copyright (c) 2025, Marcos Cruz (programandala.net)\n")
    (display "  SPDX-License-Identifier: Fair\n\n")
    (display "Press Enter to start the program. ")
    (read-line))

(define word (vector "" ""))

(define (get-words)
    (define order (vector "first" "second"))
    (clear-screen)
    (do ((w 0 (+ w 1))) ((>= w 2))
        (display (format "Enter the ~a word: " (vector-ref order w)))
        (vector-set! word w (read-line))))

(define (boolean->integer b)
  (cadr (assq b '((#t 1) (#f 0)))))

(define (exact-floor n)
    (inexact->exact (truncate n)))

(define (draw)
    (let ((even #f))
        (do ((a 0.0 (+ a 0.25))) ((>= a 40.25))
            (display (make-string (exact-floor (+ (* (sin a) 25) 26)) #\space))
            (display (vector-ref word (boolean->integer even)))
            (newline)
            (set! even (not even)))))

(clear-screen)
(display-credits)
(get-words)
(newline)
(draw)

En Swift

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Swift:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written on 2023-11-03.

Last modified: 20231103T0142+0100.
*/

import Foundation // sin()

// Move the cursor to the top left position of the terminal.
func home() {
    print("\u{001B}[H", terminator: "")
}

// Clear the terminal and move the cursor to the top left position.
func clear() {
    print("\u{001B}[2J", terminator: "")
    home()
}

var word = ["", ""]

// Ask the user to enter a word and return it.
func getWord(number: Int) -> String {
    let order = ["first", "second"]
    word[number] = ""
    while word[number] == "" {
        print("Enter the \(order[number]) word: ", terminator: "")
        word[number] = readLine() ?? ""
    }
    return word[number]
}

// Ask the user to enter two words and store them.
func getWords() {
    clear()
    for n in 0 ... 1 {
        word[n] = getWord(number: n)
    }
}

// Clear the screen, display the credits and wait for a keypress.
func printCredits() {
    clear()
    print("Sine Wave\n")
    print("Original version in BASIC:")
    print("    Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
    print("This version in Swift:")
    print("    Copyright (c) 2023, Marcos Cruz (programandala.net)")
    print("    SPDX-License-Identifier: Fair\n")
    print("Press Enter to start the program.")
    let _ = readLine()
}

func draw() {
    clear()
    var even = true
    var angle = 0.0
    while angle <= 40.0 {
        print(String(repeating: " ", count: Int(26 + 25 * sin(angle))), terminator: "")
        print(word[even ? 0 : 1])
        even = !even
        angle += 0.25
    }
}

printCredits()
getWords()
draw()

En V

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in V:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Last modified 20231103T2127+0100.
*/
import math
import os
import term

fn main() {
    term.clear()
    println('Sine Wave\n')
    println('Original version in BASIC:')
    println('    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n')
    println('This version in V:')
    println('    Copyright (c) 2023, Marcos Cruz (programandala.net)')
    println('    SPDX-License-Identifier: Fair\n')
    println('Press Enter to start the program.')
    os.input('')
    term.clear()

    mut word := ['', '']
    word[0] = os.input('Enter the first word:  ')
    word[1] = os.input('Enter the second word: ')
    term.clear()

    mut even := false
    for angle := 0.0; angle <= 40.0; angle += 0.25 {
        print(' '.repeat(int(26 + 25 * math.sin(angle))))
        println(word[int(even)])
        even = !even
    }
}

En Vala

/*
Sine Wave

Original version in BASIC:
    Creative Computing (Morristown, New Jersey, USA), ca. 1980.

This version in Vala:
    Copyright (c) 2023, Marcos Cruz (programandala.net)
    SPDX-License-Identifier: Fair

Written in 2023-08, 2023-09.

Last modified 20231103T2132+0100.
*/

using GLib; // Math needed

// Erase the screen, reset the attributes and move the cursor to the home position.
void clear() {
    print("\033[2J\033[0m\033[H");
}

void print_credits() {
    print("Sine Wave\n\n");
    print("Original version in BASIC:\n");
    print("    Creative computing (Morristown, New Jersey, USA), ca. 1980.\n\n");
    print("This version in Vala:\n");
    print("    Copyright (c) 2023, Marcos Cruz (programandala.net)\n");
    print("    SPDX-License-Identifier: Fair\n\n");
    print("Press Enter to start the program.\n");
    stdin.read_line();
}

string word[2]; // user words

void get_words() {
    string order[2] = {"first", "second"};
    for (int i = 0; i < word.length; i++) {
        print(@"Enter the $(order[i]) word: ");
        word[i] = stdin.read_line();
    }

}

string repeat_char(char c, int times) {
    string s = "";
    for (int i = 0; i < times; i++) {
        s += c.to_string();
    }
    return s;
}

void draw() {
    bool even = false;
    double angle = 0.0;
    for (angle = 0.0; angle <= 40.0; angle += 0.25) {
        print(repeat_char(' ', (int) (26 + 25 * Math.sin(angle))));
        stdout.printf("%s\n", word[(int) even]);
        even = !even;
    }
}

void main() {
    clear();
    print_credits();
    clear();
    get_words();
    clear();
    draw();
}

Rilataj paĝoj

Basics off
Metaprojekto pri la projektoj «Basics of…».
Basics off
Metaprojekto pri la projektoj «Basics of…».

Eksteraj rilataj ligiloj