साधारण शोर वाली पीढ़ी


27

मैं शोर उत्पन्न करने के लिए देख रहा हूँ जो इस प्रकार है:

यहाँ छवि विवरण दर्ज करेंयहाँ छवि विवरण दर्ज करें

(छवियाँ पेर्लिन नॉइज़ के सौजन्य से )

मैं मूल रूप से बहुत सारे छोटे "तरंग" के साथ शोर की तलाश कर रहा हूं। निम्नलिखित अवांछनीय है:

यहाँ छवि विवरण दर्ज करें

क्या ऐसा करने के लिए कोई सरल तरीके हैं? मैं अब एक सप्ताह के लिए पेर्लिन और सिम्प्लेक्स देख रहा हूं और मुझे यह कभी भी जावास्क्रिप्ट में काम करने के लिए नहीं मिल सकता है, या जब मैं करता हूं, मेरे पास इस तरह की छवियां उत्पन्न करने के लिए सही पैरामीटर नहीं हैं, या यह पूरी तरह से है धीमी गति से।

मैं समझता हूं कि मेरे द्वारा पोस्ट की गई 3 छवियां शायद एक ही एल्गोरिदम द्वारा प्राप्त की जा सकती हैं, लेकिन एक अलग पैमाने पर, लेकिन मुझे उस एल्गोरिथ्म की आवश्यकता नहीं है। आदर्श रूप में पहली छवि में कुछ हासिल करने के लिए मुझे बस एक बहुत ही सरल एल्गोरिथ्म की आवश्यकता है। शायद किसी तरह का धुंधला काम करेगा, लेकिन मैं परिणाम का प्रबंधन नहीं कर सकता।

मैं इसे जावास्क्रिप्ट में विकसित कर रहा हूं लेकिन किसी भी प्रकार का कोड या यहां तक ​​कि एक सरल और विस्तृत विवरण काम करेगा।


3
FYI करें, आप जो चाहते हैं वह स्पष्ट रूप से पेरलिन शोर है। आपके द्वारा उल्लेखित "अवांछनीय" प्रभाव में एक दूसरे से जोड़े जाने वाले पेर्लिन शोर के कई सप्तक शामिल हैं (इसे कभी-कभी भग्न शोर कहा जाता है)। क्या आपको वास्तव में सिर्फ एक छवि की आवश्यकता है, या क्या आप चाहते हैं कि यह समय के साथ बदले? यदि हां, तो आप किस प्रभाव के बाद हैं?
सैम होसेवर

@SamHocevar मैं इसे मक्खी पर उत्पन्न करना चाहता हूं। मैं इस प्रश्न में उल्लिखित चीज़ को पुन: पेश करना चाह रहा हूँ ।
Xeon06

मुझे यह जेएस पर्लिन शोर कार्यान्वयन मिला और इसे एक jsFiddle में एकीकृत किया । हालांकि, परिणाम फ्लैश में पेर्लिन शोर कार्यान्वयन से काफी अलग है, जो मुझे फ्लैश के साथ आने वाले पेर्लिन-शोर जनरेटर के कार्यान्वयन विवरण के बारे में आश्चर्यचकित करता है।
बुमज़ैक

@bummzack वास्तव में, ऐसा लगता है कि फ्लैश जनरेटर मेरे उद्देश्य के लिए एकदम सही शोर उत्पन्न करता है। मुझे आपके द्वारा पोस्ट की गई फ़िडल के साथ काम करने का एक अच्छा तरीका नहीं मिल सकता है।
Xeon06

मुझे इसमें भी दिलचस्पी है, इसलिए मैंने स्टैकओवरफ्लो पर एक सवाल रखा । उम्मीद है कि हमें वहाँ कुछ उत्तर मिलेंगे।
बुमज़ैक

जवाबों:


16

हालांकि मौजूदा उत्तर प्रश्न को दिखाने वाले चित्रों को प्राप्त करने का एक अच्छा तरीका प्रदान करते हैं, लेकिन टिप्पणियों से पता चलता है कि लक्ष्य नीचे दिखाए गए चित्र को उत्पन्न करना है:

पर्लिन शोर अशांति

इस तरह का शोर प्रश्न की छवियों में दिखाए गए शोर से काफी अलग है, क्योंकि यह करीब अलग-अलग बूँदें बनाता है।

यह बताता है कि इस तरह के शोर को अशांति कहा जाता है जो ( इस सीपीयू रत्न लेख के अनुसार ) इस प्रकार से लागू किया जाता है (जहां noiseआपका पेरलिन-शोर फ़ंक्शन -1..1 से मान लौटाता है):

double turbulence(double x, double y, double z, double f) {
    double t = -.5;
    for ( ; f <= W/12 ; f *= 2) // W = Image width in pixels
        t += abs(noise(x,y,z,f) / f);
    return t;
}

ऊपर बताए गए अशांति समारोह के साथ इस जावास्क्रिप्ट पेर्लिन-शोर कार्यान्वयन को ऊपर उठाने से शोर उत्पन्न होता है जो ऊपर की छवि के समान है:

अशांति का शोर

जावास्क्रिप्ट कोड जो ऊपर की छवि बनाने के लिए उपयोग किया गया था वह इस jsFiddle में पाया जा सकता है ।


3
यह कुछ अजीब कोड है, जावास्क्रिप्ट संस्करण जावा संस्करण से काफी अलग है, और जावास्क्रिप्ट संस्करण मूल रूप से लिखने का एक पूरी तरह से अजीब तरीका है return Math.abs(this.noise(x,y,z)*2)-.5
aaaaaaaaaaaa

@aaaaaaaaaaaa इसे केन पेरलिन ने खुद लिया, उन्होंने कोड के उस विशेष ब्लॉक को लिखा।
b1nary.atr0phy

15

आपके उदाहरण चित्र गुलाबी शोर की तरह दिखते हैं। यह इस तरह उत्पन्न होता है:

  • सबसे पहले, हमारे पास किसी प्रकार का एक यादृच्छिक यादृच्छिक शोर है। आमतौर पर, यह पूर्णांक निर्देशांक के साथ बिंदुओं पर गणना छद्म-यादृच्छिक मानों द्वारा प्राप्त की जाती है, और इन मूल्यों को किसी तरह प्रक्षेपित करती है। इस स्तर पर परिणाम इस तरह दिखता है:

    यहाँ छवि विवरण दर्ज करें

  • अगला, हम इस शोर को लेते हैं और इसकी आवृत्ति को "निचोड़ते हैं"। इसके लिए सबसे सरल सूत्र n2 (x, y) = n1 (x f, y f) है। इस तरह, दोनों ही दिशाओं में शोर पैटर्न को कई बार निचोड़ा जाता है। नियमित रूप से ब्रेक अप करने के लिए बेहतर शोर एल्गोरिदम भी इस कदम पर शोर पैटर्न को घुमाते हैं और / या अनुवाद करते हैं।

  • फिर, इस निचोड़ा हुआ पैटर्न को कुछ मूल्य (1 से कम) से गुणा किया जाता है और पहले पैटर्न में जोड़ा जाता है। वास्तव में, हम निम्न-आवृत्ति पैटर्न के शीर्ष पर छोटे उच्च-आवृत्ति भिन्नता जोड़ते हैं। परिणाम थोड़े इस तरह दिखता है:

    यहाँ छवि विवरण दर्ज करें

  • चरण 2 और 3 को कई बार दोहराया जा सकता है, बारीक और बारीक विवरण जोड़ते हैं। शुद्ध परिणाम आमतौर पर रेड क्रॉस के साथ आपके उदाहरण जैसा दिखता है। हालाँकि, ध्यान दें कि हमारे एल्गोरिथ्म में 3 पैरामीटर हैं जिनके साथ खेलना है:

    • अष्टक गणना - या, दूसरे शब्दों में, पीढ़ी में चरणों की संख्या। अधिक चरणों का अर्थ है परिणामी पैटर्न में बारीक विवरण।
    • हठ। यह वह मूल्य है जो हर चरण में गुणा किया जाता है। आमतौर पर, दृढ़ता 0 और 1. के बीच होती है। उच्च दृढ़ता वाले मान आमतौर पर बहुत कम विस्तार के साथ "शोर" पैटर्न उत्पन्न करते हैं। कम दृढ़ता सूक्ष्म विस्तार के साथ चिकनी पैटर्न बनाता है।
    • Lacunarity। यह "निचोड़" गुणांक है जिसका उपयोग हम हर चरण में करते हैं। परोपकारिता थोड़ी-सी दृढ़ता के समान काम करती है, लेकिन वास्तव में नहीं। कम लचरता स्मूथ पैटर्न का निर्माण करती है, और उच्च ल्युनेरिटी अधिक तेज और उच्च विपरीत बनाता है।

यहाँ कुछ उदाहरण हैं:

उच्च दृढ़ता: उच्च दृढ़ता का शोर

उच्च लघुकृति: ऊँचे स्वर का शोर

निम्नतरता: कम लखपन शोर

इन मापदंडों के साथ खेलना केवल एक चीज नहीं है जो आप कर सकते हैं। एक अच्छी तकनीक जो चरित्र को शोर पैटर्न में जोड़ सकती है, वह है पर्टबर्न का उपयोग करना जोड़ सकती है, वह है , अर्थात, अपने शोर फ़ंक्शन के इनपुट निर्देशांक में कुछ शोर जोड़ें।

उदाहरण के लिए, मान लें कि आपके पास कुछ फ़ंक्शन है जो दिए गए निर्देशांक और यादृच्छिक बीज को शोर उत्पन्न करता है Noise(x,y, seed):। थान से आप Noise(x+Noise(x,y,234), y+Noise(x,y,6544), seed)पेरटर्ड वैल्यू प्राप्त करने के लिए कुछ का उपयोग कर सकते हैं । यह इस तरह के पैटर्न को जन्म दे सकता है (परिक्रमा को यहां परिपत्र पैटर्न पर लागू किया जाता है, शोर करने के लिए नहीं):

अशांति

यदि आप अधिक जानकारी प्राप्त करना चाहते हैं, तो मेरा सुझाव है कि आप libnoise (C ++) या CoherentNoise (C #) पर एक नज़र डालें । दुर्भाग्य से, मैं किसी भी जावास्क्रिप्ट शोर पीढ़ी पुस्तकालय का पता नहीं है।


6

कोड टिप्पणी की है। इसका श्रेय सीन मैककुलर को जाता है। http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf

// Ported from Stefan Gustavson's java implementation
// http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
// Read Stefan's excellent paper for details on how this code works.
//
// Sean McCullough banksean@gmail.com

/**
* You can pass in a random number generator object if you like.
* It is assumed to have a random() method.
*/
var SimplexNoise = function(r) {
if (r == undefined) r = Math;
  this.grad3 = [[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],
                                 [1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],
                                 [0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]];
  this.p = [];
  for (var i=0; i<256; i++) {
this.p[i] = Math.floor(r.random()*256);
  }
  // To remove the need for index wrapping, double the permutation table length
  this.perm = [];
  for(var i=0; i<512; i++) {
this.perm[i]=this.p[i & 255];
}

  // A lookup table to traverse the simplex around a given point in 4D.
  // Details can be found where this table is used, in the 4D noise method.
  this.simplex = [
    [0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0],
    [0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0],
    [0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],
    [1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0],
    [1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0],
    [0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],
    [2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0],
    [2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]];
};

SimplexNoise.prototype.dot = function(g, x, y) {
return g[0]*x + g[1]*y;
};

SimplexNoise.prototype.noise = function(xin, yin) {
  var n0, n1, n2; // Noise contributions from the three corners
  // Skew the input space to determine which simplex cell we're in
  var F2 = 0.5*(Math.sqrt(3.0)-1.0);
  var s = (xin+yin)*F2; // Hairy factor for 2D
  var i = Math.floor(xin+s);
  var j = Math.floor(yin+s);
  var G2 = (3.0-Math.sqrt(3.0))/6.0;
  var t = (i+j)*G2;
  var X0 = i-t; // Unskew the cell origin back to (x,y) space
  var Y0 = j-t;
  var x0 = xin-X0; // The x,y distances from the cell origin
  var y0 = yin-Y0;
  // For the 2D case, the simplex shape is an equilateral triangle.
  // Determine which simplex we are in.
  var i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
  if(x0>y0) {i1=1; j1=0;} // lower triangle, XY order: (0,0)->(1,0)->(1,1)
  else {i1=0; j1=1;} // upper triangle, YX order: (0,0)->(0,1)->(1,1)
  // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
  // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
  // c = (3-sqrt(3))/6
  var x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
  var y1 = y0 - j1 + G2;
  var x2 = x0 - 1.0 + 2.0 * G2; // Offsets for last corner in (x,y) unskewed coords
  var y2 = y0 - 1.0 + 2.0 * G2;
  // Work out the hashed gradient indices of the three simplex corners
  var ii = i & 255;
  var jj = j & 255;
  var gi0 = this.perm[ii+this.perm[jj]] % 12;
  var gi1 = this.perm[ii+i1+this.perm[jj+j1]] % 12;
  var gi2 = this.perm[ii+1+this.perm[jj+1]] % 12;
  // Calculate the contribution from the three corners
  var t0 = 0.5 - x0*x0-y0*y0;
  if(t0<0) n0 = 0.0;
  else {
    t0 *= t0;
    n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
  }
  var t1 = 0.5 - x1*x1-y1*y1;
  if(t1<0) n1 = 0.0;
  else {
    t1 *= t1;
    n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1);
  }
  var t2 = 0.5 - x2*x2-y2*y2;
  if(t2<0) n2 = 0.0;
  else {
    t2 *= t2;
    n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2);
  }
  // Add contributions from each corner to get the final noise value.
  // The result is scaled to return values in the interval [-1,1].
  return 70.0 * (n0 + n1 + n2);
};

// 3D simplex noise
SimplexNoise.prototype.noise3d = function(xin, yin, zin) {
  var n0, n1, n2, n3; // Noise contributions from the four corners
  // Skew the input space to determine which simplex cell we're in
  var F3 = 1.0/3.0;
  var s = (xin+yin+zin)*F3; // Very nice and simple skew factor for 3D
  var i = Math.floor(xin+s);
  var j = Math.floor(yin+s);
  var k = Math.floor(zin+s);
  var G3 = 1.0/6.0; // Very nice and simple unskew factor, too
  var t = (i+j+k)*G3;
  var X0 = i-t; // Unskew the cell origin back to (x,y,z) space
  var Y0 = j-t;
  var Z0 = k-t;
  var x0 = xin-X0; // The x,y,z distances from the cell origin
  var y0 = yin-Y0;
  var z0 = zin-Z0;
  // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
  // Determine which simplex we are in.
  var i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
  var i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
  if(x0>=y0) {
    if(y0>=z0)
      { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } // X Y Z order
      else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } // X Z Y order
      else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } // Z X Y order
    }
  else { // x0<y0
    if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } // Z Y X order
    else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } // Y Z X order
    else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } // Y X Z order
  }
  // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
  // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
  // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
  // c = 1/6.
  var x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
  var y1 = y0 - j1 + G3;
  var z1 = z0 - k1 + G3;
  var x2 = x0 - i2 + 2.0*G3; // Offsets for third corner in (x,y,z) coords
  var y2 = y0 - j2 + 2.0*G3;
  var z2 = z0 - k2 + 2.0*G3;
  var x3 = x0 - 1.0 + 3.0*G3; // Offsets for last corner in (x,y,z) coords
  var y3 = y0 - 1.0 + 3.0*G3;
  var z3 = z0 - 1.0 + 3.0*G3;
  // Work out the hashed gradient indices of the four simplex corners
  var ii = i & 255;
  var jj = j & 255;
  var kk = k & 255;
  var gi0 = this.perm[ii+this.perm[jj+this.perm[kk]]] % 12;
  var gi1 = this.perm[ii+i1+this.perm[jj+j1+this.perm[kk+k1]]] % 12;
  var gi2 = this.perm[ii+i2+this.perm[jj+j2+this.perm[kk+k2]]] % 12;
  var gi3 = this.perm[ii+1+this.perm[jj+1+this.perm[kk+1]]] % 12;
  // Calculate the contribution from the four corners
  var t0 = 0.6 - x0*x0 - y0*y0 - z0*z0;
  if(t0<0) n0 = 0.0;
  else {
    t0 *= t0;
    n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0, z0);
  }
  var t1 = 0.6 - x1*x1 - y1*y1 - z1*z1;
  if(t1<0) n1 = 0.0;
  else {
    t1 *= t1;
    n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1, z1);
  }
  var t2 = 0.6 - x2*x2 - y2*y2 - z2*z2;
  if(t2<0) n2 = 0.0;
  else {
    t2 *= t2;
    n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2, z2);
  }
  var t3 = 0.6 - x3*x3 - y3*y3 - z3*z3;
  if(t3<0) n3 = 0.0;
  else {
    t3 *= t3;
    n3 = t3 * t3 * this.dot(this.grad3[gi3], x3, y3, z3);
  }
  // Add contributions from each corner to get the final noise value.
  // The result is scaled to stay just inside [-1,1]
  return 32.0*(n0 + n1 + n2 + n3);
};

इसके अलावा, अगर आप इसके साथ एक PRNG का उपयोग करते हैं तो आप आसानी से आसानी से प्राप्त होने वाले परिणाम प्राप्त कर सकते हैं

/*
  I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
  so it's better encapsulated. Now you can have multiple random number generators
  and they won't stomp all over eachother's state.

  If you want to use this as a substitute for Math.random(), use the random()
  method like so:

  var m = new MersenneTwister();
  var randomNumber = m.random();

  You can also call the other genrand_{foo}() methods on the instance.

  If you want to use a specific seed in order to get a repeatable random
  sequence, pass an integer into the constructor:

  var m = new MersenneTwister(123);

  and that will always produce the same random sequence.

  Sean McCullough (banksean@gmail.com)
*/

/* 
   A C-program for MT19937, with initialization improved 2002/1/26.
   Coded by Takuji Nishimura and Makoto Matsumoto.

   Before using, initialize the state by using init_genrand(seed)  
   or init_by_array(init_key, key_length).

   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
   All rights reserved.                          

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

     1. Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

     2. Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.

     3. The names of its contributors may not be used to endorse or promote 
        products derived from this software without specific prior written 
        permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


   Any feedback is very welcome.
   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/

var MersenneTwister = function(seed) {
  if (seed == undefined) {
    seed = new Date().getTime();
  } 
  /* Period parameters */  
  this.N = 624;
  this.M = 397;
  this.MATRIX_A = 0x9908b0df;   /* constant vector a */
  this.UPPER_MASK = 0x80000000; /* most significant w-r bits */
  this.LOWER_MASK = 0x7fffffff; /* least significant r bits */

  this.mt = new Array(this.N); /* the array for the state vector */
  this.mti=this.N+1; /* mti==N+1 means mt[N] is not initialized */

  this.init_genrand(seed);
}  

/* initializes mt[N] with a seed */
MersenneTwister.prototype.init_genrand = function(s) {
  this.mt[0] = s >>> 0;
  for (this.mti=1; this.mti<this.N; this.mti++) {
      var s = this.mt[this.mti-1] ^ (this.mt[this.mti-1] >>> 30);
   this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253)
  + this.mti;
      /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
      /* In the previous versions, MSBs of the seed affect   */
      /* only MSBs of the array mt[].                        */
      /* 2002/01/09 modified by Makoto Matsumoto             */
      this.mt[this.mti] >>>= 0;
      /* for >32 bit machines */
  }
}

/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
/* slight change for C++, 2004/2/26 */
MersenneTwister.prototype.init_by_array = function(init_key, key_length) {
  var i, j, k;
  this.init_genrand(19650218);
  i=1; j=0;
  k = (this.N>key_length ? this.N : key_length);
  for (; k; k--) {
    var s = this.mt[i-1] ^ (this.mt[i-1] >>> 30)
    this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525)))
      + init_key[j] + j; /* non linear */
    this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */
    i++; j++;
    if (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; }
    if (j>=key_length) j=0;
  }
  for (k=this.N-1; k; k--) {
    var s = this.mt[i-1] ^ (this.mt[i-1] >>> 30);
    this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941))
      - i; /* non linear */
    this.mt[i] >>>= 0; /* for WORDSIZE > 32 machines */
    i++;
    if (i>=this.N) { this.mt[0] = this.mt[this.N-1]; i=1; }
  }

  this.mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */ 
}

/* generates a random number on [0,0xffffffff]-interval */
MersenneTwister.prototype.genrand_int32 = function() {
  var y;
  var mag01 = new Array(0x0, this.MATRIX_A);
  /* mag01[x] = x * MATRIX_A  for x=0,1 */

  if (this.mti >= this.N) { /* generate N words at one time */
    var kk;

    if (this.mti == this.N+1)   /* if init_genrand() has not been called, */
      this.init_genrand(5489); /* a default initial seed is used */

    for (kk=0;kk<this.N-this.M;kk++) {
      y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk+1]&this.LOWER_MASK);
      this.mt[kk] = this.mt[kk+this.M] ^ (y >>> 1) ^ mag01[y & 0x1];
    }
    for (;kk<this.N-1;kk++) {
      y = (this.mt[kk]&this.UPPER_MASK)|(this.mt[kk+1]&this.LOWER_MASK);
      this.mt[kk] = this.mt[kk+(this.M-this.N)] ^ (y >>> 1) ^ mag01[y & 0x1];
    }
    y = (this.mt[this.N-1]&this.UPPER_MASK)|(this.mt[0]&this.LOWER_MASK);
    this.mt[this.N-1] = this.mt[this.M-1] ^ (y >>> 1) ^ mag01[y & 0x1];

    this.mti = 0;
  }

  y = this.mt[this.mti++];

  /* Tempering */
  y ^= (y >>> 11);
  y ^= (y << 7) & 0x9d2c5680;
  y ^= (y << 15) & 0xefc60000;
  y ^= (y >>> 18);

  return y >>> 0;
}

/* generates a random number on [0,0x7fffffff]-interval */
MersenneTwister.prototype.genrand_int31 = function() {
  return (this.genrand_int32()>>>1);
}

/* generates a random number on [0,1]-real-interval */
MersenneTwister.prototype.genrand_real1 = function() {
  return this.genrand_int32()*(1.0/4294967295.0); 
  /* divided by 2^32-1 */ 
}

/* generates a random number on [0,1)-real-interval */
MersenneTwister.prototype.random = function() {
  return this.genrand_int32()*(1.0/4294967296.0); 
  /* divided by 2^32 */
}

/* generates a random number on (0,1)-real-interval */
MersenneTwister.prototype.genrand_real3 = function() {
  return (this.genrand_int32() + 0.5)*(1.0/4294967296.0); 
  /* divided by 2^32 */
}

/* generates a random number on [0,1) with 53-bit resolution*/
MersenneTwister.prototype.genrand_res53 = function() { 
  var a=this.genrand_int32()>>>5, b=this.genrand_int32()>>>6; 
  return(a*67108864.0+b)*(1.0/9007199254740992.0); 
} 

/* These real versions are due to Isaku Wada, 2002/01/09 added */

0

पूर्व-निर्मित बनावट का उपयोग करें, या एक सर्वर पर एक पेरीलिन शोर बनावट जनरेटर रखें और इसे पर्लिन शोर छवियों के लिए क्वेरी करें।


मैं सर्वर पर पहले से ही ऐसा कर रहा हूं, और मुझे टेक्सचर जेनरेट करने की जरूरत है।
Xeon06

यदि आप सर्वर पर ऐसा कर रहे हैं, तो जावास्क्रिप्ट की आवश्यकता क्यों है? आप किन अन्य तकनीकों का उपयोग कर सकते हैं?
सैम होसेवर

@SamHocevar मैं इसे सर्वर पर जावास्क्रिप्ट में कर रहा हूं। Node.js.
Xeon06

@ Xenon06: यदि आप प्रदर्शन के बाद हैं, तो मुझे वास्तव में लगता है कि आपको मूल कोड की आवश्यकता होगी; शुक्र है कि आप C ++ में Node.js एक्सटेंशन लिख सकते हैं ।
सैम होसेवर

@SamHcece कूल, इस लिंक के लिए धन्यवाद, मैं इसकी जांच करूँगा कि क्या मेरा
परफेक्ट
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.