web chemdoodle custom mesh - javascript

I have downloaded the Chemdoodle web components from (web.chemdoodle.com)
Below is the working sample code I have taken from the site. I want to understand the _Mesh class from the API and how to create my own Mesh and put it over that molecule. Maybe a box first or something similar but without the box function (as later I want to change the box in the custom mesh with alternate vertices and faces)
<html>
<head>
<script type="text/javascript" src="../install/ChemDoodleWeb-libs.js"></script>
<script type="text/javascript" src="../install/ChemDoodleWeb.js"></script>
<title>3D ChemDoodle Web Component using WebGL : Interactive Model ofDDT</title>
</head>
<body>
</body>
</html>
<script>
var transformerDistance = new ChemDoodle.TransformCanvas3D('transformDistance', 300, 300);
// set up visual specifications
transformerDistance.specs.set3DRepresentation('Ball and Stick');
transformerDistance.specs.backgroundColor = 'black';
transformerDistance.specs.atoms_displayLabels_3D = true;
transformerDistance.specs.shapes_color = '#fff';
// read in a water molecule
var water = new ChemDoodle.io.JSONInterpreter().molFrom({"a":[{"x":0,"y":-0.2633,"i":"a0","l":"O"},{"x":-0.8109999999999999,"y":0.2633,"i":"a1","l":"H"},{"x":0.8109999999999999,"y":0.2633,"i":"a2","l":"H"}],"b":[{"b":0,"e":1,"i":"b0"},{"b":0,"e":2,"i":"b1"}]});
// create a distance object between the hydrogen atoms
var distance = new ChemDoodle.structures.d3.Distance(water.atoms[1], water.atoms[2]);
// add the objects to the scene
</script>

Related

Geodesic polygon on GoogleMaps

I am trying to show a geodesic polygon on GoogleMaps. I thought it is enough to just add geodesic:true to polygon options. But it is displayed linearly despite its huge size. Am I doing it wrong or it is not supported ?
<html>
<head>
<script src="https://maps.google.com/maps/api/js?v=3"></script>
<script>
window.onload = function() {
var map = new google.maps.Map(document.body, {zoom:9,center:{lat:49.8,lng:18.2}});
new google.maps.Polygon({geodesic:true,map:map,
path:[{lat:50,lng:18},{lat:49.3,lng:18.5},{lat:50,lng:19}]});
}
</script>
</head>
<body style="position:absolute;width:99%;height:99%">
</body>
</html>
seems you are to centerd try move the polygon near pole
window.onload = function() {
var map = new google.maps.Map(document.body, {zoom:9,center:{lat:49.8,lng:18.2}});
new google.maps.Polygon({geodesic:true,map:map,
path:[{lat:70.0,lng:18.0},{lat:70.0,lng:22.5},{lat:50.0,lng:22.5},{lat:50.0,lng:18.0 ]} );
}
(and as suugestion use float ever)

Panolens + p5js: using image BLEND SCREEN function with SLIDERS for PANORAMA pictures

I have the following question: How to show panorama images (that can be moved with mouse, or in cardboard googles) that can have a sliders controlling an image blend between two panoramas?
Description: I am trying to make an app, where user can see a panorama image and move around in it (I used PANOLENS for it), and then using sliders be able to make the images blend with each other. The blend is made using SCREEN BLEND function (basically, as the sliders move to one side, some brighter elements from one panorama start to appear on the other panorama - so in a way, two panorama images are displayed at the same time).
I think I kinda figured the way to do it for normal rectangular images - I use p5js library with IMAGE BLEND SCREEN function with 3 sliders - it is in the script called sketch.js:
let DAYLIGHT;
let LAMPS1;
let LAMPS2;
function preload() {
DAYLIGHT = loadImage('../img/OFFICEDL.JPG');
LAMPS1 = loadImage('../img/OFFICEL2.JPG');
LAMPS2 = loadImage('../img/OFFICEL1.JPG');
}
function setup() {
canvas = createCanvas(1200,600).parent("recimage");
DAYLIGHT.resize(1200,600);
LAMPS1.resize(1200,600);
LAMPS2.resize(1200,600);
DLslider = createSlider(0, 255, 0).parent('slidersimage');
DLslider.position(10, 0).parent('slidersimage');
DLslider.style('width', '200px');
L1slider = createSlider(0, 255, 0).parent('slidersimage');
L1slider.position(10, 30).parent('slidersimage');
L1slider.style('width', '200px');
L2slider = createSlider(0, 255, 0).parent('slidersimage');
L2slider.position(10, 60).parent('slidersimage');
L2slider.style('width', '200px');
}
function draw() {
background(0);
blendMode(SCREEN);
const DLvalue = DLslider.value();
const L1value = L1slider.value();
const L2value = L2slider.value();
tint(255, 255-DLvalue);
image(DAYLIGHT,0,0);
tint(255, L1value);
image(LAMPS1,0,0);
tint(255, L2value);
image(LAMPS2,0,0);
blendMode(BLEND);
}
Now for displaying the panoramas for now I have only used a workflow from tutorial to display the panorama, and for that I load three.min.js and panolens.js, and finally in the script main.js I use tell the app to display the panorama picture:
const panoImage = document.querySelector('.pano-image');
const testPano1 = '../img/OFFICEDL.jpg';
const panorama = new PANOLENS.ImagePanorama(testPano1);
const viewer = new PANOLENS.Viewer({
container: panoImage,
});
viewer.add( panorama );
Finally, in my html it looks like this:
<!DOCTYPE html><html><head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
</head>
<body>
<h1> PANORAMA TEST</h1>
<p>
This is the panorama view of the room
</p>
<div class="centering">
<div class="pano-image"> </div>
</div>
<p>
This is the stretched out panorama (equirectangular image view) with adjustable level of lighting
</p>
<div class="centering">
<p id="recimage"></p>
<p id="slidersimage"></p>
</div>
<p>
End text
</p>
<script src="js/p5.js"></script>
<script src="js/sketch.js"></script>
<script src="js/three.min.js"></script>
<script src="js/panolens.min.js"></script>
<script src="js/main.js"></script>
</body></html>
For now, altogether there is a panorama image on the top, and equirectangular version of it on the bottom, which has the sliders controlling it. Is there a way to implement similar control to the panoramic version?
Also, a side question: my sliders do not seem to position themselves relatively to the canvas, but rather to the whole website...anyone has any tips for that?
Any help would be greatly appreciated!

Bing Maps v8 JS API

I have a very simple Bing maps program where I want to allow the user to draw one shape on the map, I've got the drawing tools and everything set up however Bing's events don't seem to fire in the correct way -
Drawing started - fires when I change my drawing tool to either a line or a polygon
Drawing Changed - fires when I change my drawing tool to either a line or a polygon
I simply want to clear the existing polygons from the map when I begin to draw a new polygon - however making a call to the getPrimitives function on the drawing manager clears the drawing mode, So then I thought about caching the drawing mode, reading the primitives to delete them and then resetting the drawing mode but then the setDrawingMode method on the drawing Manager calls the drawing started again which triggers the whole process again.
Does anyone know how to overcome this.
Does look odd that the drawing started event is firing when you click the mode. Will have the team look into that.
However, what you are trying todo would have some potential issues. If you clear the drawing manager when the user has started drawing a polygon on the map, that polygon will also be removed from the map as well. What you can do is when finished drawing a polygon, is move it to a separate layer, then you can clear that layer without effecting the drawing manager. If you are only interested in drawing polygons, you don't even need the drawing manager as you can handle this yourself using the drawing tools and a button. For example: http://bingmapsv8samples.azurewebsites.net/#DrawingTools_CreateShape
Here is a code sample that achieves what you are asking using the drawing manager:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type='text/javascript'>
var map, baseLayer, drawingManager;
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {
credentials: 'YourBingMapsKey'
});
//Load the DrawingTools module
Microsoft.Maps.loadModule('Microsoft.Maps.DrawingTools', function () {
//Create a base layer to add drawn shapes.
baseLayer = new Microsoft.Maps.Layer();
map.layers.insert(baseLayer);
//Create an instance of the DrawingTools class and bind it to the map.
var tools = new Microsoft.Maps.DrawingTools(map);
//Show the drawing toolbar and enable editting on the map.
tools.showDrawingManager(function (manager) {
drawingManager = manager;
Microsoft.Maps.Events.addHandler(drawingManager, 'drawingEnded', function (e) {
//When use finisihes drawing a shape, removing it from the drawing layer and add it to the base layer.
var shapes = drawingManager.getPrimitives();
if (shapes) {
drawingManager.clear();
baseLayer.add(shapes);
}
});
Microsoft.Maps.Events.addHandler(drawingManager, 'drawingChanging', function (e) {
//When the drawing is changing, clear the base layer.
baseLayer.clear();
});
})
});
}
</script>
<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
</head>
<body>
<div id="myMap" style="position:relative;width:600px;height:400px;"></div>
</body>
</html>
Here is a similar code sample that does this without the drawing manager and a custom button to start drawing a polygon.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type='text/javascript'>
var map, baseLayer, tools, currentShape;
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {
credentials: 'YourBingMapsKey'
});
//Create a base layer to add drawn shapes.
baseLayer = new Microsoft.Maps.Layer();
map.layers.insert(baseLayer);
//Load the DrawingTools module.
Microsoft.Maps.loadModule('Microsoft.Maps.DrawingTools', function () {
//Create an instance of the DrawingTools class and bind it to the map.
tools = new Microsoft.Maps.DrawingTools(map);
Microsoft.Maps.Events.addHandler(tools, 'drawingChanging', function (e) {
//When the drawing is changing, clear the base layer.
baseLayer.clear();
});
//When the user presses 'esc', take the polygon out of edit mode and re-add to base map.
document.getElementById('myMap').onkeypress = function (e) {
if (e.charCode === 27) {
tools.finish(shapeDrawn);
currentShape = null;
}
};
});
}
function drawPolygon() {
//Stop any current drawing.
if (currentShape) {
tools.finish(shapeDrawn);
currentShape = null;
}
//Create a new polygon.
tools.create(Microsoft.Maps.DrawingTools.ShapeType.polygon, function (s) {
currentShape = s;
});
}
function shapeDrawn(s) {
baseLayer.add(s);
}
</script>
<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
</head>
<body>
<div id="myMap" style="position:relative;width:600px;height:400px;"></div><br />
<input type="button" onclick="drawPolygon()" value="Draw Polygon" />
</body>
</html>

How to Clear entire Shape Layer in Microsoft VirtualEarth 6.3 using pure javascript?

The code snippet shown below (HTML5/javascript) loads Microsoft Bing Map (VirtualEarth 6.3), then adds two Shape layers and two sample Pushpins, one per each layer.
QUESTION: What pure javascript function (or solution) to use in order to clear all pushpins from just the 1st layer keeping the other layer intact?
Note: clear layer function should be implemented without deleting the entire layer.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bing VE Map w/layers</title>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>
<script type="text/javascript">
// VE map
var _map;
// 1st shape layer
var _layer1 ;
// 2nd shape layer
var _layer2;
function MapLoad() {
// load map
_map = new VEMap('Map');
_map.LoadMap();
// center point (Columbus Circle NY)
var _center = new VELatLong(40.7681, -73.9819);
// set center point and initial zoom level
_map.SetCenterAndZoom(_center, 12);
// set Map style
_map.SetMapStyle(VEMapStyle.Shaded);
// add 1st shape layer1 to Map obj
_layer1 = new VEShapeLayer()
_map.AddShapeLayer(_layer1);
// add 2nd shape layer2 to Map obj
_layer2 = new VEShapeLayer()
_map.AddShapeLayer(_layer2);
// add pushpin to layer1
var _pushpin1 = new VEShape(VEShapeType.Pushpin, _center);
_layer1.AddShape(_pushpin1);
// add pushpin (Apple Store on 5th) to layer2
var _pushpin2 = new VEShape(VEShapeType.Pushpin, new VELatLong(40.7639, -73.9725));
_layer2.AddShape(_pushpin2);
// QUESTION: HOW TO CLEAR ALL SHAPES FROM LAYER 1, (BUT NOT DELETING THE ENTIRE LAYER)?
}
</script>
</head>
<body onload="MapLoad();">
<div id="Map" style="position:absolute; top:100px; height:90%; width:100%;"></div>
</body>
</html>
You could use the dedicated method DeleteAllShapes() of the VEShapeLayer class, see the MSDN:
https://msdn.microsoft.com/en-us/library/bb412473.aspx
See the example:
// Delete all shapes within the layer at the selected index.
function DeleteAllShapes()
{
layer = map.GetShapeLayerByIndex(selIndex);
layer.DeleteAllShapes();
IndexChanged(selIndex);
}
Also, I would recommend to use AJAX v7.0 instead of v6.3 since it's now deprecated and due to be out of support on November 30, 2016.

The Image doesn't show up on the Canvas

<html>
<head>
<meta charset="utf-8">
<title>Game</title>
<script src="http://code.createjs.com/easeljs-0.4.2.min.js"></script>
</head>
<body>
<div id ="beeld">
<canvas id ="stageCanvas" width="1024" height="576">
<script src ="javascript.js"></script>
</canvas>
</div>
</body>
</html>
This is my Html
//Javascript Document
var canvas = document.getElementById('stageCanvas');
var stage = new Stage(canvas);
var Background;
var imgBackground = new Image();
imgBackground.src ="images/bg.png";
Background = new Bitmap(imgBackground);
Background.x = 0
Background.y = 0
stage.addChild(Background);
stage.update();
And that's my js.
The image is 1024 by 576, so it should be fullscreen. The original is 2048 by 576. I was planning to do like the background would slide to left and repeat it self when it gets to the end.
So my question is, why doesnt the image show up on the canvas.
I'm a very new to this, so I'm sorry if I'm asking such an easy question.
PS: If I inspect the HTML, it DOESN'T show any errors and it DOES show that the image is being loaded. It's just not.. drawn.. I guess.
I'm getting frustrated, because I'm stuck here for a couple hours already.
I FOUND A WORKING CODE
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Easel simple game</title>
<script src="http://code.createjs.com/easeljs-0.4.2.min.js"></script>
<script>
var canvas;
var stage;
var bg;
var score;
var ghost;
function init() {
canvas = document.getElementById("StageCanvas");
stage = new Stage(canvas);
score = 0;
bg = new Image();
bg.src = "img/bg.png";
bg.onload = setBG;
}
function setBG(event){
var bgrnd = new Bitmap(bg);
stage.addChild(bgrnd);
stage.update();
}
</script>
</head>
<body onload="init();">
<canvas id="StageCanvas" width="1240" height="576"></canvas>
</body>
</html>
By the way this code is the work for someone else, so I don't take any credit.
This seems to work perfectly. But once I remove the
bg = new Image();
bg.src = "img/bg.png";
bg.onload = setBG;
it stops working.
Background = new Bitmap(imgBackground);
In HTML:
Try to move the script-tag of your javascript.js to right before the </body> or at least not into the <canvas>...</canvas>.
And another thing is: You have a space between src and = and id and =, that might cause problems in some browsers.
In JavaScript:
You need to execute the update-method with () otherwise that line will just be a listed reference to the update function.
stage.update();
And a second thing, that I noticed(though not part of the issue): You are using EaselJS 0.4.2, but 0.5.0 is already released, just in case you want to be up-to-date: http://code.createjs.com/easeljs-0.5.0.min.js ;-)
I'm having the same issue with EaselJS at the moment. While it might work for you, you can try and add a ticker which will automatically update the canvas:
createjs.Ticker.addListener(stage);
I was able to get the image to paint on the canvas after adding this, but as soon as I add any transforms to the image (scale, positioning, height, width) they are not applied prior to the image being drawn.
I've been scratching my head over this too.

Categories