Agent 47

*A simple fork to display agent 47's barcode (640509 - 040147)*


play.google.com/stor…%20scanner&hl=fr

Log in to post a comment.

// Forked from "What time is it?" by bap
// https://turtletoy.net/turtle/2985a91e4b

const dict = {
    "start": {code: "11010000100", value: 103},
    "stop": {code: "1100011101011", value: 106},
	" ":{code: "11011001100", value: 0, },
	"!":{code: "11001101100", value: 1, },
	'"':{code: "11001100110", value: 2, },
	"#":{code: "10010011000", value: 3, },
	"$":{code: "10010001100", value: 4, },
	"%":{code: "10001001100", value: 5, },
	"&":{code: "10011001000", value: 6, },
	"'":{code: "10011000100", value: 7, },
	"(":{code: "10001100100", value: 8, },
	")":{code: "11001001000", value: 9, },
	"*":{code: "11001000100", value: 10, },
	"+":{code: "11000100100", value: 11, },
	",":{code: "10110011100", value: 12, },
	"-":{code: "10011011100", value: 13, },
	".":{code: "10011001110", value: 14, },
	"/":{code: "10111001100", value: 15, },
	"0":{code: "10011101100", value: 16, },
	"1":{code: "10011100110", value: 17, },
	"2":{code: "11001110010", value: 18, },
	"3":{code: "11001011100", value: 19, },
	"4":{code: "11001001110", value: 20, },
	"5":{code: "11011100100", value: 21, },
	"6":{code: "11001110100", value: 22, },
	"7":{code: "11101101110", value: 23, },
	"8":{code: "11101001100", value: 24, },
	"9":{code: "11100101100", value: 25, },
	":":{code: "11100100110", value: 26, },
	";":{code: "11101100100", value: 27, },
	"<":{code: "11100110100", value: 28, },
	"=":{code: "11100110010", value: 29, },
	">":{code: "11011011000", value: 30, },
	"?":{code: "11011000110", value: 31, },
	"@":{code: "11000110110", value: 32, },
	"A":{code: "10100011000", value: 33, },
	"B":{code: "10001011000", value: 34, },
	"C":{code: "10001000110", value: 35, },
	"D":{code: "10110001000", value: 36, },
	"E":{code: "10001101000", value: 37, },
	"F":{code: "10001100010", value: 38, },
	"G":{code: "11010001000", value: 39, },
	"H":{code: "11000101000", value: 40, },
	"I":{code: "11000100010", value: 41, },
	"J":{code: "10110111000", value: 42, },
	"K":{code: "10110001110", value: 43, },
	"L":{code: "10001101110", value: 44, },
	"M":{code: "10111011000", value: 45, },
	"N":{code: "10111000110", value: 46, },
	"O":{code: "10001110110", value: 47, },
	"P":{code: "11101110110", value: 48, },
	"Q":{code: "11010001110", value: 49, },
	"R":{code: "11000101110", value: 50, },
	"S":{code: "11011101000", value: 51, },
	"T":{code: "11011100010", value: 52, },
	"U":{code: "11011101110", value: 53, },
	"V":{code: "11101011000", value: 54, },
	"W":{code: "11101000110", value: 55, },
	"X":{code: "11100010110", value: 56, },
	"Y":{code: "11101101000", value: 57, },
	"Z":{code: "11101100010", value: 58, },
	"[":{code: "11100011010", value: 59, },
	"\\":{code: "11101111010", value: 60, },
	"]":{code: "11001000010", value: 61, },
	"^":{code: "11110001010", value: 62, },
	"_":{code: "10100110000", value: 63, },
	"NUL":{code: "10100001100", value: 64, },
	"SOH":{code: "10010110000", value: 65, },
	"STX":{code: "10010000110", value: 66, },
	"ETX":{code: "10000101100", value: 67, },
	"EOT":{code: "10000100110", value: 68, },
	"ENQ":{code: "10110010000", value: 69, },
	"ACK":{code: "10110000100", value: 70, },
	"BEL":{code: "10011010000", value: 71, },
	"BS":{code: "10011000010", value: 72, },
	"HT":{code: "10000110100", value: 73, },
	"LF":{code: "10000110010", value: 74, },
	"VT":{code: "11000010010", value: 75, },
	"FF":{code: "11001010000", value: 76, },
	"CR":{code: "11110111010", value: 77, },
	"SO":{code: "11000010100", value: 78, },
	"SI":{code: "10001111010", value: 79, },
	"DLE":{code: "10100111100", value: 80, },
	"DC1":{code: "10010111100", value: 81, },
	"DC2":{code: "10010011110", value: 82, },
	"DC3":{code: "10111100100", value: 83, },
	"DC4":{code: "10011110100", value: 84, },
	"NAK":{code: "10011110010", value: 85, },
	"SYN":{code: "11110100100", value: 86, },
	"ETB":{code: "11110010100", value: 87, },
	"CAN":{code: "11110010010", value: 88, },
	"EM":{code: "11011011110", value: 89, },
	"SUB":{code: "11011110110", value: 90, },
	"ESC":{code: "11110110110", value: 91, },
	"FS":{code: "10101111000", value: 92, },
	"GS":{code: "10100011110", value: 93, },
	"RS":{code: "10001011110", value: 94, },
	"US":{code: "10111101000", value: 95, },
}

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();
turtle.setheading(90)
        
const HEIGHT = 50
const WIDTH = 0.8
const START = -80

const drawLine = (x, black)  => {
    for (let i=0; i<WIDTH*10; i++) {
        turtle.penup()
        turtle.goto(x+i*0.1, -HEIGHT/2+5)
        if (black) {
            turtle.pendown()
        }
        turtle.forward(HEIGHT)
    }
}

const drawCode = (input) => {
    let x = START
    for (let i=0; i<input.length; i++) {
        drawLine(x, input[i])
        x += WIDTH
    }
}

const textToInput = (text) => {
    return text.split("").reduce((result, letter) => {
        if (!dict[letter]) {
            throw Error("Missing character: " + letter + ".")
        }
        return result + dict[letter].code  
    }, "").split("").map(Number)
}

const checkSum = (text) => {
    let sum = 103
    for (let i = 1; i <= text.length; i++) {
        sum += i * dict[text[i-1]].value
    }
    return sum % 103
}

const getCheckSum = (text) => {
    const cs = checkSum(text)
    for (letter in dict) {
        if (dict[letter].value === cs) {
            return dict[letter].code.split("").map(Number)
        }
    }
    throw Error("Could not find letter with value: " + cs + ".")
}

const getDate = () => {
    return "640509 - 040147"; // Remplace par la chaîne que tu veux
}


const text = getDate()
drawCode(
    dict.start.code.split("").map(Number)
    .concat(textToInput(text))
    .concat(getCheckSum(text))
    .concat(dict.stop.code.split("").map(Number))
)