memoscan
← all memos

Memo 0x9cdd2cb3…fddaee on Ethereum

// Aragnation let num_categories = 4, num_colors_per_palette = 17, Nx, Ny, num_prototypes, pattern = new Array(), mask_gen = new Array(), color_pattern = new Array(), noise_vector = new Array(), palettes; class Random { constructor() { this.useA = false; let sfc32 = function(uint128Hex) { let a = parseInt(uint128Hex.substr(0, 8), 16); let b = parseInt(uint128Hex.substr(8, 8), 16); let c = parseInt(uint128Hex.substr(16, 8), 16); let d = parseInt(uint128Hex.substr(24, 8), 16); return function() { a |= 0; b |= 0; c |= 0; d |= 0; let t = (((a + b) | 0) + d) | 0; d = (d + 1) | 0; a = b ^ (b >>> 9); b = (c + (c << 3)) | 0; c = (c << 21) | (c >>> 11); c = (c + t) | 0; return (t >>> 0) / 4294967296; }; }; // seed prngA with first half of tokenData.hash this.prngA = new sfc32(tokenData.hash.substr(2, 32)); // seed prngB with second half of tokenData.hash this.prngB = new sfc32(tokenData.hash.substr(34, 32)); for (let i = 0; i < 1e6; i += 2) { this.prngA(); this.prngB(); } } // random number between 0 (inclusive) and 1 (exclusive) random_dec() { this.useA = !this.useA; return this.useA ? this.prngA() : this.prngB(); } // random number between a (inclusive) and b (exclusive) random_num(a, b) { return a + (b - a) * this.random_dec(); } // random integer between a (inclusive) and b (inclusive) // requires a < b for proper probability distribution random_int(a, b) { return Math.floor(this.random_num(a, b + 1)); } // random boolean with p as percent liklihood of true random_bool(p) { return this.random_dec() < p; } // random value in an array of items random_choice(list) { return list[this.random_int(0, list.length - 1)]; } } // From https://gist.github.com/dmitric/0de47d734bd1747158fd3b11f482e884 // Artblocks injects the tokenData variable into your sketch like so // let tokenData = {"hash":"0xf445bc56ff81a55f2ece1536eecf9972469048c04f778570b12ed664a9053590","tokenId":"123000456"} console.log(tokenData.hash) // your random seed let seed = generate_seed_from_token_data(tokenData); // the ID of the token let tokenId = parseInt(tokenData.tokenId.substring(2)) rnd = new Random(seed); function generate_seed_from_token_data(token) { return parseInt(token.hash.slice(0, 16), 16) } function setup_params_from_token(token) { let hashPairs = [] for (let j = 0; j < 32; j++) { hashPairs.push(token.hash.slice(2 + (j * 2), 4 + (j * 2))) } return hashPairs.map(x => { return parseInt(x, 16) }) } function calculateFeatures(tokenData) { let p = setup_params_from_token(tokenData), pid = 0; let pick_using_param = (choices, param) => choices[parseInt(map(param, 0, 256, 0, choices.length))]; let feats = {}; feats.texture = pick_using_param(["gradient", "plain"], p[pid++]); feats.reflection = pick_using_param(["yes", "no", "no", "no"], p[pid++]); feats.colors = pick_using_param(SAMPLE_COLOR_OPS, p[pid++]); feats.palette = palette_names[pick_using_param([...Array(palettes.length).keys()], p[pid++])]; feats.bg_style = bg_style_names[pick_using_param([...Array(4).keys()], p[pid++])]; generate_masks_colors_noise(feats.colors); feats.subject = category_names[infer_category()]; return feats; } function setup() { start = Date.now(); /************************************************************************* * Boilerplate: aspect ratio, margin, pixel density, seed, etc. *************************************************************************/ ar = 3 / 4, mult = 1.0; pixelDensity(2); if (windowWidth >= ar * windowHeight) { h = mult * windowHeight, w = ar * mult * windowHeight; } else { h = mult * windowWidth / ar, w = mult * windowWidth; } pt = h / 1000; // Use to set for stroke widths. margin = w / 15; createCanvas(w, h); // randomSeed(seed); noiseSeed(seed); console.log(w, h, seed); /*************************************************************************/ /************************************************************************* * Scene configs, color palettes *************************************************************************/ category_names = ["landscape", "flower", "urban", "bird"]; bg_style_names = ["graph", "rods and cones", "marble", "fabric"]; palette_names = ["v1", "indian", "american", "australian", "british", "canadian", "chinese", "dutch", "french", "german", "russian", "spanish", "swedish", "turkish"]; palettes = [ // from model // all_colors, // v1 [[41, 128, 185],[52, 152, 219],[26, 188, 156],[44, 62, 80],[39, 174, 96],[52, 73, 94],[142, 68, 173],[22, 160, 133],[127, 140, 141],[211, 84, 0],[155, 89, 182],[149, 165, 166],[189, 195, 199],[231, 76, 60],[230, 126, 34],[241, 196, 15],[236, 240, 241]], // indian [[59, 59, 152],[27, 156, 252],[37, 204, 247],[24, 44, 97],[44, 58, 71],[130, 88, 159],[109, 33, 79],[88, 177, 159],[85, 230, 193],[179, 55, 113],[189, 197, 129],[154, 236, 219],[202, 211, 200],[249, 127, 81],[254, 164, 127],[234, 181, 67],[248, 239, 186]], // american [[9, 132, 227],[116, 185, 255],[0, 206, 201],[45, 52, 54],[0, 184, 148],[108, 92, 231],[225, 112, 85],[99, 110, 114],[162, 155, 254],[255, 118, 117],[178, 190, 195],[129, 236, 236],[223, 230, 233],[214, 48, 49],[253, 203, 110],[255, 234, 167],[250, 177, 160]], // australian [[48, 51, 107],[104, 109, 224],[34, 166, 179],[19, 15, 64],[106, 176, 76],[72, 52, 212],[83, 92, 104],[186, 220, 88],[149, 175, 192],[240, 147, 43],[255, 121, 121],[126, 214, 223],[199, 236, 238],[235, 77, 75],[255, 190, 118],[249, 202, 36],[223, 249, 251]], // british [[39, 60, 117],[0, 151, 230],[0, 168, 255],[25, 42, 86],[68, 189, 50],[64, 115, 158],[53, 59, 72],[113, 128, 147],[72, 126, 176],[194, 54, 22],[127, 143, 166],[156, 136, 255],[220, 221, 225],[232, 65, 24],[225, 177, 44],[251, 197, 49],[245, 246, 250]], // canadian [[52, 31, 151],[46, 134, 222],[1, 163, 164],[34, 47, 62],[16, 172, 132],[95, 39, 205],[87, 101, 116],[29, 209, 161],[84, 160, 255],[238, 82, 83],[131, 149, 167],[72, 219, 251],[200, 214, 229],[255, 107, 107],[255, 159, 67],[254, 202, 87],[255, 159, 243]], // chinese [[55, 66, 250],[30, 144, 255],[123, 237, 159],[47, 53, 66],[46, 213, 115],[83, 82, 237],[87, 96, 111],[116, 125, 140],[112, 161, 255],[255, 71, 87],[255, 107, 129],[164, 176, 190],[206, 214, 224],[255, 99, 72],[255, 127, 80],[236, 204, 104],[241, 242, 246]], // dutch [[0, 98, 102],[6, 82, 221],[18, 203, 196],[27, 20, 100],[0, 148, 50],[18, 137, 167],[111, 30, 81],[131, 52, 113],[87, 88, 187],[234, 32, 39],[181, 52, 113],[153, 128, 250],[217, 128, 250],[238, 90, 36],[247, 159, 31],[255, 195, 18],[253, 167, 223]], // french [[30, 55, 153],[56, 173, 169],[7, 153, 146],[12, 36, 97],[10, 61, 98],[60, 99, 130],[183, 21, 64],[96, 163, 188],[106, 137, 204],[235, 47, 6],[229, 142, 38],[130, 204, 221],[248, 194, 145],[229, 80, 57],[250, 152, 58],[246, 185, 59],[250, 211, 144]], // german [[56, 103, 214],[45, 152, 218],[38, 222, 129],[75, 101, 132],[32, 191, 107],[119, 140, 163],[235, 59, 90],[15, 185, 177],[75, 123, 236],[250, 130, 49],[136, 84, 208],[165, 177, 194],[165, 94, 234],[252, 92, 101],[253, 150, 68],[254, 211, 48],[209, 216, 224]], // russian [[87, 75, 144],[84, 109, 229],[61, 193, 211],[48, 57, 82],[99, 205, 218],[89, 98, 117],[196, 69, 105],[120, 111, 166],[119, 139, 235],[225, 95, 65],[207, 106, 135],[119, 139, 235],[248, 165, 194],[230, 103, 103],[241, 144, 102],[245, 205, 121],[247, 215, 148]], // spanish [[34, 112, 147],[52, 172, 224],[51, 217, 178],[44, 44, 84],[33, 140, 116],[71, 71, 135],[64, 64, 122],[132, 129, 122],[112, 111, 211],[179, 57, 57],[204, 174, 98],[170, 166, 157],[209, 204, 192],[255, 82, 82],[255, 121, 63],[255, 177, 66],[247, 241, 227]], // swedish [[60, 64, 198],[15, 188, 249],[0, 216, 214],[30, 39, 46],[5, 196, 107],[87, 95, 207],[72, 84, 96],[128, 142, 155],[52, 231, 228],[255, 63, 52],[239, 87, 119],[75, 207, 250],[255, 221, 89],[255, 94, 87],[255, 192, 72],[255, 211, 42],[210, 218, 226]], // turkish [[125, 95, 255],[23, 192, 235],[24, 220, 255],[61, 61, 61],[58, 227, 116],[113, 88, 226],[75, 75, 75],[50, 255, 126],[103, 230, 220],[255, 56, 56],[197, 108, 240],[126, 255, 245],[255, 184, 184],[255, 77, 77],[255, 175, 64],[255, 242, 0],[255, 204, 204]] ]; // model.js mask_model = [[3,19,22,23,39,45,49],[[2,27,33,35,40,42,45],[2,27,39,41,42],[31,33,35,39,40,41,42],[11,12,32,33,35,39,40,41,42,50],[2,11,35,39,40,41,42,50],[19,27,31,35,39,40,45],[2,5,14,22,33,35,50],[],[11,21,31,36,41,42,43,46],[4,15,19],[2,5,6,27,35,39,42],[4,22,27,33,35,41,42,50],[1,6,26,41,42,46,50],[2,4,27,39,40,41,42,45],[2,14,31,40,41],[],[4,6,15],[],[33,35,39,41,42,45],[1,2,14,26,27,39,42,45],40,[32,33,35,41,42,50],[33,35,41,42,50],[],[],[2,3,4,15,19,27,35,40,45],[2,4,11,27,31,40,41,42],[4,14,15,33,39,40,41,42,45],35,[],[2,6,27,31,33,41,42,49],[4,22,33,35],[4,5,12,19,22],[6,11,18,21,46],[2,11,12,19,22,32,39,50],[],[],[1,2,6,11,12,21,26],[2,14,19,27,39,40,42],[1,2,4,5,14,42],[2,3,11,12,22,32,42],[2,4,5,19,22,40,41],[],[12,31,40,41,46],[1,2,11,14,19],36,[],[],[4,5,11,12,22],[2,5,12,19,22,35]],[[2,27,35,40,41,42,43],[2,6,11,21,27,3