some visuals for โ€˜mainโ€™ model

Heart contour map

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:

Contour visual ๐Ÿ“Š

Data:

Code
input_domains = ({
  x_in: _.range(-3,3.001,0.25),
  y_in: _.range(-3.5,5.001,0.25),
})

data = calcudata({
  models:[main],
  input_cursors: [{}],
  input_domains,
  outputs:['f']
})

data

Visualized using Plot:

Code
viewof plot = Plot.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: [
    Plot.contour(data, { // https://observablehq.com/plot/marks/contour
      x: "x_in",
      y: "y_in",
      fill: "value", interpolate: Plot.interpolateNearest,blur,
      interval
    })
  ]
})

viewof interval = Inputs.range([1,10],{value:4,label: 'contour intervals', step:0.1})

viewof blur = Inputs.range([0,50],{value:4,label: 'blur', step:0.5})
Tip

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 ๐Ÿ› ๏ธ๐Ÿงฐ

Appendix

Code
import { calcudata } from "@declann/little-calcu-helpers"
embed = require('vega-embed');

viewof entrypoint = Inputs.select(['models/heart/heart-contour.cul.js'], {label:'entrypoint'})

entrypoint_no_cul_js = entrypoint.slice(0,-7)

main = require(`../../${entrypoint_no_cul_js}.js`);

introspection_fetch = await fetch(`../../${entrypoint_no_cul_js}.introspection.json`)

introspection = introspection_fetch.json({typed:true})

inputs = Object.values(introspection.cul_functions).filter(d => d.reason == 'input definition').map(d => d.name).sort()

formulae = Object.values(introspection.cul_functions).filter(d => d.reason == 'definition').map(d => d.name)

// formulae excluding pure inputs
formulae_not_inputs = Object.values(introspection.cul_functions).filter(d => d.reason == 'definition' && inputs.indexOf(d.name+'_in') == -1).map(d => d.name)
|