Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- artdecode.c (artefact signal decoder) - Cmdr. Evrithiki
- This script uses ROOT (http://root.cern.ch) to decode and draw polygonal
- renderings encoded by 'Unknown Artefact' (sic; British English) in the
- game Elite: Dangerous (or anything using the same encoding system)
- on a 26x26 2D plot.
- The encoding scheme uses letters A-Z to encode triplets of X,Y coordinates
- to create a triangle. A series of these triangles will, when plotted,
- create a complete image.
- The string AA will encode 0,0 and ZZ will encode 25,25. (An offset
- can be added to plotted coordinates if desired; this will also
- increase the size of the canvas.)
- This script will only accept letters in the English alphabet. Case
- does not matter ('A' is the same as 'a').
- For more information and prewritten examples, see
- https://forums.frontier.co.uk/showthread.php?t=175726&page=498.
- This script will error-check input and will not accept strings of
- coordinates with missing letters, nor will it accept any containing
- digits (1-9).
- It is designed to be run as a script within ROOT. From a ROOT prompt,
- enter '.x artdecode.c' and follow the prompts.
- This work is licensed under the Creative Commons Attribution-
- NonCommercial-ShareAlike 4.0 International License. To view a copy of
- this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
- Please credit "Cmdr. Evrithiki" if you use it. It would be neat if
- someone was able to make a cross-platform graphical version of this
- script and improved on the graphics, particularly the shading!
- */
- /* declare global variables - note, Float_t is a special ROOT vartype. */
- Float_t coordsX[3] = {-1};
- Float_t coordsY[3] = {-1};
- bool verbose(true);
- string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* English only */
- /* You can specify an offset here to add white space around the render */
- int offset = 0;
- int size = 26 + (offset*2);
- /* Determine whether character is an English alphabetic letter or a number.
- Returns -1 if it's a number, the position in the alphabet if a letter. */
- int letterpos (char input) {
- int pos = -1;
- for (int i=0; i<alphabet.length(); i++) {
- if (input == alphabet[i]) {
- pos = i;
- }
- }
- return pos;
- }
- /* error-check string (content can only be spaces or letters) */
- bool stringOK (string input) {
- /* check for non-letter/space content */
- for (int i=0; i<input.length(); i++) {
- if ((letterpos(input[i]) == -1) && (input[i] != ' ')) {
- cout << "Failed check at " << i << " (" << input[i]
- << ", " << letterpos(input[i]) << ")" << endl;
- return false;
- }
- }
- /* check that letters are in groupings of 6 */
- int count(0);
- for (int i=0; i<input.length(); i++) {
- if (input[i] != ' ') {
- count++;
- } else {
- if (count != 6) {
- cout << "Found a word not of length 6." << endl;
- return false;
- } else {
- count = 0;
- }
- }
- }
- return true;
- }
- /* count how many 'words' are in input */
- int wordcount (string input) {
- int words(1);
- for (int i=0; i<input.length(); i++) {
- if (input[i] == ' ') {
- words++;
- }
- }
- return words;
- }
- /* Do the actual decoding */
- int decode (string input) {
- if (verbose) {cout << input << " --> ";}
- int t=0;
- for (int i=0; i<input.length(); i+=2) {
- coordsX[t] = letterpos(input[i]) + offset;
- coordsY[t] = letterpos(input[i+1]) + offset;
- t++;
- }
- for (int i=0; i<(input.length()/2); i++) {
- if (verbose) {
- cout << setw(2) << coordsX[i] << "," << setw(2) << coordsY[i] << " ";
- if (i == ((input.length()/2)-1)) {cout << endl;}
- }
- }
- return 1;
- }
- string intstr (int input) {
- stringstream convert;
- string output;
- convert << input;
- output = convert.str();
- convert.str("");
- return output;
- } //convert int to string
- /* main program starts here */
- int artdecode () {
- string input("");
- cout << "String to decode (case insensitive, one line): ";
- getline(cin, input);
- /* convert string to uppercase */
- for (int i=0; i<input.length(); i++) {
- input[i] = toupper(input[i]);
- }
- if (!stringOK(input)) {
- cout << "Input can only contain letters and spaces." << endl;
- return 0;
- }
- /* We will not be using Fill(), so a TH2C will suffice */
- TH2C *Message = new TH2C("Message","Decoded Message",size,0,size,size,0,size);
- Message->Draw();
- gStyle->SetOptStat(0); /* remove stats box */
- int wcount(0);
- string group("");
- for (int i=0; i<input.length(); i+=7) {
- for (int ii=0; ii<6; ii++) {
- group[ii] = input[i+ii];
- }
- wcount++;
- decode(group.c_str());
- /* Draw decoded triangle. Be ye warned, ROOT shading can be weird */
- TPolyLine *triangle = new TPolyLine(3,coordsX,coordsY);
- triangle->SetFillColor(kGray);
- triangle->SetLineColor(kBlack);
- triangle->SetLineWidth(3);
- triangle->Draw("f");
- triangle->Draw();
- }
- cout << "Done." << endl;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment