float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Written as a way to stop forgetting these things. | |
May be wrong sometimes, as it's just the result of my research here and there. | |
If it helps you, give me a shout!) | |
Ordered dithering is a technique used to reduce - deliberately! - the precision of an image. | |
Motivation : artistic (mainly ?), color quantization --> reduce the number of color in an image | |
---------------------------------------------------------------- | |
INTRODUCTION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.iquilezles.org/www/articles/palettes/palettes.htm | |
// to see this function graphed out go to: https://www.desmos.com/calculator/18rq4ybrru | |
vec3 cosPalette( float t , vec3 brightness, vec3 contrast, vec3 osc, vec3 phase) | |
{ | |
return brightness + contrast*cos( 6.28318*(osc*t+phase) ); | |
} | |
vec3 hsv2rgb(vec3 c) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$red: #FF0000 | |
$green: #00FF00 | |
$blue: #0000FF | |
$black: #000000 | |
$white: #FFFFFF | |
$gray: #808080 | |
$cyan: #00FFFF | |
$magenta: #FF00FF | |
$yellow: #FFFF00 | |
$brown: #996633 |
Generator functions are basically functions that you can pause at some point. You can define a generator function with function*
:
function* Generator() {
// code goes here
}
I like to named my generator functions with a capital, for reasons that will become apparent later, but generally they are named with a lowercase letter.
map
=> Takes an array, and then applies a function to every element of that array.filter
=> Takes an array, and passes every element through a function. It only keeps the element if the function returnstrue
.sort
=> By default, it sorts the elements of an array in alphabetical order. But, if you give it a function, it will use it to sort the array in the following way:- The function takes two arguments to compare,
a
andb
. - The function returns a negative number if
a
is lower thanb
. - The function returns zero if
a
has the same value asb
. - The function returns a positive number is
a
is higher thanb
.
- The function takes two arguments to compare,
reduce
=> Starts with an accumulator. It starts with the first element of the array. Then it goes through the rest of the elements, and for each one, it applies a function to the accumulator and the element and puts the result back into the accumulator. The function returns what the accumulator is at the end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WEBGL // p5 WEBGL rendering mode. | |
createCanvas(w, h, renderer) // Creates a 3D canvas (if renderer is WEBGL). | |
// Primitives | |
plane(width, height) // Creates a plane in 3D space. Equivalent to rect() in the default rendering mode. | |
plane(width, height, detailX, detailY) // Creates a plane in 3D space with the number of triangle subdivisions specified. | |
box(width) // Creates a cube in 3D space. | |
box(width, height, depth) // Creates a cuboid in 3D space. | |
box(width, height, depth, detailX, detailY) // Creates a cuboid in 3D space with triangle subdivisions. | |
sphere(radius) // Creates a sphere in 3D space. |