Skip to content

Instantly share code, notes, and snippets.

@azproduction
Forked from 140bytes/LICENSE.txt
Created January 8, 2012 11:34
Show Gist options
  • Save azproduction/1578062 to your computer and use it in GitHub Desktop.
Save azproduction/1578062 to your computer and use it in GitHub Desktop.
140byt.es -- Click ↑↑ fork ↑↑ to play!
// all arguments in _meters_
function /*bokeh*/(
a, // distance to target
b, // circle of confusion @see https://gist.github.com/gists/1327415 - z_coc.js for details
c, // aperture (f/2.8 - 2.8 etc)
d, // lenses focal
f, // camera sensor height @see https://gist.github.com/gists/1327415 - z_sensor.js for details
x, // distance from target to background, default 1e6 (only finity positive number is allowed)
z
){
x = x || 1e6;
return x / ((z = ((a * f / d) / f + 1) * d) + x) * d * d / c / (z - d) / b
};
function(a,b,c,d,e,f,g){return f=f||1e6,f/((g=(a*e/d/e+1)*d)+f)*d*d/c/(g-d)/b}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mikhail Davydov <azazel.private@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "bokeh_calculator",
"description": "A bokeh number (background blur value) calculator",
"keywords": [
"bokeh",
"photo",
"calculator"
]
}
<!DOCTYPE html>
<title>Photo Frame</title>
<div>Expected value: <b>55.0600902713579</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
var CIRCLES_OF_CONFUSION = {
"Canon 5D (Mark II)": 0.03
/* ... */
};
var SENSOR_SIZES = {
"Canon 5D (Mark II)": [36, 24]
/* ... */
};
var CAMERA_NAME = "Canon 5D (Mark II)",
DISTANCE = 3, // m
COC = CIRCLES_OF_CONFUSION[CAMERA_NAME], // mm
APERTURE = 2.8,
FOCAL = 135, // mm
DISTANCE_FROM_TARGET_TO_BACKGROUND = 10, // m
SENSOR_HEIGHT = SENSOR_SIZES[CAMERA_NAME][1]; // mm
var bokeh = function(a,b,c,d,e,f,g){return f=f||1e6,f/((g=(a*e/d/e+1)*d)+f)*d*d/c/(g-d)/b};
var result = bokeh(DISTANCE, COC / 1e3, APERTURE, FOCAL / 1e3, SENSOR_HEIGHT / 1e3, DISTANCE_FROM_TARGET_TO_BACKGROUND);
document.getElementById("ret").innerHTML = result;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment