Piko

From Esolang
Jump to navigation Jump to search

Piko

Piko is an esoteric language made by User:Kirbyiseatinghumanmeat. The idea of Piko is a canvas that allows you to draw things on it using commands!

Overview

Piko is based on a canvas, an 8x8, 2D array. Every single string inside the canvas is called cells, you put a character (like /) to every single string on the canvas though commands, so that character will be represented on the current row and column in the canvas, when Piko finished your masterpiece, it will show it to the user.

Commands

| <n>        Move horizontally (Go to the <n> row)
- <n>        Move vertically (Go to the <n> column)
> <char>     Replace the string at the current row and column with <char>
_ <char>     Fill the current row with <char>
. <t>        Sleep for <t> seconds (Kinda useless)
^ <filename> Run the filename

Note that the ^ command hasn't been tested on the original interpreter yet!

Implementations

The original interpreter (Written in Ruby)

To use the interpreter, you will need to run it with a file name (like Arsel).

class String
 def raw
   gsub("\\" * 2) { "\\" * 3 }
 end
end
class Piko
 def init_board
   result = [[]]*8
   for index in 0..result.length
     result[index] = [" "]*8
   end
   return result
 end
 def initialize(file)
   @script = file.split("\n")
   @board = init_board
   @valid_cmds = %w[
     | - > _ . ^
   ]
   @col, @row = 0, 0
   @pos = 0
 end
 def print_board()
   for smaller_board in @board
     puts smaller_board.to_s
   end
 end
 def run()
   while @pos < @script.length
     cmd, value = @script[@pos].split(" ")
     if @valid_cmds.include? cmd
       if cmd == "|"
         @row = value.to_i
         @pos += 1
       elsif cmd == "-"
         @col = value.to_i
         @pos += 1
       elsif cmd == ">"
         @board[@row][@col] = value.raw
         @pos += 1
       elsif cmd == "_"
         @board[@row] = [value]*8
         @pos += 1
       elsif cmd == "."
         sleep value.to_i
         @pos += 1
       elsif cmd == "^"
         run File.read(value)
         @pos += 1
       end
     elsif cmd == " " then @pos += 1
     else
       puts "Invalid command: #{cmd}"
       break
     end
   end
   print_board
 end
end
piko = Piko.new(File.read(ARGV[0]))
piko.run