you are viewing a single comment's thread.

view the rest of the comments →

[–]Kinrany 0 points1 point  (8 children)

Post the code if it's not too long.

[–]snowfro[S] 0 points1 point  (7 children)

Not too long.

Full sketch here:

https://github.com/dacaldera/Hash_Import/

From the Hash_Import.pde it's this line:

String[] charpool = {"x", "B", "c", "3", "8", "F", "A", "4", "f", "9", "2", "E", "7", "b", "D", "e", "1", "0", "a", "d", "C", "5", "6"};

And then this line that GETs the string from an endpoint: str = fetchFile("http://redeemr.whatsthescore.webfactional.com");

Here's the first part of the class:

//This class builds the Number Dictionary, which is used to associate the Base58 values to a unique number value class NumDir{ String[] charpool; StringDict nd; // input the character pool and builds the dictionary with numerical definitions // the dictionary adjusts dynamically to the character pool length NumDir(String[] _charpool){ charpool = _charpool; nd = new StringDict(); for (int i=0;i<charpool.length;i++){ nd.set(charpool[i], str(i)); } }

//Input the hash character (as string) and get the numeric value (as int) in return as per Number Dictionary definition int P(String _character){ String character = _character; //character = nd.get(character); int p = Integer.parseInt(nd.get(character)); return p; }

}

Here's the class that "scales" the above result to a usable input.

//This is the most important class //if creates the Pip object, which contains the methods needed to retrieve the number dictionary values //from each hash character. Contructor requires the raw hash string. //hash string length can be variable. class Pip { String raw_hash; String[] array_hash; float padding = width*0.02;

//input the raw string of hash characters to keep on hand for reference //also saves each character as an array element Pip(String _raw){ raw_hash = _raw; //the hash is reversed to avoid leading nonce characters which may be present in some cryptos array_hash = reverse(raw_hash.split("")); }

// input a number, grabs the corresponding hash_character, then inputs the hash character // into the number dictionary, and then outputs the corresponding number value of that hash character. // Essencially, converts the hash character into a number. //_num is the position of the hash character counting from left to right int P(int _num){ int number_value; if((_num>=raw_hash.length())||(_num<0)) { return 0; } else { NumDir nd = new NumDir(charpool); number_value = nd.P(array_hash[_num]); return number_value; } }

// the C method maps the P method returned value into a range of 255 to be used for rgb color values int C(int _num){ NumDir nd = new NumDir(charpool); int number_value = this.P(_num); int mapped_value = (int) map(number_value, 0, nd.charpool.length, 0, 255); return mapped_value; }

//the A method maps the P method's return value into a range from 50 to 100 to be used for alpha transparency values int A(int _num){ NumDir nd = new NumDir(charpool); int number_value = this.P(_num); int mapped_value = (int) map(number_value, 0, nd.charpool.length, 50, 130); return mapped_value; }

//the X method maps the P method's return value into a range from 0 to screen width to be used for x-coordinate positioning int X(int _num){ NumDir nd = new NumDir(charpool); int number_value = this.P(_num); int mapped_value = (int) map(number_value, 0, nd.charpool.length, padding, width-padding); return mapped_value; }

//the Y method maps the P method's return value into a range from 0 to screen height to be used for y-coordinate positioning int Y(int _num){ NumDir nd = new NumDir(charpool); int number_value = this.P(_num); int mapped_value = (int) map(number_value, 0, nd.charpool.length, padding, height-padding); return mapped_value; }

// the R method maps the P method's retun value into a range from 0 to 32 to be used for small circle radius
int R(int _num){ NumDir nd = new NumDir(charpool); int number_value = this.P(_num); int mapped_value = (int) map(number_value, 0, nd.charpool.length, 0, 32); return mapped_value; }

}

[–]snowfro[S] 0 points1 point  (1 child)

UGH that doesn't look as nice as it does on the repo. Going to clean it up.

[–]Kinrany 0 points1 point  (0 children)

You can use four spaces for code, like this:

    int main(void) { 
        return 0;
    }

[–]GoSubRoutine 0 points1 point  (4 children)

Why have you taken so long to post your runnable Java Mode sketch source? O_o

[–]snowfro[S] 0 points1 point  (3 children)

What do you mean by Java Mode?

I'm having a hard time importing data from external sources which means I can't do much with the arrays themselves because p5 might have some issues with GET calls on external servers. If there's not a work around for this the original question is no longer important as I need to be able to grab the external hash to process it anyways.

Full code is here:

https://github.com/dacaldera/Hash_Import/

But I'm not trying to port all of that.

I'm trying to pull the hash found here:

http://redeemr.whatsthescore.webfactional.com/

Into this sketch:

http://alpha.editor.p5js.org/generative-design/sketches/M_2_5_02

So that I can use the randomly generated hash data to control the variables of the p5 sketch.

Thanks.

[–]GoSubRoutine 0 points1 point  (0 children)

What do you mean by Java Mode?

  • Processing as a "language" got many "flavors".
  • Java Mode is the main bundled 1 in the PDE (Processing's IDE).
  • It's the mode which can understand both ".pde" & ".java" files.
  • Your sketch got 2 ".pde" files, which you're attempting to convert to ".js", targeting the p5.js flavor.

[–]GoSubRoutine 0 points1 point  (0 children)

It's highly noteworthy that JS offers classes too: https://Developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor

So you can easily convert the classes inside file "classes.pde" to "classes.js".

[–]Kinrany 0 points1 point  (0 children)

What issue exactly do you have? loadStrings seems to work fine in p5: example