Code
= ({
input_domains x_in: _.range(-3,3.001,0.25),
y_in: _.range(-3.5,5.001,0.25),
})
= calcudata({
data models:[main],
input_cursors: [{}],
,
input_domainsoutputs:['f']
})
data
Some functions I just canโt resist.
See Also: A different method to a heart visualization is on my blog.
This function appears in a neat video about marching squares (skip to 17:20)
The function is:
Data:
= ({
input_domains x_in: _.range(-3,3.001,0.25),
y_in: _.range(-3.5,5.001,0.25),
})
= calcudata({
data models:[main],
input_cursors: [{}],
,
input_domainsoutputs:['f']
})
data
Visualized using Plot:
= Plot.plot({
viewof plot color: {legend: true, reverse: true, label: `f(x_in,y_in)`},
x: { label:'x_in', tickFormat:d3.format('.2f'), ticks:_.uniq(data.map(d => d.x_in))},
y: { label: 'y_in', tickFormat:d3.format('.2f'), ticks:_.uniq(data.map(d => d.y_in))},
marks: [
.contour(data, { // https://observablehq.com/plot/marks/contour
Plotx: "x_in",
y: "y_in",
fill: "value", interpolate: Plot.interpolateNearest,blur,
interval
})
]
})
= Inputs.range([1,10],{value:4,label: 'contour intervals', step:0.1})
viewof interval
= Inputs.range([0,50],{value:4,label: 'blur', step:0.5}) viewof blur
There is only one formula/function of note in this calculang model: f(x_in,y_in)
. As usually for calculang model source code, you can see it by going to Developer Tools (Ctrl+Shift+I) and navigating to the .cul.js
files (Ctrl+P and search .cul.js
).
Alternatively, select this models entrypoint (below) in calculang devtools ๐ ๏ธ๐งฐ
import { calcudata } from "@declann/little-calcu-helpers"
= require('vega-embed');
embed
= Inputs.select(['models/heart/heart-contour.cul.js'], {label:'entrypoint'})
viewof entrypoint
= entrypoint.slice(0,-7)
entrypoint_no_cul_js
= require(`../../${entrypoint_no_cul_js}.js`);
main
= await fetch(`../../${entrypoint_no_cul_js}.introspection.json`)
introspection_fetch
= introspection_fetch.json({typed:true})
introspection
= Object.values(introspection.cul_functions).filter(d => d.reason == 'input definition').map(d => d.name).sort()
inputs
= Object.values(introspection.cul_functions).filter(d => d.reason == 'definition').map(d => d.name)
formulae
// formulae excluding pure inputs
= Object.values(introspection.cul_functions).filter(d => d.reason == 'definition' && inputs.indexOf(d.name+'_in') == -1).map(d => d.name) formulae_not_inputs