Skip to content

Commit ae4d5fd

Browse files
committed
Some cleanup in css3d molecules example.
1 parent 4832470 commit ae4d5fd

1 file changed

Lines changed: 16 additions & 47 deletions

File tree

examples/css3d_molecules.html

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,7 @@
129129
baseSprite.onload = function () {
130130

131131
loadMolecule( "models/molecules/caffeine.pdb" );
132-
133-
function generateButtonCallback( url ) {
134-
135-
return function ( event ) {
136-
137-
loadMolecule( url );
138-
139-
}
140-
141-
}
142-
143-
for ( var m in MOLECULES ) {
144-
145-
var button = document.createElement( 'button' );
146-
button.innerHTML = m;
147-
menu.appendChild( button );
148-
149-
var url = "models/molecules/" + MOLECULES[ m ];
150-
151-
button.addEventListener( 'click', generateButtonCallback( url ), false );
152-
153-
}
132+
createMenu();
154133

155134
};
156135

@@ -164,40 +143,34 @@
164143

165144
//
166145

167-
function parseColor( colorString ) {
168-
169-
// default to white opaque
146+
function generateButtonCallback( url ) {
170147

171-
var r, g, b, a;
172-
r = g = b = a = 1;
148+
return function ( event ) {
173149

174-
var matchRGBA = reRGBA.exec( colorString );
150+
loadMolecule( url );
175151

176-
if ( matchRGBA ) {
152+
}
177153

178-
r = parseInt( matchRGBA[ 1 ] ) / 255;
179-
g = parseInt( matchRGBA[ 2 ] ) / 255;
180-
b = parseInt( matchRGBA[ 3 ] ) / 255;
181-
a = parseFloat( matchRGBA[ 4 ] );
154+
}
182155

183-
} else {
156+
function createMenu() {
184157

185-
var matchRGB = reRGB.exec( colorString );
158+
for ( var m in MOLECULES ) {
186159

187-
if ( matchRGB ) {
160+
var button = document.createElement( 'button' );
161+
button.innerHTML = m;
162+
menu.appendChild( button );
188163

189-
r = parseInt( matchRGB[ 1 ] ) / 255;
190-
g = parseInt( matchRGB[ 2 ] ) / 255;
191-
b = parseInt( matchRGB[ 3 ] ) / 255;
164+
var url = "models/molecules/" + MOLECULES[ m ];
192165

193-
}
166+
button.addEventListener( 'click', generateButtonCallback( url ), false );
194167

195168
}
196169

197-
return { "r": r, "g": g, "b": b, "a": a };
198-
199170
}
200171

172+
//
173+
201174
function colorify( ctx, width, height, color, a ) {
202175

203176
var r = color.r;
@@ -247,8 +220,6 @@
247220

248221
function loadMolecule( url ) {
249222

250-
//console.log( "loading", url );
251-
252223
for ( var i = 0; i < objects.length; i ++ ) {
253224

254225
scene.remove( objects[ i ] );
@@ -268,7 +239,7 @@
268239
var color = geometry.colors[ i ];
269240
var element = geometry.elements[ i ];
270241

271-
if ( !colorSpriteMap[ element ] ) {
242+
if ( ! colorSpriteMap[ element ] ) {
272243

273244
var canvas = imageToCanvas( baseSprite );
274245
var context = canvas.getContext( '2d' );
@@ -296,8 +267,6 @@
296267

297268
}
298269

299-
//console.log( "atoms", geometry.vertices.length );
300-
301270
render();
302271

303272
} );

0 commit comments

Comments
 (0)