Commit 4458c41a authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

rastering with height map z

parent cebddea1
......@@ -35,6 +35,7 @@ var init = function() {
var inputs = {
map:{type:'',label:'height map',
event:function(evt){
mod.map = evt.detail.map
mod.width = evt.detail.width
mod.height = evt.detail.height
mod.xmin = evt.detail.xmin
......@@ -214,11 +215,19 @@ var interface = function(div){
// 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
//
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')
svg.removeChild(g)
var g = document.createElementNS('http://www.w3.org/2000/svg','g')
......@@ -228,29 +237,34 @@ function calculate_path() {
// line loop
//
var ix = 0
var iy = mod.height-1
var iy = h-1
var dx = 1
var dy = 0
//var x2 = mod.xmin+(mod.xmax-mod.xmin)*ix/(mod.width-1)
//var y2 = mod.ymin+(mod.ymax-mod.ymin)*iy/(mod.height-1)
var x = xmin+(xmax-xmin)*ix/(w-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) {
var ixp = ix
var iyp = iy
var dzp = dz
ix += dx
iy += dy
var line = document.createElementNS('http://www.w3.org/2000/svg','line')
line.setAttribute('stroke','black')
line.setAttribute('stroke-width',1)
line.setAttribute('stroke-linecap','round')
line.setAttribute('x1',ixp)
line.setAttribute('y1',iyp)
line.setAttribute('x2',ix)
line.setAttribute('y2',iy)
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;
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')
line.setAttribute('stroke','black')
line.setAttribute('stroke-width',1)
line.setAttribute('stroke-linecap','round')
line.setAttribute('x1',ixp)
line.setAttribute('y1',iyp+dzp)
line.setAttribute('x2',ix)
line.setAttribute('y2',iy+dz)
g.appendChild(line)
if (ix == (mod.width-1)) {
if (dx == 1) {
dx = 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment