Commit a852031d authored by Mandic's avatar Mandic
Browse files

Update colorbrewer2.html

parent c1696859
Pipeline #6430 passed with stages
in 13 seconds
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</link> </link>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/styles/vs.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style> <style>
#red, #red,
#green, #green,
...@@ -62,30 +65,41 @@ ...@@ -62,30 +65,41 @@
</X3D> </X3D>
</td> </td>
<td width="50%" align="left" valign="top" scope="col"> <td width="50%" align="left" valign="top" scope="col">
<p>The following example will show you haw to interactively modify the 3D scene.</p> <p>The following example will show you how to interactively modify the 3D scene.</p>
<div id="red"></div> <div id="red"></div>
<div id="green"></div> <div id="green"></div>
<div id="blue"></div> <div id="blue"></div>
<p> <p>
<br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br>
The diffuse color of a material will be interactively changed. The diffuse color of a material will be interactively changed.
A JavaScript <a href="https://jqueryui.com/slider/#colorpicker target=" _blank"> RGB color picker </a> is used A JavaScript <a href="http://jqueryui.com/slider/#colorpicker target=" _blank"> RGB color picker </a> is used
and modified. and modified.
If the RGB color value is changed, the diffuse material of the sphere shall be changed as well. So we need to If the RGB color value is changed, the diffuse material of the sphere shall be changed as well. So we need to
get the Material node first. get the Material node first.
This is done by the getElementById function in X3DOM. Of course, the Material node needs to have an unique id. This is done by the getElementById function in X3DOM. Of course, the Material node needs to have an unique id.
<pre> <pre>
&lt;X3D id="shapedata" width="600px" height="600px" style="float:left"&gt; <code class="language-html">
&lt;Scene&gt; &lt;html&gt;
&lt;Shape&gt; &lt;head&gt;
&lt;Appearance&gt; &lt;title&gt;colorbrewer&lt;/title&gt;
&lt;Material id="material" diffuseColor="0.980, 0.502, 0.447"&gt; &lt;/Material&gt; &lt;script type='text/javascript' src='http://www.x3dom.org/download/x3dom.js'&gt; &lt;/script&gt;
&lt;/Appearance&gt; &lt;link rel='stylesheet' type='text/css' href='http://www.x3dom.org/download/x3dom.css'&gt;&lt;/link&gt;
&lt;Sphere radius="2.0"&gt; &lt;/Sphere&gt; &lt;/head&gt;
&lt;/Shape&gt; &lt;body&gt;
&lt;/Scene&gt; &lt;X3D id="shapedata" width="600px" height="600px" style="float:left"&gt;
&lt;/X3D&gt; &lt;Scene&gt;
</pre> &lt;Shape&gt;
&lt;Appearance&gt;
&lt;Material id="material" diffuseColor="0.980, 0.502, 0.447"&gt; &lt;/Material&gt;
&lt;/Appearance&gt;
&lt;Sphere radius="2.0"&gt; &lt;/Sphere&gt;
&lt;/Shape&gt;
&lt;/Scene&gt;
&lt;/X3D&gt;
&lt;/body&gt;
&lt;/html&gt;
</code>
</pre>
<br> <br>
For example, if the diffuse color should be set to red, the Material node is referenced by its id and the For example, if the diffuse color should be set to red, the Material node is referenced by its id and the
attribute diffuseColor is set to attribute diffuseColor is set to
...@@ -102,33 +116,32 @@ ...@@ -102,33 +116,32 @@
rgbstring = " "+ red/255 + " " + green/255 + " " + blue/255; rgbstring = " "+ red/255 + " " + green/255 + " " + blue/255;
mat.setAttribute("diffuseColor", rgbstring); mat.setAttribute("diffuseColor", rgbstring);
</pre> </pre>
</p>
</td> </td>
</tr> <script type="text/javascript" src="x3dom.js"></script>
</table> <script>
<script type="text/javascript" src="x3dom.js"></script> function refreshDiffuseMaterial() {
<script> var red = $("#red").slider("value"),
function refreshDiffuseMaterial() { green = $("#green").slider("value"),
var red = $("#red").slider("value"), blue = $("#blue").slider("value");
green = $("#green").slider("value"), var mat = document.getElementById("material");
blue = $("#blue").slider("value"); rgbstring = " " + red / 255 + " " + green / 255 + " " + blue / 255;
var mat = document.getElementById("material"); mat.setAttribute("diffuseColor", rgbstring);
rgbstring = " " + red / 255 + " " + green / 255 + " " + blue / 255; }
mat.setAttribute("diffuseColor", rgbstring); $(function () {
} $("#red, #green, #blue").slider({
$(function () { orientation: "horizontal",
$("#red, #green, #blue").slider({ range: "min",
orientation: "horizontal", max: 255,
range: "min", value: 127,
max: 255, slide: refreshDiffuseMaterial,
value: 127, change: refreshDiffuseMaterial
slide: refreshDiffuseMaterial, });
change: refreshDiffuseMaterial $("#red").slider("value", 255);
}); $("#green").slider("value", 140);
$("#red").slider("value", 255); $("#blue").slider("value", 60);
$("#green").slider("value", 140); });
$("#blue").slider("value", 60); </script>
});
</script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
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