If you're seeing this message, it means we're having trouble loading external resources on our website.

তোমার যদি কোন ওয়েব ফিল্টার দেওয়া থাকে, তাহলে দয়া করে নিশ্চিত কর যে *.kastatic.org এবং *.kasandbox.org ডোমেইনগুলো উন্মুক্ত।

মূল বিষয়বস্তু

পারলিন নয়েজ (Perlin noise)

A good random number generator produces numbers that have no relationship and show no discernible pattern. As we are beginning to see, a little bit of randomness can be a good thing when programming organic, lifelike behaviors. However, randomness as the single guiding principle is not necessarily natural.
There's an algorithm that results in more natural results, and that's known as “Perlin noise". Ken Perlin developed the noise function while working on the original Tron movie in the early 1980s; he used it to create procedural textures for computer-generated effects. In 1997, Perlin won an Academy Award in technical achievement for this work. Perlin noise can be used to generate various effects with natural qualities, such as clouds, landscapes, and patterned textures like marble.
পারলিন নয়েজে অনেক বেশি দৃশ্যমান প্রাকৃতিক বৈশিষ্ট্য থাকে কারণ এটি সাধারণভাবেই একটি ক্রম তৈরি করে থাকে (“মসৃণ”) যেটা হল সুডো দৈব সংখ্যার একটি ক্রমবিন্যাস। নিচের লেখচিত্রটিতে সময়ের সাথে সাথে পারলিন নয়েজ দেখা যায়, যেখানে x-অক্ষ সময় নির্দেশ করে; বক্ররেখাটির মসৃণতার দিকে লক্ষ্য করি।
কোডের বৈশিষ্ট্যের ছবি
Figure I.5: Noise (নয়েজ)
পক্ষান্তরে, এই লেখচিত্রে সময়ের সাপেক্ষে পূর্ণ দৈব সংখ্যাগুলো দেখা যায়।
কোডের বৈশিষ্ট্যের ছবি
Figure I.6: Random (দৈব সংখ্যা)
ProcessingJS এ পারলিন নয়েজের জন্য তৈরি করা আলাদা একটি অ্যালগোরিদম আছে: সেটা হল noise() ফাংশন। noise() ফাংশনটি একটি, দুইটি কিংবা তিনটি আর্গুমেন্ট ব্যবহার করে কাজ করে, কারণ কম্পিউটারে নয়েজ একটি, দুইটি কিংবা তিনটি মাত্রা নিয়ে কাজ করে। প্রথমে একটি এক-মাত্রার নয়েজ নিয়ে কাজ করা যাক।

নয়েজ সম্পর্কে বিস্তারিতভাবে জানা (Noise Detail)

নয়েজ রেফারেন্সে (Noise reference) রয়েছে যে, নয়েজকে কয়েকটি “অক্টেভের” (octaves) মাধ্যমে হিসাব করা হয়। noiseDetail() ফাংশনটিকে কল করলে, এটি অক্টেভের সংখ্যা এবং অক্টেভগুলোর একে অপরের মধ্যে থাকা সম্পর্কের গুরুত্ব - দুইটি বিষয়ই পরিবর্তন করে ফেলে।
Consider drawing a circle in our ProcessingJS window at a random x-location:
var x = random(0, width);
ellipse(x, 180, 16, 16);
এখন, x-এর যে কোন অবস্থানের পরিবর্তে, আমরা x-অবস্থানের জন্য একটি পারলিন নয়েজ চাই যেটা অনেক বেশি “মসৃণ (smoother) হবে।” এখানে হয়তো মনে হতে পারে, এখানে থাকা সবগুলো random() কে noise() দিয়ে প্রতিস্থাপিত করা হবে, উদাহরণস্বরূপ-
var x = noise(0, width);
ellipse(x, 180, 16, 16);
তত্ত্বগতভাবে আমরা এটাই করতে চাই—পারলিন নয়েজ অনুযায়ী 0 এবং প্রস্থের মধ্যে থাকা একটি x-এর মান হিসাব করতে চাই—কিন্তু এটি সঠিক কাজ নয়। যেভাবে random() ফাংশনে আর্গুমেন্টের মাধ্যমে সর্বনিম্ন এবং সর্বোচ্চ মানের একটি রেঞ্জ ঠিক করে দেওয়া হয়, noise() ফাংশনটি এইরকমভাবে কাজ করে না। noise() ফাংশনে এমন একটি আর্গুমেন্ট পাঠাতে হয় যা "যে কোন সময়ের," (moment in time) তাৎপর্য বহন করে এবং সবসময় 0 এবং 1 এর ভিতরে যে কোন একটি মান রিটার্ন করে।  আমরা এক-মাত্রার পারলিন নয়েজকে এমনভাবে চিন্তা করতে পারি যা রৈখিক ক্রমানুসারে সময়ের মানকে প্রকাশ করে। এখানে কিছু ইনপুট মান এবং তার থেকে পাওয়া রিটার্ন মানের কিছু উদাহরণ দেওয়া হল:
TimeNoise Value
00.469
0.010.480
0.020.492
0.030.505
0.040.517
এখন ProcessingJS এ থাকা যে কোন একটি নয়েজের মান পাওয়ার জন্য, আমাদেরকে noise() ফাংশনে সময়ের একটি নির্দিষ্ট মুহূর্ত পাঠাতে হবে। উদাহরণস্বরূপ:
var n = noise(0.03);
According to the above table, noise() will return 0.505 at the time of 0.03. We can write a program that stores a time variable and requests that noise value continuously in draw().
The above code results in the same value printed over and over. This happens because we are asking for the result of the noise() function at the same point in time over and over.
If we increment the time variable t, however, we’ll get a different result.
The rate at which we increment t also affects the smoothness of the noise. If we make large jumps in time, then we are skipping ahead and the values will be more random.
সময়ের সাথে noise
চিত্র 1.7
t এর জন্য- 0.01, 0.02, 0.05, 0.1, 0.0001 এই মানগুলো ব্যবহার করে, উপরের এই কোডটি বেশ কয়েকবার রান করা হলে বিভিন্ন রকম ফলাফল খুঁজে পাওয়া যেতে পারে।

নয়েজ ম্যাপিং করা (Mapping Noise)

Now we’re ready to answer the question of what to do with the noise value. Once we have the value with a range between 0 and 1, it’s up to us to map that range to what we want.
We could just multiply by the max number in the range, but this is also a good opportunity to introduce the ProcessingJS’s map() function, which will help us in more situations later on. The map() function takes five arguments. First up is the value we want to map, in this case n. Then we have to give it the value’s current range (minimum and maximum), followed by our desired range.
কোডের বৈশিষ্ট্যের ছবি
চিত্র I.8
আমরা জানি যে, নয়েজের রেঞ্জ থাকে 0 এবং 1 এর মধ্যে কিন্তু আমরা এখন 0 থেকে বর্তমান প্রস্থের মধ্যে একটি চতুর্ভুজ আঁকাতে চাই।
আমরা এলোমেলোভাবে চলা (random walker) অবজেক্টে একই যুক্তি (logic) ব্যবহার করে পারলিন নয়েজ অনুযায়ী x- এবং y-এর মানগুলো ব্যবহার করতে পারি।
Notice how the above example requires an additional pair of variables: tx and ty. This is because we need to keep track of two time variables, one for the x-location of the Walker object and one for the y-location.
But there is something a bit odd about these variables. Why does tx start at 0 and ty at 10,000? While these numbers are arbitrary choices, we have very specifically initialized our two time variables with different values. This is because the noise function is deterministic: it gives you the same result for a specific time t each and every time. If we asked for the noise value at the same time t for both x and y, then x and y would always be equal, meaning that the Walker object would only move along a diagonal. Instead, we simply use two different parts of the noise space, starting at 0 for x and 10,000 for y so that x and y can appear to act independently of each other.
কোডের বৈশিষ্ট্যের ছবি
চিত্র I.9
সত্যি হল, সময় এখানে কোন ভূমিকা পালন করছে না। এটা আমাদের নয়েজ ফাংশনটি কীভাবে কাজ করে তা বুঝতে সাহায্য করছে। কিন্তু আমাদের কাছে যেটা আছে সেটা হল স্থান, সময় নয়। উপরের লেখচিত্রটি একটি এক-মাত্রিক স্থানে, নয়েজ মানের জন্য একটি রৈখিক ধারা প্রকাশ করছে আর আমরা একটি নির্দিষ্ট x-অবস্থানের জন্য একটি মান চাইতে পারি। উদাহরণস্বরূপ, মাঝেমধ্যেই আমরা xoff নামে একটি চলক খুঁজে পাব, যেটা t সময়ের পরিবর্তে, নয়েজ গ্রাফের সাথে সাথে x-offset কেও চিহ্নিত করবে, (ডায়াগ্রামে উল্লেখিত)।
পরবর্তী অনুশীলনীগুলোতে আমরা Walker এর সাথে নয়েজ নিয়ে একটু ভিন্নভাবে অনুশীলন করার চেষ্টা করবো।

এই "প্রাকৃতিক সিমুলেশন" কোর্সটি নেওয়া হয়েছে Daniel Shiffman (ড্যানিয়েল শিফম্যান) এর লেখা "The Nature of Code" (কোডের প্রকৃতি) থেকে এবং এটি ক্রিয়েটিভ কমন্সের এট্রিবিউশন-নন কমার্শিয়াল 3.0 আনপোরটেড লাইসেন্সের অধিনস্ত।

আলোচনায় অংশ নিতে চাও?

কোন আলাপচারিতা নেই।
ইংরেজি জানো? খান একাডেমির ইংরেজি সাইটে আরো আলোচনা দেখতে এখানে ক্লিক কর।