3D Plot
Priskribo de la ĉi-paĝa enhavo
Konvertado de 3D Plot al pluri program-lingvoj.
3D Plot ofte estas la dua programo konvertita en la projektoj Basics off.
Ĉi-tiu programo estas konvertita en 28 program-lingvojn.
Originalo
Origin of 3d_plot.bas:
3-D Plot (by Mark Bramhall), 1978.
Creative Computing's BASIC Games.
- http://vintage-basic.net/games.html
- http://vintage-basic.net/bcg/3dplot.bas
- https://www.atariarchives.org/basicgames/showpage.php?page=167
1 PRINT TAB(32);"3D PLOT"
2 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
3 PRINT:PRINT:PRINT
5 DEF FNA(Z)=30*EXP(-Z*Z/100)
100 PRINT
110 FOR X=-30 TO 30 STEP 1.5
120 L=0
130 Y1=5*INT(SQR(900-X*X)/5)
140 FOR Y=Y1 TO -Y1 STEP -5
150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*Y)
160 IF Z<=L THEN 190
170 L=Z
180 PRINT TAB(Z);"*";
190 NEXT Y
200 PRINT
210 NEXT X
300 END
Eliraĵo
*
* * *
* * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * *
* * * * * * ** * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * ** *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * ** *
* * * * * * * * *
* * * * * * * * * *
* * * * * * ** * * *
* * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * *
* * *
*
En Ada
-- 3D Plot
--
-- Original version in BASIC:
-- 3-D Plot (by Mark Bramhall), 1978.
-- Creative Computing's BASIC Games.
-- - http://vintage-basic.net/games.html
-- - http://vintage-basic.net/bcg/3dplot.bas
-- - https://www.atariarchives.org/basicgames/showpage.php?page=167
--
-- This version in Ada:
-- Copyright (c) 2025, Marcos Cruz (programandala.net);
-- SPDX-License-Identifier: Fair
--
-- Written on 2025-03-19, 2025-03-29.
--
-- Last modified: 20251204T2259+0100.
with ada.numerics;
use ada.numerics;
with ada.numerics.elementary_functions;
use ada.numerics.elementary_functions;
with ada.text_io;
use ada.text_io;
procedure plot_3d is
procedure move_cursor_home is
escape : constant character := character'val (16#1B#); -- 0x1B
begin
put (escape & "[H");
end move_cursor_home;
procedure erase_screen is
escape : constant character := character'val (16#1B#); -- 0x1B
begin
put (escape & "[2J");
end erase_screen;
procedure clear_screen is
begin
erase_screen;
move_cursor_home;
end clear_screen;
procedure wait_for_keypress (expected_char : character) is
pressed_char : character;
is_a_char_available : boolean;
begin
loop
ada.text_io.get_immediate (pressed_char, is_a_char_available);
if (pressed_char = expected_char) then
exit;
end if;
end loop;
end wait_for_keypress;
procedure print_credits is
begin
put_line ("3D Plot");
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_keypress (character'val (16#0a#)); -- 0x0a, the enter character
end print_credits;
function a (z : float) return float is
begin
return 30.0 * exp (-z * z / 100.0);
end a;
procedure draw is
space : constant character := ' ';
dot : constant character := '*';
width : constant integer := 56;
l : integer;
z : integer;
y : integer;
y1 : integer;
line : array (0 .. width - 1) of character;
x : float := -30.0;
begin
while x <= 30.0 loop
for c in 0 .. width - 1 loop
line (c) := space;
end loop;
l := 0;
y1 :=
5
* integer (
float'truncation (sqrt (900.0 - x * x) / 5.0)
);
y := y1;
while y >= -y1 loop
z := integer (
float'truncation (
25.0
+ a (sqrt (x * x + float (y * y)))
- 0.7 * float (y)
)
);
if z > l then
l := z;
line (z) := dot;
end if;
y := y - 5;
end loop;
for pos in 0 .. width - 1 loop
put (line (pos));
end loop;
new_line;
x := x + 1.5;
end loop;
end draw;
begin
clear_screen;
print_credits;
clear_screen;
draw;
end plot_3d;
En Arturo
; 3D Plot
; Original version in BASIC:
; 3-D Plot (by Mark Bramhall), 1978.
; Creative Computing's BASIC Games.
; - http://vintage-basic.net/games.html
; - http://vintage-basic.net/bcg/3dplot.bas
; - https://www.atariarchives.org/basicgames/showpage.php?page=167
; This version in Arturo:
; Copyright (c) 2023, Marcos Cruz (programandala.net)
; SPDX-License-Identifier: Fair
;
; Written on 2023-10-17.
;
; Last modified: 20251205T0043+0100.
SPACE: ` `
DOT: `*`
WIDTH: 56
; Display the credits and wait for a keypress.
printCredits: function [] [
print "3D Plot\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."
]
a: function [z] [
mul 30 exp div (mul neg z z) 100
]
draw: function [] [
x: neg 30
while [not? greater? x 30] [
line: array.of: WIDTH SPACE
l: 0
y1: mul 5 floor div sqrt(sub 900 (mul x x)) 5
loop y1 .. (neg y1) .step: 5 'y [
z: floor (add 25 sub a(sqrt(add mul x x mul y y)) (mul 0.7 y))
if greater? z l [
l: z
line\[z]: DOT
]
] ; y loop
loop 0 .. (sub WIDTH 1) 'pos [
prints line\[pos]
]
print ""
add 'x 1.5
] ; x loop
]
clear
printCredits
clear
draw
En C#
// 3D Plot
// Original version in BASIC, "3D Plot":
// 3-D Plot (by Mark Bramhall), 1978.
// Creative Computing's BASIC Games.
// - http://vintage-basic.net/games.html
// - http://vintage-basic.net/bcg/3dplot.bas
// - https://www.atariarchives.org/basicgames/showpage.php?page=167
// This version in C#:
// Copyright (c) 2024, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2024-12-20.
//
// Last modified: 20251205T1528+0100.
using System;
class D3Plot
{
static void PrintCredits()
{
Console.WriteLine("3D Plot\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 any key to start. ");
Console.ReadKey();
}
static double A(double z)
{
return 30 * Math.Exp(-z * z / 100);
}
static void Draw()
{
const int WIDTH = 56;
const char SPACE = ' ';
const char DOT = '*';
int l = 0;
int z = 0;
int y = 0;
int y1 = 0;
char[] line = new char[WIDTH];
double x = -30.0;
while (x <= 30.0)
{
for (int i = 0; i < WIDTH; i++)
{
line[i] = SPACE;
}
l = 0;
y1 = 5 * (int)(Math.Sqrt(900 - x * x) / 5);
y = y1;
while (y >= -y1)
{
z = (int)(25 + A(Math.Sqrt(x * x + (double)(y * y))) - 0.7 * y);
if (z > l)
{
l = z;
line[z] = DOT;
};
y += -5;
} // y loop
foreach (char c in line)
{
Console.Write(c);
}
Console.WriteLine();
x += 1.5;
} // x loop
}
static void Main()
{
Console.Clear();
PrintCredits();
Console.Clear();
Draw();
}
}
En C3
// 3D Plot
// 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: 20250307T1349+0100.
import std::io;
const SPACE = " ";
const DOT = "*";
const WIDTH = 56;
fn void clearScreen() {
io::printn("\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 void printCredits() {
io::printn("3D Plot\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. ");
}
fn double a(double z) {
return 30.0 * $$exp(-z * z / 100.0);
}
fn void draw() {
int l = 0;
int z = 0;
int y1 = 0;
String[WIDTH] line = {};
for (double x = -30.0; x <= 30.0; x += 1.5) {
for (int i = 0; i < WIDTH; i += 1) {
line[i] = SPACE;
}
l = 0;
y1 = 5 * (int)($$sqrt(900.0 - x * x) / 5.0);
for (int y = y1; y >= -y1; y += -5) {
z = (int)(25.0 + a($$sqrt(x * x + (double)(y * y))) - 0.7 * (double)y);
if (z > l) {
l = z;
line[z] = DOT;
}
} // y loop
for (int pos = 0; pos < WIDTH; pos += 1) {
io::print(line[pos]);
}
io::printn();
} // x loop
}
fn void main() {
clearScreen();
printCredits();
clearScreen();
draw();
}
En Chapel
/*
3D Plot
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Chapel:
Copyright (c) 2025, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2025-04-04.
Last modified 20250405T2002+0200.
*/
import IO;
import Math;
const space = " ";
const dot = "*";
const width = 56;
// Erase the screen, reset the attributes and move the cursor to the home
// position.
proc clear() {
write("\x1B[2J\x1B[0m\x1B[H");
}
// Clear the screen, display the credits and wait for a keypress.
proc printCredits() {
clear();
writeln("3D Plot\n");
writeln("Original version in BASIC:");
writeln(" Creative computing (Morristown, New Jersey, USA), ca. 1980.\n");
writeln("This version in Chapel:");
writeln(" Copyright (c) 2025, Marcos Cruz (programandala.net)");
writeln(" SPDX-License-Identifier: Fair\n");
writeln("Press Enter to start the program.");
IO.readLine();
}
proc a(z: real): real {
return 30 * Math.exp(-z * z / 100);
}
proc draw() {
var l: int = 0;
var z: int = 0;
var y1: int = 0;
var line: [0 ..< width] string;
clear();
var x: real = -30.0;
while x <= 30.0 {
for pos in 0 ..< width {
line[pos] = space;
}
l = 0;
y1 = 5 * (sqrt(900 - x * x) / 5): int;
var y: int = y1;
while y >= -y1 {
z = (25 + a(sqrt(x * x + (y * y): real)) - 0.7 * (y): real): int;
if z > l {
l = z;
line[z] = dot;
}
y += -5;
} // y loop
for pos in 0 ..< width {
write(line[pos]);
}
writeln("");
x += 1.5;
} // x loop
}
proc main() {
printCredits();
draw();
}
En Crystal
# 3D Plot
# 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 on 2023-09, 2023-11.
#
# Last modified: 20231104T0055+0100.
SPACE = ' '
DOT = '*'
WIDTH = 56
def clear
print "\e[0;0H\e[2J"
end
def print_credits
puts "3D Plot\n"
puts "Original version in BASIC:"
puts " Creative computing (Morristown, New Jersey, USA), ca. 1980.\n"
puts "This version in Crystal:"
puts " Copyright (c) 2023, Marcos Cruz (programandala.net)"
puts " SPDX-License-Identifier: Fair\n"
puts "Press Enter to start the program."
gets
end
def a(z)
return 30 * Math.exp(-z * z / 100)
end
def draw
x = -30.0
while x <= 30
c = 0
line = Array.new WIDTH, SPACE
l = 0
y1 = 5 * (Math.sqrt(900 - x * x) / 5).to_i
y = y1
while y >= -y1
z = (25 + a(Math.sqrt(x * x + y * y)) - 0.7 * y).to_i
if z > l
l = z
line[z] = DOT
end
y += -5
end
c = 0
line.each do |item|
print item
end
puts
x += 1.5
end
end
clear
print_credits
clear
draw
En D
/*
3D Plot
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-25/26.
Last modified 20251220T0654+0100.
*/
module three_d_plot;
/// 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");
}
/// Clear the screen, display the credits and wait for a keypress.
void printCredits()
{
import std.stdio : readln;
import std.stdio : writeln;
clear();
writeln("3D Plot\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();
}
float a(float z)
{
import std.math : exp;
return 30 * exp(-z * z / 100);
}
void draw()
{
import std.stdio : write;
import std.stdio : writeln;
import std.math : sqrt;
enum char dot = '*';
enum char space = ' ';
enum int width = 56;
int l = 0;
int z = 0;
int y1 = 0;
char[width] line;
clear();
for (float x = -30.0; x <= 30.0; x += 1.5)
{
for (int pos = 0; pos<width; pos++)
{
line[pos] = space;
}
l = 0;
y1 = 5 * cast(int)(sqrt(900 - x * x) / 5);
for (int y = y1; y >= -y1; y += -5)
{
z = cast(int)(25 + a(sqrt(x * x + cast(float)(y * y))) - 0.7 * cast(float)(y));
if (z > l)
{
l = z;
line[z] = dot;
}
} // y loop
for (int pos = 0; pos<width; pos++)
{
write(line[pos]);
}
writeln();
} // x loop
}
void main()
{
printCredits();
draw();
}
En F#
// 3D Plot
// Original version in BASIC, "3D Plot":
// Creative Computing (Morristown, New Jersey, USA), ca. 1980.
// This version in F# 5.0:
// Copyright (c) 2024, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2024-12-20.
//
// Last modified: 20241231T1245+0100.
open System
let PrintCredits() =
printfn "3D Plot\n"
printfn "Original version in BASIC:"
printfn " Creative computing (Morristown, New Jersey, USA), ca. 1980.\n"
printfn "This version in F# 5.0:"
printfn " Copyright (c) 2024, Marcos Cruz (programandala.net)"
printfn " SPDX-License-Identifier: Fair\n"
printf "Press any key to start. "
Console.ReadKey() |> ignore
let A z =
30.0 * Math.Exp(-z * z / 100.0)
let Draw() =
let WIDTH = 56
let SPACE = ' '
let DOT = '*'
let mutable l = 0
let mutable z = 0
let mutable y = 0
let mutable y1 = 0
let mutable line : char array = Array.zeroCreate WIDTH
let mutable output = new String(line)
let mutable x = -30.0
while x <= 30.0 do
for i=0 to WIDTH-1 do
line.[i] <- SPACE
l <- 0
y1 <- 5 * int (Math.Sqrt(900.0 - x * x) / 5.0)
y <- y1
while y >= -y1 do
z <- int (25.0 + A(Math.Sqrt(x * x + double (y * y))) - 0.7 * double y)
if z > l then
l <- z
line.[z] <- DOT
y <- y + -5
let output = String(line)
printfn "%s" output
x <- x + 1.5
[<EntryPoint>]
let main argv =
Console.Clear()
PrintCredits()
Console.Clear()
Draw()
0 // integer exit code
// vim: filetype=fsharp
En FreeBASIC
/'
3D Plot
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in FreeBASIC:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2024-11-20.
Last modified: 20241120T2343+0100.
'/
sub print_credits()
print !"3D Plot\n"
print "Original version in BASIC:"
print !" Creative computing (Morristown, New Jersey, USA), ca. 1980.\n"
print "This version in FreeBASIC:"
print " Copyright (c) 2024, Marcos Cruz (programandala.net)"
print !" SPDX-License-Identifier: Fair\n"
print "Press any key to start the program. ";
sleep
end sub
function a(z as single) as single
return 30 * exp(-z * z / 100)
end function
function repeat(s as string, n as integer) as string
' source: https://rosettacode.org/wiki/Repeat_a_string#FreeBASIC
if n < 1 then return ""
if n = 1 then return s
var size = len(s)
if size = 0 then return s ' empty string
if size = 1 then return string(n, s[0]) ' repeated single character
var buffer = space(size * n) ' create buffer for size > 1
for i as integer = 0 to n - 1
for j as integer = 0 to size - 1
buffer[i * size + j] = s[j]
next j
next i
return buffer
end function
sub do_draw()
const size as integer = 56
dim x as single
dim l as integer
dim l1 as integer
dim y as single
dim y1 as integer
dim z as single
for x = -30 to 30 step 1.5
dim row as string = repeat(" ", size)
l = 0
y1 = 5 * int(sqr(900 - x * x) / 5)
for y = y1 to -y1 step -5
z = int((25 + a(sqr(x * x + y * y)) - .7 * y))
if z > l then
l = z
row = mid(row, 1, z) + "*" + mid(row, z+2)
end if
next
print row
next
end sub
cls
print_credits()
cls
do_draw()
' vim: filetype=freebasic
En Go
/*
3D Plot
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"
const space rune = ' '
const dot rune = '*'
const width int = 56
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
}
// Display the credits and wait for a keypress.
func printCredits() {
fmt.Println("3D Plot\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 a(z float64) float64 {
return 30 * math.Exp(-z*z/100)
}
func draw() {
var l = 0
var z = 0
var y1 = 0
var line [width]rune
for x := -30.0; x <= 30.0; x += 1.5 {
for pos := 0; pos < width; pos++ {
line[pos] = space
}
l = 0
y1 = 5 * int(math.Sqrt(900-x*x)/5)
for y := y1; y >= -y1; y += -5 {
z = int(25 + a(math.Sqrt(x*x+float64(y*y))) - 0.7*float64(y))
if z > l {
l = z
line[z] = dot
}
} // y loop
for pos := 0; pos < width; pos++ {
fmt.Printf(string(line[pos]))
}
fmt.Println()
} // x loop
}
func main() {
clearScreen()
printCredits()
clearScreen()
draw()
}
En Hare
// 3D Plot
// Original version in BASIC:
// Creative Computing (Morristown, New Jersey, USA), ca. 1980.
// This version in Hare:
// Copyright (c) 2024, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2024-12-14/15, 2025-03-07.
//
// Last modified: 20260213T1645+0100.
use bufio;
use fmt;
use math;
use os;
use strings;
def SPACE = ' ';
def DOT = '*';
def WIDTH = 56;
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 print_credits() void = {
fmt::println("3D Plot\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, Marcos Cruz (programandala.net)")!;
fmt::println(" SPDX-License-Identifier: Fair\n")!;
press_enter("Press Enter to start.");
};
fn a(z: f64) f64 = {
return 30.0 * math::expf64(-z * z / 100.0);
};
fn draw() void = {
let l = 0;
let z = 0;
let y1 = 0;
let line: [WIDTH]rune = [SPACE...];
for (let x = -30.0; x <= 30.0; x += 1.5) {
line = [SPACE...];
l = 0;
y1 = 5 * (math::sqrtf64(900.0 - x * x) / 5.0): int;
for (let y = y1; y >= -y1; y += -5) {
z = (25.0
+ a(math::sqrtf64(x * x + (y * y): f64))
- 0.7 * (y: f64)): int;
if (z > l) {
l = z;
line[z] = DOT;
};
};
for (let pos = 0; pos < WIDTH; pos += 1) {
fmt::print(line[pos])!;
};
fmt::println()!;
};
};
export fn main() void = {
clear_screen();
print_credits();
clear_screen();
draw();
};
En Icon
# 3D Plot
#
# 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-03/21.
#
# Last modified 20231103T2341+0100.
link iscreen # clear()
$define dot "*"
$define space " "
$define width 56
procedure print_credits()
clear()
write("3D Plot\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 a(z)
return 30 * exp(-z * z / 100)
end
procedure draw()
clear()
x := -30
while x <= 30 do {
line := repl(space,width)
l := 0
y1 := 5 * integer(sqrt(900 - x * x) / 5)
y := y1
while y >= -y1 do {
z := integer(25 + a(sqrt(x * x + y * y)) - .7 * y)
if z > l then {
l := z
line[z + 1] := dot
}
y -:= 5
}
write(line)
x +:= 1.50
}
end
procedure main()
print_credits()
draw()
end
En Janet
# 3D Plot
# Original version in BASIC:
# 3-D Plot (by Mark Bramhall), 1978.
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
# This version in Janet:
# Copyright (c) 2025, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2025-12-23.
#
# Last modified: 20251225T1944+0100.
(defn move-cursor-home []
(prin "\e[H"))
(defn clear-screen []
(prin "\e[2J")
(move-cursor-home))
(defn display-credits []
(print "3D Plot\n")
(print "Original version in BASIC:")
(print " Mark Bramhall, 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. ")
(flush)
(getline))
(defn a [z]
(* 30 (math/exp (/ (* (- z) z) 100))))
(defn draw []
(def line-width 56)
(def space (chr " "))
(def asterisk (chr "*"))
(def line (buffer/new-filled line-width space))
(var l 0)
(var z 0)
(var y1 0)
(var y 0)
(loop [x :range [-30 30.5 1.5]]
(set l 0)
(set y1 (* 5 (math/floor (/ (math/sqrt (- 900 (* x x))) 5))))
(loop [y :down [y1 (+ (- y1) -5) 5]]
(set z (math/floor (- (+ 25 (a (math/sqrt (+ (* x x) (* y y))))) (* 0.7 y))))
(when (> z l)
(set l z)
(buffer/push-at line z asterisk)))
(print line)
(buffer/fill line space)))
(defn main [& args]
(clear-screen)
(display-credits)
(clear-screen)
(draw))
En Julia
# 3D Plot
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
# This version in Julia:
# Copyright (c) 2023, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
# Written in 2023-07-07/08.
# Last modified: 20241202T2317+0100.
width = 56
function clear()
print("\e[0;0H\e[2J")
end
function print_credits()
clear()
println("3D Plot\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, Marcos Cruz (programandala.net)")
println(" SPDX-License-Identifier: Fair\n")
println("Press Enter to start the program.")
_ = readline()
end
function a(z)
return 30 * exp(-z * z / 100)
end
function draw()
clear()
for x = -30 : 1.5 : 30
line = repeat(" ", width)
l = 0
y1 = 5 * floor(Int, sqrt(900 - x * x) / 5)
for y = y1 : -5 : -y1
z = floor(Int, (25 + a(sqrt(x * x + y * y)) - .7 * y))
if z > l
l = z
line = line[1:z] * "*" * line[z+2:end]
end
end
println(line)
end
end
print_credits()
draw()
En Kotlin
/*
3D Plot
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()
}
fun showCredits() {
println("3D Plot\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 a(z: Double): Double {
return 30 * kotlin.math.exp(-z * z / 100)
}
fun draw() {
val width = 56
val space = ' '
val dot = '*'
var line = CharArray(width)
var l: Int
var y1: Int
var z: Int
var x = -30.0
while (x <= 30) {
line.fill(space)
l = 0
y1 = 5 * (kotlin.math.sqrt(900 - x * x) / 5).toInt()
for (y in y1 downTo -y1 step 5) {
z = (25 + a(kotlin.math.sqrt(x * x + (y * y)))-0.7 * y).toInt()
if (z > l) {
l = z
line[z] = dot
}
}
for (pos in 0 ..< width) {
print(line[pos])
}
println()
x += 1.5
}
}
fun main() {
clear()
showCredits()
clear()
draw()
}
En Lobster
/*
3D Plot
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Lobster:
Copyright (c) 2023, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2023-09-16.
Last modified 20250318T1528+0100.
*/
def clear():
print("\x1B[0;0H\x1B[2J")
def showCredits():
print("3D Plot\n")
print("Original version in BASIC:")
print(" Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
print("This version in Lobster:")
print(" Copyright (c) 2023, Marcos Cruz (programandala.net)")
print(" SPDX-License-Identifier: Fair\n")
get_line("Press Enter to start the program.")
def exp(n: float) -> float:
let E = 2.71828
return pow(E, n)
def a(z: float) -> float:
return 30.0 * exp(-z * z / 100.0)
def draw():
let WIDTH = 56
let SPACE = " "
let DOT = "*"
var l = 0
var y1 = 0
var z = 0
var x = -30.0
while x <= 30.0:
let line = []
var pos = 0
while pos < WIDTH:
push(line, SPACE)
pos += 1
l = 0
y1 = 5 * int(sqrt(900.0 - x * x) / 5.0)
var y = y1
while y >= -y1:
z = int(25.0 + a(sqrt(x * x + float(y * y))) - 0.7 * float(y))
if z > l:
l = z
line[z] = DOT
y -= 5
print(concat_string(line, ""))
x += 1.5
clear()
showCredits()
clear()
draw()
En Odin
/*
3D Plot
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Odin:
Copyright (c) 2023, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2023-02/03, 2023-08/09, 2023-12.
Last modified: 20241229T1712+0100.
*/
package three_d_plot
import "../lib/anodino/src/read"
import "../lib/anodino/src/term"
import "core:fmt"
import "core:math"
SPACE :: ' '
DOT :: '*'
WIDTH :: 56
// Display the credits and wait for a keypress.
//
print_credits :: proc() {
fmt.println("3D Plot\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, Marcos Cruz (programandala.net)")
fmt.println(" SPDX-License-Identifier: Fair\n")
read.a_prompted_string("Press Enter to start the program. ")
}
a :: proc(z : f64) -> f64 {
return 30 * math.exp(-z * z / 100)
}
draw :: proc() {
l := 0
z := 0
y1 := 0
line : [WIDTH]rune
for x := -30.0; x <= 30.0; x += 1.5 {
for pos in 0 ..< WIDTH {
line[pos] = SPACE
}
l = 0
y1 = 5 * int(math.sqrt(900 - x * x) / 5)
for y := y1; y >= -y1; y += -5 {
z = int(25 + a(math.sqrt(x * x + f64(y * y))) - 0.7 * f64(y))
if z > l {
l = z
line[z] = DOT
}
} // y loop
for pos in 0 ..< WIDTH {
fmt.print(line[pos])
}
fmt.println("")
} // x loop
}
main :: proc() {
term.clear_screen()
print_credits()
term.clear_screen()
draw()
}
En Pike
#! /usr/bin/env pike
// 3D Plot
// 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: 20250311T0155+0100.
constant SPACE = " ";
constant DOT = "*";
constant WIDTH = 56;
void clear_screen() {
write("\x1B[0;0H\x1B[2J");
}
void prompt(string s) {
write(s);
Stdio.stdin->gets();
}
void print_credits() {
write("3D Plot\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");
prompt("Press Enter to start. ");
}
float a(float z) {
return 30.0 * exp(-z * z / 100.0);
}
void draw() {
int l = 0;
int z = 0;
int y1 = 0;
array(string) line = allocate(WIDTH);
for (float x = -30.0; x <= 30.0; x += 1.5) {
for (int i = 0; i < WIDTH; i += 1)
line[i] = SPACE;
l = 0;
y1 = 5 * (int) (sqrt(900.0 - x * x) / 5.0);
for (int y = y1; y >= -y1; y += -5) {
z = (int) (25.0 + a(sqrt(x * x + (float) (y * y))) - 0.7 * (float) y);
if (z > l) {
l = z;
line[z] = DOT;
}
} // y loop
for (int pos = 0; pos < WIDTH; pos += 1)
write(line[pos]);
write("\n");
} // x loop
}
void main() {
clear_screen();
print_credits();
clear_screen();
draw();
}
En Python
# 3D Plot
# 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: 20241029T1607+0100.
import math
import os
WIDTH = 56
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("3D Plot\n")
print("Original version in BASIC:")
print(" Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
print("This version in Python:")
print(" Copyright (c) 2024, Marcos Cruz (programandala.net)")
print(" SPDX-License-Identifier: Fair\n")
input("Press Enter to start the program.")
def a(z):
return 30 * math.exp(-z * z / 100)
def draw():
x = -30.0
while x <= 30.0:
line = " " * WIDTH
l = 0
y1 = 5 * math.floor(math.sqrt(900 - x * x) / 5)
for y in range(y1, -y1 - 1, -5):
z = math.floor(25 + a(math.sqrt(x * x + y * y)) - .7 * y)
if z > l:
l = z
line = line[: z] + "*" + line[z + 1:]
print(line)
x += 1.5
print_credits()
clear()
draw()
En Racket
#! /usr/bin/env racket
#|
3D Plot
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Racket:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2024-12-06.
Last modified: 20260106T0841+0100.
|#
#lang racket
(define (move-cursor-home)
(display "\e[H"))
(define (clear-screen)
(display "\e[2J")
(move-cursor-home))
(define (display-credits)
(displayln "3D Plot\n")
(displayln "Original version in BASIC:")
(displayln " Creative computing (Morristown, New Jersey, USA), ca. 1980.\n")
(displayln "This version in Racket")
(displayln " Copyright (c) 2024, Marcos Cruz (programandala.net)")
(displayln " SPDX-License-Identifier: Fair\n")
(display "Press Enter to start the program. ")
(void (read-line)))
(define (a z)
(* 30 (exp (/ (* (- z) z) 100))))
(define (draw)
(define l 0)
(define z 0)
(define y1 0)
(define line-width 56)
(define line (make-string line-width #\space))
(for ([x (in-range -30.0 30.5 1.5)])
(set! l 0)
(set! y1 (* 5 (exact-floor (/ (sqrt (- 900 (* x x))) 5))))
(for ([y (in-range y1 (+ (- y1) -5) -5)])
(set! z (exact-floor (- (+ 25 (a (sqrt (+ (* x x) (* y y))))) (* 0.7 y))))
(when (> z l)
(begin
(set! l z)
(string-set! line z #\*))))
(displayln line)
(string-fill! line #\space)))
(clear-screen)
(display-credits)
(clear-screen)
(draw)
En Raku
# 3D Plot
# 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-02.
# Last modified: 20241211T1232+0100.
constant $WIDTH = 56;
sub clear_screen {
print "\e[0;0H\e[2J";
}
sub print_credits {
put "3D Plot\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";
put 'Press Enter to start the program.';
prompt '';
}
sub a($z) {
30 * exp(-$z * $z / 100);
}
sub draw {
for -30, -28.5 ... 30 -> $x {
my $line = ' ' x $WIDTH;
my $l = 0;
my $y1 = 5 * (sqrt(900 - $x * $x) / 5).Int;
for $y1, $y1 - 5 ... -$y1 -> $y {
my $z = (25 + a(sqrt($x * $x + $y * $y)) - .7 * $y).Int;
if $z > $l {
$l = $z;
$line.substr-rw($z, 1) = '*';
}
}
put $line;
}
}
clear_screen;
print_credits;
clear_screen;
draw;
En Ring
/*
3D Plot
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Ring:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2024-03-15.
Last modified: 20240318T1303+0100.
*/
SPACE = " "
DOT = "*"
WIDTH = 56
// Clear the terminal and move the cursor to the top left position.
func clear() {
system("clear")
}
// Display the credits and wait for a keypress.
func printCredits() {
print("3D Plot\n\n")
print("Original version in BASIC:\n")
print(" Creative computing (Morristown, New Jersey, USA), ca. 1980.\n\n")
print("This version in Ring:\n")
print(" Copyright (c) 2024, Marcos Cruz (programandala.net)\n")
print(" SPDX-License-Identifier: Fair\n\n")
print("Press Enter to start the program.\n")
getString()
}
func a(z) {
return 30.0 * exp(-z * z / 100.0)
}
func draw() {
l = 0
z = 0
y1 = 0
line = list(WIDTH)
x = -30.0
while x <= 30.0 {
for pos = 1 to WIDTH {
line[pos] = SPACE
}
l = 0
y1 = 5 * floor(sqrt(900.0 - x * x) / 5.0)
y = y1
while y >= -y1 {
z = floor(25.0 + a(sqrt(x * x + y * y)) - 0.7 * y)
if z > l {
l = z
line[z] = DOT
}
y += -5
} // y loop
print(SPACE)
for pos = 1 to WIDTH {
print(line[pos])
}
print(nl)
x += 1.5
} // x loop
}
func main {
clear()
printCredits()
clear()
draw()
}
En Rust
/*
3D Plot
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 on 2024-12-26/27.
Last modified: 20241227T1235+0100.
*/
use std::io;
use std::io::Write;
const SPACE: char = ' ';
const DOT: char = '*';
const WIDTH: usize = 56;
fn move_cursor_home() {
print!("\x1B[H")
}
fn erase_screen() {
print!("\x1B[2J")
}
fn clear_screen() {
erase_screen();
move_cursor_home()
}
fn press_enter(prompt: &str) {
print!("{prompt}");
io::stdout().flush().unwrap(); // print pending text
let mut input = String::new();
let _ = io::stdin().read_line(&mut input);
}
// Display the credits and wait for a keypress.
//
fn print_credits() {
println!("3D Plot\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");
press_enter("Press Enter to start the program. ")
}
fn a(z: f64) -> f64 {
return 30.0 * f64::exp(-z * z / 100.0)
}
fn draw() {
let mut l: isize;
let mut z: isize;
let mut y1: isize;
let mut line : [char; WIDTH];
let mut x: f64 = -30.0;
while x <= 30.0 {
line = [SPACE; WIDTH];
l = 0;
y1 = 5 * (f64::sqrt(900.0 - x * x) / 5.0) as isize;
let mut y = y1;
while y >= -y1 {
z = (25.0 + a(f64::sqrt(x * x + (y * y) as f64)) - 0.7 * (y as f64)) as isize;
if z > l {
l = z;
line[z as usize] = DOT
}
y += -5
} // y loop
for pos in 0 .. WIDTH {
print!("{}", line[pos])
}
println!();
x += 1.5
} // x loop
}
fn main() {
clear_screen();
print_credits();
clear_screen();
draw()
}
En Scala
/*
3D Plot
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()
def showCredits() =
println("3D Plot\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 any key to start the program.")
io.StdIn.readLine("")
def a(z: Double): Double =
30 * math.exp(-z * z / 100)
def draw() =
val width = 56
val space = ' '
val dot = '*'
var line = new Array[Char](width)
var l = 0
var y1 = 0
var z = 0
var x = -30.0
while x <= 30 do
line = Array.fill(width){space}
l = 0
y1 = 5 * (math.sqrt(900 - x * x) / 5).toInt
for y <- y1 to -y1 by -5 do
z = (25 + a(math.sqrt(x * x + (y * y)))-0.7 * y).toInt
if z > l then
l = z
line(z) = dot
for pos <- 0 until width do
print(line(pos))
println()
x += 1.5
@main def main() =
clear()
showCredits()
clear()
draw()
En Scheme
; 3D Plot
; Original version in BASIC:
; 3-D Plot (by Mark Bramhall), 1978.
; Creative Computing (Morristown, New Jersey, USA), ca. 1980.
; This version in Scheme (Bigloo):
; Copyright (c) 2025, Marcos Cruz (programandala.net)
; SPDX-License-Identifier: Fair
;
; Written in 2025-11-30/12-03.
;
; Last modified: 20251205T0113+0100.
(module 3d-plot)
(define (move-cursor-home)
(display "\x1B[H"))
(define (clear-screen)
(display "\x1B[2J")
(move-cursor-home))
(define (display-credits)
(display "3D Plot\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 (a z)
(* 30 (exp (/ (* (- z) z) 100))))
(define (draw)
(define l 0)
(define z 0)
(define y1 0)
(define line-width 56)
(define line (make-string line-width #\space))
(do ((x -30.0 (+ x 1.5))) ((> x 30.0))
(set! l 0)
(set! y1 (* 5 (floor (/ (sqrt (- 900 (* x x))) 5))))
(do ((y y1 (- y 5))) ((< y (- y1)))
(set! z (floor (- (+ 25 (a (sqrt (+ (* x x) (* y y))))) (* 0.7 y))))
(when (> z l)
(set! l z)
(string-set! line (inexact->exact (truncate z)) #\*)))
(display line)
(newline)
(string-fill! line #\space)))
(clear-screen)
(display-credits)
(clear-screen)
(draw)
En Swift
/*
3D Plot
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-02/03, 2023-11-17.
Last modified: 20231117T2222+0100.
*/
import Foundation // exp(), sqrt()
let SPACE = " "
let DOT = "*"
let WIDTH = 56
// 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()
}
// Display the credits and wait for a keypress.
func printCredits() {
print("3D Plot\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 a(_ z: Double) -> Double {
return 30.0 * exp(-z * z / 100.0)
}
func draw() {
var l = 0
var z = 0
var y1 = 0
var line = Array<String>(repeating: SPACE, count: WIDTH)
var x = -30.0
while x <= 30.0 {
for pos in 0 ..< WIDTH {
line[pos] = SPACE
}
l = 0
y1 = 5 * Int(sqrt(900.0 - x * x) / 5.0)
var y = y1
while y >= -y1 {
z = Int(25.0 + a(sqrt(x * x + Double(y * y))) - 0.7 * Double(y))
if z > l {
l = z
line[z] = DOT
}
y += -5
} // y loop
for pos in 0 ..< WIDTH {
print(line[pos], terminator: "")
}
print()
x += 1.5
} // x loop
}
clear()
printCredits()
clear()
draw()
En V
/*
3D Plot
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
Written in 2023-02-04/05.
Last modified 20250108T2315+0100.
*/
import math
import os
import term
const space = u8(` `)
const dot = u8(`*`)
fn credits() {
term.clear()
println('3D Plot\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')
os.input('\nPress the Enter key to start. ')
}
fn a(z f64) f64 {
return 30 * math.exp(-z * z / 100)
}
fn draw() {
mut l := 0
mut z := 0
mut y1 := 0
width := 56
mut line := []u8{len: width}
term.clear()
for x := -30.0; x <= 30.0; x += 1.5 {
line = []u8{len: width, init: space}
l = 0
y1 = 5 * int(math.sqrt(900 - x * x) / 5)
for y := y1; y >= -y1; y += -5 {
z = int(25 + a(math.sqrt(x * x + y * y)) - 0.7 * f64(y))
if z > l {
l = z
line[z] = dot
}
} // y loop
println(line.bytestr())
} // x loop
}
fn main() {
credits()
draw()
}
En Vala
/*
3D Plot
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-30/31.
Last modified 20231103T2132+0100.
*/
using GLib; // Math needed
// Clear the screen, reset the attributes and move the cursor to the home position.
void clear() {
print("\033[2J\033[0m\033[H");
}
// Display the credits and wait until the user presses Enter.
void print_credits() {
print("3D Plot\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();
}
double a(double z) {
return 30 * Math.exp(-z * z / 100);
}
void draw() {
const int width = 56;
const char space = ' ';
const char dot = '*';
char line[width];
int l = 0;
int z = 0;
int y1 = 0;
for (double x = -30.0; x <= 30.0; x += 1.5) {
for (int pos = 0; pos < width; pos++) {
line[pos] = space;
}
l = 0;
y1 = 5 * (int)(Math.sqrt(900 - x * x) / 5);
for (int y = y1; y >= -y1; y += -5) {
z = (int)(25 + a(Math.sqrt(x * x + (y * y))) - 0.7 * y);
if (z > l) {
l = z;
line[z] = dot;
}
} // y loop
for (int pos = 0; pos < width; pos++) {
print(line[pos].to_string());
}
print("\n");
} // x loop
}
void main() {
clear();
print_credits();
clear();
draw();
}
