Skip to content
Snippets Groups Projects
Commit 4458c41a authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

rastering with height map z

parent cebddea1
Branches
No related tags found
No related merge requests found
...@@ -35,6 +35,7 @@ var init = function() { ...@@ -35,6 +35,7 @@ var init = function() {
var inputs = { var inputs = {
map:{type:'',label:'height map', map:{type:'',label:'height map',
event:function(evt){ event:function(evt){
mod.map = evt.detail.map
mod.width = evt.detail.width mod.width = evt.detail.width
mod.height = evt.detail.height mod.height = evt.detail.height
mod.xmin = evt.detail.xmin mod.xmin = evt.detail.xmin
...@@ -214,11 +215,19 @@ var interface = function(div){ ...@@ -214,11 +215,19 @@ var interface = function(div){
// calculate_path // calculate_path
// //
function calculate_path() { function calculate_path() {
var h = mod.height
var w = mod.width
var xmin = mod.xmin
var xmax = mod.xmax
var ymin = mod.ymin
var ymax = mod.ymax
var zmin = mod.zmin
var zmax = mod.zmax
// //
// clear SVG // clear SVG
// //
var svg = document.getElementById(mod.div.id+'svg') var svg = document.getElementById(mod.div.id+'svg')
svg.setAttribute('viewBox',"0 0 "+(mod.width-1)+" "+(mod.height-1)) svg.setAttribute('viewBox',"0 0 "+(w-1)+" "+(h-1))
var g = document.getElementById(mod.div.id+'g') var g = document.getElementById(mod.div.id+'g')
svg.removeChild(g) svg.removeChild(g)
var g = document.createElementNS('http://www.w3.org/2000/svg','g') var g = document.createElementNS('http://www.w3.org/2000/svg','g')
...@@ -228,29 +237,34 @@ function calculate_path() { ...@@ -228,29 +237,34 @@ function calculate_path() {
// line loop // line loop
// //
var ix = 0 var ix = 0
var iy = mod.height-1 var iy = h-1
var dx = 1 var dx = 1
var dy = 0 var dy = 0
//var x2 = mod.xmin+(mod.xmax-mod.xmin)*ix/(mod.width-1) var x = xmin+(xmax-xmin)*ix/(w-1)
//var y2 = mod.ymin+(mod.ymax-mod.ymin)*iy/(mod.height-1) var y = ymin+(ymax-ymin)*iy/(h-1)
var z = mod.map[(h-1-iy)*w+ix]
var dz = h*(zmax-z)/(ymax-ymin)
while (1) { while (1) {
var ixp = ix var ixp = ix
var iyp = iy var iyp = iy
var dzp = dz
ix += dx ix += dx
iy += dy iy += dy
if (iy <= 0)
break;
var x = xmin+(xmax-xmin)*ix/(w-1)
var y = ymin+(ymax-ymin)*iy/(h-1)
var z = mod.map[iy*w+ix]
var dz = 0.1*h*(zmax-z)/(zmax-zmin)
var line = document.createElementNS('http://www.w3.org/2000/svg','line') var line = document.createElementNS('http://www.w3.org/2000/svg','line')
line.setAttribute('stroke','black') line.setAttribute('stroke','black')
line.setAttribute('stroke-width',1) line.setAttribute('stroke-width',1)
line.setAttribute('stroke-linecap','round') line.setAttribute('stroke-linecap','round')
line.setAttribute('x1',ixp) line.setAttribute('x1',ixp)
line.setAttribute('y1',iyp) line.setAttribute('y1',iyp+dzp)
line.setAttribute('x2',ix) line.setAttribute('x2',ix)
line.setAttribute('y2',iy) line.setAttribute('y2',iy+dz)
g.appendChild(line) g.appendChild(line)
//var x2 = mod.xmin+(mod.xmax-mod.xmin)*ix/(mod.width-1)
//var y2 = mod.ymin+(mod.ymax-mod.ymin)*iy/(mod.height-1)
if (iy <= 0)
break;
if (ix == (mod.width-1)) { if (ix == (mod.width-1)) {
if (dx == 1) { if (dx == 1) {
dx = 0 dx = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment