首页 > 其他分享 >vis.js造型曲面3d图形

vis.js造型曲面3d图形

时间:2024-04-23 18:13:52浏览次数:27  
标签:function style colormap 50 js vis var options 3d

  • 代码案例
<!DOCTYPE html>
<html>
  <head>
    <title>Graph 3D demo</title>
    <style>
        body {
          font: 10pt arial;
        }

        fieldset {
          width: fit-content;
        }

        fieldset > div {
          float: left;
        }

        fieldset > div + div {
          margin-left: 100px;
        }
    </style>
    <script
      type="text/javascript"
      src="https://unpkg.com/vis-graph3d@latest/dist/vis-graph3d.min.js"
    ></script>
    <script type="text/javascript">
        var data = null;
        var graph = null;

        function custom(x, y) {
          return Math.sin(x / 50) * Math.cos(y / 50) * 50 + 50;
        }

        // Called when the Visualization API is loaded.
        function drawVisualization() {
          var radioButtons = document.getElementsByName("style");
          var selectedRadio = null;
          radioButtons.forEach(function (radioButton) {
            if (radioButton.checked === true) {
              selectedRadio = radioButton;
            }
          });
          const style = (selectedRadio && selectedRadio.value) || null;

          // Create and populate a data table.
          data = new vis.DataSet();
          // create some nice looking data with sin/cos
          var counter = 0;
          var steps = 50; // number of datapoints will be steps*steps
          var axisMax = 314;
          var axisStep = axisMax / steps;
          for (var x = 0; x < axisMax; x += axisStep) {
            for (var y = 0; y < axisMax; y += axisStep) {
              var value = custom(x, y);
              data.add({ id: counter++, x: x, y: y, z: value, style: value });
            }
          }

          // specify options
          var options = {
            width: "600px",
            height: "600px",
            style: "surface",
            showPerspective: true,
            showGrayBottom: true,
            showGrid: true,
            showShadow: true,
            showSurfaceGrid: false,
            keepAspectRatio: true,
            verticalRatio: 0.5,
          };

          if (style === "default") {
            options.colormap = ["#000FFF", "#68E8FB", "#00FF00", "#FFF000", "#FF0000"];
          } else if (style === "function") {
            options.colormap = function (x) {
              return { r: 255 * x, g: 0, b: 0, a: (1 + x) / 2 };
            };
          } else if (style === "hue") {
            options.colormap = {
              hue: {
                start: 360,
                end: -360,
                saturation: 50,
                brightness: 100,
                colorStops: 8, // How many colour gradients do we want
              },
            };
          } else if (style === "html") {
            options.colormap = ["#000000", "#6A0DAD", "#FFFFFF"];
          } // else use defaults.

          // Instantiate our graph object.
          var container = document.getElementById("mygraph");
          graph = new vis.Graph3d(container, data, options);
        }

        window.addEventListener("load", () => {
          drawVisualization();
        });

    </script>
  </head>
  <body onl oad="drawVisualization();">
    <fieldset>
      <legend>Select Style</legend>
      <div>
        <input
          type="radio"
          name="style"
          id="defaultStyle"
          value="default"
          checked="checked"
          onchange="drawVisualization();"
        />
        <label for="defaultStyle">Default Configuration: </label>
        <!-- <code>
          <pre>
    colormap: [
      '#000FFF',
      '#68E8FB',
      '#00FF00',
      '#FFF000',
      '#FF0000',
    ]</pre
          >
        </code> -->
      </div>
    
      <div>
        <input
          type="radio"
          name="style"
          id="functionStyle"
          value="function"
          onchange="drawVisualization();"
        />
        <label for="functionStyle">Function Configuration:</label>
        <!-- <code>
          <pre>
    colormap: function(x) {
      return {r: 255*x, g: 0, b: 0, a: (1+x)/2};
    }</pre
          >
        </code> -->
      </div>
    
      <div>
        <input
          type="radio"
          name="style"
          id="hueStyle"
          value="hue"
          onchange="drawVisualization();"
        />
        <label for="hueStyle">Hue Configuration:</label>
        <!-- <code>
          <pre>
    colormap: {
      hue: {
        start: 360,
        end: -360,
        saturation: 50,
        brightness: 100,
        colorStops: 8,
      }
    }</pre
          >
        </code> -->
      </div>
    
      <div>
        <input
          type="radio"
          name="style"
          id="htmlStyle"
          value="html"
          onchange="drawVisualization();"
        />
        <label for="htmlStyle">HTML Hex Configuration:</label>
        <!-- <code>
          <pre>
    colormap: [
      '#000000',
      '#6A0DAD',
      '#FFFFFF',
    ]</pre
          >
        </code> -->
      </div>
    </fieldset>
    
    <div id="mygraph"></div>    
      
  </body>
</html>
  • 效果图
点击查看详情

标签:function,style,colormap,50,js,vis,var,options,3d
From: https://www.cnblogs.com/dogleftover/p/18153476

相关文章

  • vis.js可动的3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>html,body{font:10ptarial;padding:0;margin:0;width:100%;hei......
  • vis.js表面值3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}</style><scripttype="text/javascript"src=......
  • Web3开发者技术选型:前端视角(next.js)
    引言在现代Web开发的世界中,Web3技术的兴起为前端开发者开辟了新的可能性。Web3技术主要指的是建立在区块链基础上的分布式网络,使用户能够通过智能合约和去中心化应用(DApps)直接交互,而无需传统的中介机构。为了有效地开发Web3应用,前端开发者需要掌握一些关键的技术和工具,其中Next.j......
  • JS逆向
    断点调试的几种办法一、文件流程断点首先以一个登录界面举例说明,抓取登录的数据包.载荷处存在加密的数据 在启动器处可以查看调用堆栈,这个登录请求,大致分析是处在中间位置发生了加密,所以跟一下Login 之后在代码前加入断点,并登录 发现加密数据是在Login处有,匿名处没......
  • [转] JS运算符 &&和|| 及其优先级
    [转]JS运算符&&和||及其优先级:https://blog.csdn.net/banyu0052/article/details/101946098?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7EPaidSort-1-101946098-blog-82424825.235%5Ev43%5Ep......
  • 原生js base64格式数据 下载
    原生jsbase64格式数据下载/***封装base64Strblob对象**/functionbase64toBlob(base64Str){varbstr=atob(base64Str),n=bstr.length,u8arr=newUint8Array(n);while(n--){u8arr[n]=bstr.charCodeAt(n);}returnnewBlob([u8arr]);}/......
  • 【前端】纯JS实现文本对比高亮显示
    1.参考demo1-1、连接:http://incaseofstairs.com/jsdiff/1-2、例子:2.页面<!DOCTYPEhtml><!--savedfromurl=(0033)http://incaseofstairs.com/jsdiff/--><html><head><metahttp-equiv="Content-Type"content="text/html;chars......
  • react-native-vision-camera 扫二维码报错 [unknown/unknown] Waiting for the barcod
    1.问题:使用react-native-vision-camera库扫描解析二维码时,部分手机出现如下报错:2.解决:android/app/build.gradle文件中添加依赖:dependencies{//...implementation'com.google.mlkit:barcode-scanning:17.2.0'}3.参考:GitHub相关issues......
  • 前端在浏览器显示摄像头传回的RTSP视频流,前端采用的技术有VUE+video.js+flv.js
    在前端使用Vue.js框架,结合video.js和flv.js播放RTSP视频流,需要经过一系列步骤,因为浏览器并不能直接播放RTSP流,所以通常需要一个服务器来将RTSP流转为HLS或FLV格式,然后前端再通过flv.js播放。以下是一个基于此思路的基本实现指南:确保你已经安装了Vue.js、video.js、flv.js相关的依......
  • JS基础(二)运算符、流程控制语句、数组对象、JSON对象、Date对象、Math对象、Function对
    一运算符<script>//算数运算符//(1)自加运算varx=10;//x=x+1;//x+=2;varret=x++;//先赋值再计算:x+=1//varret=++x;//先计算再赋值:x+=1console.log(x)......