Write language name in 3D ASCII: Difference between revisions
m Added note |
Keithpinson (talk | contribs) Converts a grid of astrisks to 3D cubes |
||
Line 133: | Line 133: | ||
For the VRML script, see [http://nsg.upor.net/jpage/jpage.htm Andrew Nikitin's J page] (search for VRML) and for the origin of the 3D J banner, see [http://www.jsoftware.com/pipermail/programming/2007-May/006539.html Oleg Kobchenko's post to the J Forums]. |
For the VRML script, see [http://nsg.upor.net/jpage/jpage.htm Andrew Nikitin's J page] (search for VRML) and for the origin of the 3D J banner, see [http://www.jsoftware.com/pipermail/programming/2007-May/006539.html Oleg Kobchenko's post to the J Forums]. |
||
=={{header|Scala}}== |
|||
<lang Scala>def ASCII3D = { |
|||
val name = """ |
|||
* |
|||
** ** * * * |
|||
* * * * * * * |
|||
* * * * * * * |
|||
* * *** * *** |
|||
* * * * * * * |
|||
* * * * * * * |
|||
** ** * * *** * * |
|||
* |
|||
* |
|||
""" |
|||
// |
|||
// Create Array |
|||
// |
|||
def getMaxSize( s:String ) : (Int,Int) = { |
|||
var width = 0 |
|||
var height = 0 |
|||
val nameArray = s.split("\n") |
|||
height = nameArray.size |
|||
nameArray foreach {i => width = (i.size max width)} |
|||
(width,height) |
|||
} |
|||
val size = getMaxSize( name ) |
|||
var arr = Array.fill( size._2+1, (size._1*3)+(size._2+1) )( ' ' ) |
|||
// |
|||
// Map astrisk to 3D cube |
|||
// |
|||
val cubeTop = """///\""" |
|||
val cubeBottom = """\\\/""" |
|||
val nameArray = name.split("\n") |
|||
for( j <- (0 until nameArray.size) ) { |
|||
for( i <- (0 until nameArray(j).size) ) { |
|||
if( nameArray(j)(i) == '*' ) |
|||
{ |
|||
val indent = nameArray.size - j |
|||
arr(j ) = arr(j ) patch ((i*3 + indent), cubeTop, cubeTop.size) |
|||
arr(j+1) = arr(j+1) patch ((i*3 + indent), cubeBottom, cubeBottom.size) |
|||
} |
|||
} |
|||
} |
|||
// |
|||
// Map Array to String |
|||
// |
|||
var name3D = "" |
|||
for( j <- (0 until arr.size) ) { |
|||
for( i <- (0 until arr(j).size) ) { name3D += arr(j)(i) } |
|||
name3D += "\n" |
|||
} |
|||
name3D |
|||
} |
|||
println(ASCII3D)</lang> |
|||
{{out}} |
|||
<pre> |
|||
///\ |
|||
//////\ //////\ ///\ ///\/ ///\ |
|||
///\\\\\\\/ ///\\\\\\\/ ///\\\///\ ///\/ ///\\\///\ |
|||
///\/ ///\/ ///\/ ///\/ ///\/ ///\/ ///\/ |
|||
\\///\ ///\/ /////////\/ ///\/ /////////\/ |
|||
\\///\ ///\/ ///\\\///\/ ///\/ ///\\\///\/ |
|||
///\/ ///\/ ///\/ ///\/ ///\/ ///\/ ///\/ |
|||
//////\\\\/ \\//////\ ///\/ \\///\ /////////\ ///\/ ///\/ |
|||
\\\\\\/ \\\\\\/ \\\/ \\\/ \\\\\\\\\/ \\\/ ///\/ |
|||
\\///\ |
|||
\\\/ |
|||
</pre> |
|||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
Revision as of 22:26, 18 March 2012
The task is to write the language's name in 3D ASCII. (We can leave the definition of "3D ASCII" fuzzy, so long as the result is interesting or amusing, not a cheap hack to satisfy the task.)
Ada
Quotes are not escaped by \ in ada (nor does \ have any meaning in strings), so this turns out highlighting funny. <lang Ada>with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Fixed; use Ada.Strings.Fixed; procedure AsciiArt is
art : constant array(1..27) of String(1..14) := (1=>" /\\\\\\ ", 2=>" /\\\", 3|6|9=>" ", 4|12=>" /\\\\\\\\\\ ", 5|8|11=>" \/\\\", 7|17|21=>" /\\\//////\\\", 10|19|20|22=>"\/\\\ \/\\\", 13|23|24=>"\/\\\\\\\\\\\\", 14|18=>" /\\\\\\\\\\\", 15=>" \/////////\\\", 16=>"\/\\\//////\\\", 25=>"\/// \/// ", 26|27=>"\//////////// ");
begin
for i in art'Range loop Put(art(i)&' '); if i mod 3 = 0 then New_Line; Put(i/3*' '); end if; end loop;
end AsciiArt;</lang>
- Output:
/\\\\\\ /\\\ /\\\\\\\\\\ \/\\\ /\\\//////\\\ \/\\\ \/\\\ \/\\\ \/\\\ /\\\\\\\\\\ \/\\\\\\\\\\\\ /\\\\\\\\\\\ \/////////\\\ \/\\\//////\\\ /\\\//////\\\ /\\\\\\\\\\\ \/\\\ \/\\\ \/\\\ \/\\\ /\\\//////\\\ \/\\\ \/\\\ \/\\\\\\\\\\\\ \/\\\\\\\\\\\\ \/// \/// \//////////// \////////////
C
3D enough?<lang c>#include <stdio.h> char*s = " _____\n /____/\\\n/ ___\\/\n\\ \\/__/\n \\____/"; int main(){ puts(s); return 0; }</lang>
Icon and Unicon
The following fits under the fuzzy definition of 3D ASCII and pays homage to one of the Icon Newsletter logos. <lang Icon>procedure main(arglist) write(ExpandText(
if !arglist == "icon" then "14/\\\n14\\/\n12/\\\n11/1/\n10/1/1/\\\n10\\/1/2\\\n12/1/\\1\\\n_ 12\\1\\1\\/\n10/\\1\\1\\2/\\\n9/2\\1\\/1/2\\\n_ 8/1/\\1\\2/1/\\1\\2/\\\n8\\1\\/1/2\\1\\/1/2\\1\\\n_ 6/\\1\\2/4\\2/1/\\1\\1\\\n5/1/2\\/6\\/1/2\\1\\/\n_ /\\2/1/1/\\10/1/\\1\\2/\\\n\\/2\\1\\/1/10\\/1/1/2\\/\n_ 2/\\1\\2/1/\\6/\\2/1/\n2\\1\\1\\/1/2\\4/2\\1\\/\n_ 3\\1\\2/1/\\1\\2/1/\\1\\\n4\\/2\\1\\/1/2\\1\\/1/\n_ 9\\2/1/\\1\\2/\n10\\/2\\1\\1\\/\n12/\\1\\1\\\n12\\1\\/1/\n_ 13\\2/1/\\\n14\\/1/1/\n16/1/\n16\\/\n14/\\\n14\\/\n" else "13/\\\n12/1/\n11/1/1/\\\n11\\1\\/1/\n12\\2/1/\\\n13\\/1/2\\\n_ 15/1/\\1\\2/\\\n15\\/1/1/2\\/\n17/1/1/\\18/\\\n17\\/1/1/17/2\\\n_ 19/1/1/\\14/1/\\1\\\n19\\/1/2\\13\\1\\1\\/\n21/1/\\1\\10/\\1\\1\\\n_ 21\\1\\1\\/10\\1\\1\\/\n19/\\1\\1\\2/\\6/\\1\\1\\\n_ 18/2\\1\\/1/2\\5\\1\\/1/\n17/1/\\1\\2/1/\\1\\2/\\1\\2/\n_ 17\\1\\/1/2\\1\\/1/2\\1\\1\\/\n15/\\1\\2/4\\2/1/\\1\\1\\\n_ 14/1/2\\/6\\/1/2\\1\\/\n9/\\2/1/1/\\10/1/\\1\\2/\\\n_ 9\\/2\\1\\/1/10\\/1/1/2\\/\n11/\\1\\2/1/\\6/\\2/1/\n_ 11\\1\\1\\/1/2\\4/2\\1\\/\n9/\\1\\1\\2/1/\\1\\2/1/\\1\\\n_ 8/2\\1\\/2\\1\\/1/2\\1\\/1/\n7/1/\\1\\5\\2/1/\\1\\2/\n_ 7\\1\\1\\/6\\/2\\1\\1\\/\n5/\\1\\1\\10/\\1\\1\\\n_ 5\\1\\1\\/10\\1\\/1/\n3/\\1\\1\\13\\2/1/\\\n3\\1\\/1/14\\/1/1/\n_ 4\\2/17/1/1/\\\n5\\/18\\/1/1/\n23/\\2/1/1/\\\n23\\/2\\1\\/1/\n_ 28\\2/1/\\\n29\\/1/2\\\n31/1/\\1\\\n31\\/1/1/\n33/1/\n33\\/\n" ))
end
procedure ExpandText(s) s ? until pos(0) do
writes(repl(" ",tab(many(&digits)))|tab(upto(&digits)|0))
end</lang>
Sample output with "icon" as the argument:
/\ \/ /\ / / / / /\ \/ / \ / /\ \ \ \ \/ /\ \ \ /\ / \ \/ / \ / /\ \ / /\ \ /\ \ \/ / \ \/ / \ \ /\ \ / \ / /\ \ \ / / \/ \/ / \ \/ /\ / / /\ / /\ \ /\ \/ \ \/ / \/ / / \/ /\ \ / /\ /\ / / \ \ \/ / \ / \ \/ \ \ / /\ \ / /\ \ \/ \ \/ / \ \/ / \ / /\ \ / \/ \ \ \/ /\ \ \ \ \/ / \ / /\ \/ / / / / \/ /\ \/
J
<lang j> require 'vrml.ijs' NB. Due to Andrew Nikitin
view 5#.^:_1]21-~a.i.'j*ez`C3\toy.G)' NB. Due to Oleg Kobchenko ________________________ |\ \ \ \ \ | \_____\_____\_____\_____\ | | | | |\ \ |\| | | | \_____\ | \_____|_____|_____| | | | | | | | |\| | \| | |\| | \_____| \_____| | \_____| | | | |\| | | \_____| ______ | | |
|\ \ |\| | | \_____\_________|_\_____| | |\ \ \ \ |
\| \_____\_____\_____\ | | | | | |___| \| | | | \_____|_____|_____|
</lang>
For the VRML script, see Andrew Nikitin's J page (search for VRML) and for the origin of the 3D J banner, see Oleg Kobchenko's post to the J Forums.
Scala
<lang Scala>def ASCII3D = {
val name = """ * ** ** * * * * * * * * * * * * * * * * * * * *** * *** * * * * * * * * * * * * * * ** ** * * *** * * * * """
// // Create Array // def getMaxSize( s:String ) : (Int,Int) = { var width = 0 var height = 0 val nameArray = s.split("\n") height = nameArray.size nameArray foreach {i => width = (i.size max width)} (width,height) } val size = getMaxSize( name ) var arr = Array.fill( size._2+1, (size._1*3)+(size._2+1) )( ' ' )
// // Map astrisk to 3D cube // val cubeTop = """///\""" val cubeBottom = """\\\/""" val nameArray = name.split("\n")
for( j <- (0 until nameArray.size) ) { for( i <- (0 until nameArray(j).size) ) { if( nameArray(j)(i) == '*' ) { val indent = nameArray.size - j arr(j ) = arr(j ) patch ((i*3 + indent), cubeTop, cubeTop.size) arr(j+1) = arr(j+1) patch ((i*3 + indent), cubeBottom, cubeBottom.size) } } } // // Map Array to String // var name3D = "" for( j <- (0 until arr.size) ) { for( i <- (0 until arr(j).size) ) { name3D += arr(j)(i) } name3D += "\n" } name3D
}
println(ASCII3D)</lang>
- Output:
///\ //////\ //////\ ///\ ///\/ ///\ ///\\\\\\\/ ///\\\\\\\/ ///\\\///\ ///\/ ///\\\///\ ///\/ ///\/ ///\/ ///\/ ///\/ ///\/ ///\/ \\///\ ///\/ /////////\/ ///\/ /////////\/ \\///\ ///\/ ///\\\///\/ ///\/ ///\\\///\/ ///\/ ///\/ ///\/ ///\/ ///\/ ///\/ ///\/ //////\\\\/ \\//////\ ///\/ \\///\ /////////\ ///\/ ///\/ \\\\\\/ \\\\\\/ \\\/ \\\/ \\\\\\\\\/ \\\/ ///\/ \\///\ \\\/
ZX Spectrum Basic
We have used an extended (non ascii) character in this example to produce an inverted space symbol (143 on the spectrum character table), for simplicity. We could substitute another character, and change the handler to cause a colour switch using a traditional space (ascii 32), but the output would still look the same.
<lang zxbasic>10 LET s$="BASIC": REM our language name 20 DIM b(5,5):REM our bigmap characters 30 FOR l = 1 TO 5: REM 5 characters 40 FOR m = 1 TO 5: REM 5 rows 50 READ b(l,m) 60 NEXT m 70 NEXT l
100 PAPER 0: REM black background 110 INK 2: REM our shadow will be red 120 CLS 130 LET r=9: REM shadow will start on row 5 140 LET c=2: REM shadow will start at column 2 150 GO SUB 2000: REM draw shadow 160 INK 6: REM our forground will be yellow 170 LET r=10: REM foreground will start on row 6 180 LET c=3: REM foreground will start on column 3 190 GO SUB 2000: REM display the language name
999 STOP
1000 REM convert to binary bigmap 1010 LET t=n: REM temporary variable 1020 LET g$="": REM this will contain our 5 character binary bigmap 1040 FOR z=5 TO 0 STEP -1 1050 LET d$=" ": REM assume next digit is zero (draw a space) 1060 IF t>=(2^z) THEN LET d$=CHR$(143): LET t=t-(2^z): LET sf=1: REM 143 is a block 1070 LET g$=g$+d$ 1080 NEXT z 1090 RETURN
2000 REM display the big letters 2010 FOR l=1 TO 5: REM our 5 rows 2020 PRINT AT r+l-1,c; 2030 FOR m=1 TO 5: REM bigmap for each character 2040 LET n=b(l,m) 2050 GO SUB 1000 2060 PRINT g$;: REM 5 character bigmap 2070 PRINT " ";: REM space between each letter 2080 NEXT m 2090 NEXT l 2100 RETURN
9000 DATA 30,17,30,17,30: REM B 9010 DATA 14,17,31,17,17: REM A 9020 DATA 15,16,14,1,30: REM S 9030 DATA 31,4,4,4,31: REM I 9040 DATA 14,17,16,17,14: REM C</lang>