memoscan
← all memos

Memo 0xa37bb46e…4cfeca on Ethereum

let nodes = []; let nodesToDraw = 1; let nodeOrder = []; let cred = [1, 0.8, 0.76]; let cblue = [210, 0.72, 0.7]; let cyellow = [46, 0.82, 0.95]; let cwhite = [0, 0, 0.96]; let cback = [cred,cblue,cyellow,cwhite]; let _cbackTop, _cbackBottom; let _rotate; let _weightFactor; let _metaWonk; let _mirrorChance; let _xydivs; let _mirror; let _rwonk; let maxUnits = 17; let minUnits = 9; let minWonk = 0.001; let maxWonk = 0.45; let speedScalar = 0.2; let maxDistance; let xygap; let bigdim; let sameWeight; let sameThinWeight; let newBackground = true; function setup() { createCanvas(window.innerWidth, window.innerHeight, WEBGL); pixelDensity(); colorMode(HSB, 360, 1, 1, 1); r = new RND(); defineNetwork(true); setAttributes('alpha', false); } function rollDice() { _cbackBottom = int(r.rb(0, cback.length)); _cbackTop = int(r.rb(0, cback.length)); _weightFactor = r.rb(0.066, 0.15); _metaWonk = r.rb(minWonk, maxWonk); _rotate = r.rb(0, TWO_PI); _mirrorChance = r.rb(0,1); _xydivs = int(r.rb(minUnits, maxUnits)); _rwonk = r.rb(0,1); } function draw() { if (newBackground) { defineBackground(); newBackground = false; } if (nodesToDraw < nodes.length-1 && frameCount % 10 == 0) { nodesToDraw++; } push(); rotate(_rotate); for (let i = 0; i < nodesToDraw; i++) { nodes[i].displayNetwork(); } pop(); } function keyPressed() { if (key == ' ') { defineNetwork(false); } } function windowResized() { resizeCanvas(window.innerWidth, window.innerHeight); r = new RND(); defineNetwork(true); } function defineBackground() { noStroke(); beginShape(); fill(cback[_cbackTop]) vertex(-width/2, -height/2); vertex(width/2, -height/2); fill(cback[_cbackBottom]); vertex(width/2, height/2); vertex(-width/2, height/2); endShape(); } function defineNetwork(bbb) { rollDice(); if (bbb) { newBackground = true; } nodesToDraw = 1; bigdim = max(width, height); xygap = bigdim/float(_xydivs); maxDistance = dist(0, 0, bigdim, bigdim); sameWeight = xygap * _weightFactor; sameThinWeight = map(bigdim, 1920, 3840, 1.0, 2.0); sameThinWeight = max(0.5, sameThinWeight); if (_mirrorChance > 0.5 && _weightFactor > 0.1) { _mirror = true; } else { _mirror = false; } nodes = [(_xydivs+7)*(_xydivs+7)]; nodeOrder = [nodes.length]; for (let i = 0; i < nodeOrder.length; i++) { nodeOrder[i] = i; } let nodeCount = 0; let wonk = minWonk; if (_rwonk > 0.75) { wonk = maxWonk; } else if (_rwonk > 0.10) { wonk = _metaWonk; } for (let x = -3; x <= _xydivs+3; x++) { for (let y = -3; y <= _xydivs+3; y++) { let xoff = 0; if (y % 2 == 0) { xoff = -xygap/2.0; } let xx = r.rb(-xygap*wonk, xygap*wonk); let yy = r.rb(-xygap*wonk, xygap*wonk); let nx = map(x*xygap, 0, bigdim, -bigdim/2-xygap/2, bigdim/2+xygap/2); let ny = map(y*xygap, 0, bigdim, -bigdim/2-xygap/2, bigdim/2+xygap/2); nodes[nodeCount] = new Node(nx + xoff, ny, xx, yy); nodeCount++; } } shuffle(nodes, true); buildConnections(); } function buildConnections() { for (let i = 0; i < nodes.length; i++) { nodes[i].setID(i); } for (let i = 0; i < nodes.length; i++) { nodes[i].buildNetwork(nodes); } } class Node { constructor(_x, _y, _xoff, _yoff) { this.x = _x + _xoff; this.y = _y + _yoff; this.newX = this.x; this.newY = this.y; this.centerDist = dist(0, 0, this.x, this.y); this.minimDist = dist(0, 0, xygap/2, xygap/2); this.totalConnections = 0; this.currentNet = 0; this.speed = []; this.weights = []; this.baseDist = dist(0, 0, xygap+(xygap/_xydivs), xygap+(xygap/_xydivs)); this.id = 0; this.otherNodes = []; this.connections = []; this.alphaLines = []; this.sending = []; this.c = [ cyellow, cblue, cred, cwhite ]; this.easing = 0.04; this.currentC = []; this.nextC = []; } setID(_id) { this.id = _id; } buildNetwork(_others) { let potentialConnections = [_others.length]; let count = 0; for (let i = 0; i < _others.length; i++) { if (i != this.id) { let d = dist(this.x, this.y, _others[i].x, _others[i].y); if (d < this.baseDist) { potentialConnections[count] = _others[i]; count++; this.totalConnections++; } } } this.connections = subset(potentialConnections, 0, count); this.alphaLines = [this.connections.length]; this.sending = [this.connections.length]; this.speed = [this.connections.length]; this.currentC = [this.connections.length]; this.nextC = [this.connections.length]; this.weights = [this.connections.length]; this.currentNet = int(r.rb(0, this.connections.length)); let sharedColor = this.c[int(r.rb(0, this.c.length))]; for (let i = 0; i < this.connections.length; i++) { this.alphaLines[i] = 1.0; this.sending[i] = true; let distance = dist(this.x, this.y, this.connections[i].x, this.connections[i].y); this.speed[i] = map(distance, this.baseDist, this.minimDist, 0.02, 0.05); this.currentC[i] = sharedColor; this.h = hue(this.currentC[i]); this.s = saturation(this.currentC[i]); this.b = brightness(this.currentC[i]); this.nextC[i] = this.c[int(r.rb(0, this.c.length))]; this.nh = hue(this.currentC[i]); this.ns = saturation(this.currentC[i]); this.nb = brightness(this.currentC[i]); this.weights[i] = sameWeight; } } displayNetwork() { if (this.connections.length > 0 && this.currentNet >= 0) { let i = this.currentNet; if (this.alphaLines[i] > 0.0) { this.x += (this.newX-this.x) * this.easing; this.y += (this.newY-this.y) * this.easing; let nextx = map(this.alphaLines[i], 0, 1, this.connections[i].x, this.x); let nexty = map(this.alphaLines[i], 0, 1, this.connections[i].y, this.y); let sw = map(this.alphaLines[i], 0, 1, this.weights[i], 1); if (abs(nextx-this.x) > 1.0) { if (_mirror) { push(); translate(xygap*0.25, xygap*0.25); strokeWeight(sameThinWeight); stroke(this.currentC[i][0], this.currentC[i][1], this.currentC[i][2], 0.01); line(this.x, this.y, nextx, nexty); pop(); } push(); translate(this.x, this.y); let angle = atan2(nexty-this.y, nextx-this.x); rotate(angle); let d = dist(this.x, this.y, nextx, nexty); let wide = sw * 0.5; let halfWide = wide; beginShape(); noStroke(); fill(this.currentC[i][0], this.currentC[i][1], this.currentC[i][2], 0.05); vertex(0, 0); vertex(halfWide, wide); fill(this.nextC[i][0], this.nextC[i][1], this.nextC[i][2], 0.05); vertex(d-halfWide, wide); vertex(d, 0); endShape(); pop(); } } else { this.alphaLines[i] = 1.0; this.currentC[i] = this.c[int(r.rb(0, this.c.length))]; this.nextC[i] = this.c[int(r.rb(0, this.c.length))]; this.currentNet = int(r.rb(0, this.alphaLines.length)); if (this.currentNet < 0) { this.currentNet = 0; } } this.alphaLines[i] -= this.speed[i] * speedScalar; } } } class RND { 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; }; }; this.prngA = new sfc32(tokenData.hash.substr(2, 32)); this.prngB = new sfc32(tokenData.hash.substr(34, 32)); for (let i = 0; i < 1e6; i += 2) { this.prngA(); this.prngB(); } } random_dec() { this.useA = !this.useA; return this.useA ? this.prngA() : this.prngB(); } rb(a, b) { return a + (b - a) * this.random_dec(); } }