From 0c05f20b44aadc5f13deaeada42cce1c0fb970ee Mon Sep 17 00:00:00 2001 From: Neil Gershenfeld <gersh@cba.mit.edu> Date: Sat, 2 Jun 2018 15:40:30 -0400 Subject: [PATCH] wip --- files.html | 3 ++- modules/index.js | 2 +- modules/mesh/{slice => slice raster} | 28 ++++++++++++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) rename modules/mesh/{slice => slice raster} (95%) diff --git a/files.html b/files.html index 934170a..b677c47 100644 --- a/files.html +++ b/files.html @@ -19,6 +19,7 @@ <a href='./js/files.js'>files.js</a><br> <a href='./js/mods.js'>mods.js</a><br> <a href='./js/modules.js'>modules.js</a><br> +<i> node_modules</i><br> <a href='./js/printserver.js'>printserver.js</a><br> <a href='./js/programs.js'>programs.js</a><br> <a href='./js/serialserver.js'>serialserver.js</a><br> @@ -133,7 +134,7 @@ <a href='./modules/math/parallel'>parallel</a><br> <a href='./modules/math/scalar'>scalar</a><br> <i> mesh</i><br> - <a href='./modules/mesh/slice'>slice</a><br> + <a href='./modules/mesh/slice%20raster'>slice raster</a><br> <i> module</i><br> <a href='./modules/module/create'>create</a><br> <a href='./modules/module/delete'>delete</a><br> diff --git a/modules/index.js b/modules/index.js index dbbb7af..0f6ffa9 100644 --- a/modules/index.js +++ b/modules/index.js @@ -103,7 +103,7 @@ module_menu(' glsl_benchmark','modules/math/glsl_benchmark') module_menu(' parallel','modules/math/parallel') module_menu(' scalar','modules/math/scalar') module_label('mesh') -module_menu(' slice','modules/mesh/slice') +module_menu(' slice raster','modules/mesh/slice%20raster') module_label('module') module_menu(' create','modules/module/create') module_menu(' delete','modules/module/delete') diff --git a/modules/mesh/slice b/modules/mesh/slice raster similarity index 95% rename from modules/mesh/slice rename to modules/mesh/slice raster index c109051..3c48845 100644 --- a/modules/mesh/slice +++ b/modules/mesh/slice raster @@ -1,5 +1,5 @@ // -// mesh slice +// mesh slice raster // // Neil Gershenfeld // (c) Massachusetts Institute of Technology 2018 @@ -20,7 +20,7 @@ var mod = {} // // name // -var name = 'mesh slice (under development)' +var name = 'mesh slice raster' // // initialization // @@ -405,16 +405,24 @@ function worker() { // function to draw line // function line(x0,y0,x1,y1) { - var ix0 = Math.floor(w*(x0-xmin)/(xmax-xmin)) - var iy0 = Math.floor(h*(y0-ymin)/(ymax-ymin)) - var ix1 = Math.floor(w*(x1-xmin)/(xmax-xmin)) - var iy1 = Math.floor(h*(y1-ymin)/(ymax-ymin)) + var ix0 = Math.round(w*(x0-xmin)/(xmax-xmin)) + var iy0 = Math.round(h*(y0-ymin)/(ymax-ymin)) + var ix1 = Math.round(w*(x1-xmin)/(xmax-xmin)) + var iy1 = Math.round(h*(y1-ymin)/(ymax-ymin)) var dx = ix1-ix0 var dy = iy1-iy0 - console.log(ix0,iy0) - buf[(h-1-iy0)*w*4+ix0*4+0] = 255 - buf[(h-1-iy0)*w*4+ix0*4+1] = 255 - buf[(h-1-iy0)*w*4+ix0*4+2] = 255 + var ix = ix0 + var iy = iy0 + var x = x0 + var y = y0 + do { + buf[(h-1-iy)*w*4+ix*4+0] = 255 + buf[(h-1-iy)*w*4+ix*4+1] = 255 + buf[(h-1-iy)*w*4+ix*4+2] = 255 + x += dx + y += dy + ix = Math.round(w*(x0-xmin)/(xmax-xmin)) + } while (!((ix == ix0) && (iy == iy0))) } // // get vars from buffer -- GitLab