Turn a COLLADA effect into a trimesh material.
764008
def _parse_material(effect, resolver):
    

    # Compute base color
    baseColorFactor = np.ones(4)
    baseColorTexture = None
    if isinstance(effect.diffuse, collada.material.Map):
        try:
            baseColorTexture = _load_texture(
                effect.diffuse.sampler.surface.image.path, resolver)
        except BaseException:
            log.warning('unable to load base texture',
                        exc_info=True)
    elif effect.diffuse is not None:
        baseColorFactor = effect.diffuse

    # Compute emission color
    emissiveFactor = np.zeros(3)
    emissiveTexture = None
    if isinstance(effect.emission, collada.material.Map):
        try:
            emissiveTexture = _load_texture(
                effect.diffuse.sampler.surface.image.path, resolver)
        except BaseException:
            log.warning('unable to load emissive texture',
                        exc_info=True)
    elif effect.emission is not None:
        emissiveFactor = effect.emission[:3]

    # Compute roughness
    roughnessFactor = 1.0
    if (not isinstance(effect.shininess, collada.material.Map)
            and effect.shininess is not None):
        roughnessFactor = np.sqrt(2.0 / (2.0 + effect.shininess))

    # Compute metallic factor
    metallicFactor = 0.0

    # Compute normal texture
    normalTexture = None
    if effect.bumpmap is not None:
        try:
            normalTexture = _load_texture(
                effect.bumpmap.sampler.surface.image.path, resolver)
        except BaseException:
            log.warning('unable to load bumpmap',
                        exc_info=True)

    return visual.texture.PBRMaterial(
        emissiveFactor=emissiveFactor,
        emissiveTexture=emissiveTexture,
        normalTexture=normalTexture,
        baseColorTexture=baseColorTexture,
        baseColorFactor=baseColorFactor,
        metallicFactor=metallicFactor,
        roughnessFactor=roughnessFactor
    )
704255
def _create_pure_shape(self, primitive_type, options, sizes, mass, precision):
        
        lua_code = "simCreatePureShape({}, {}, {{{}, {}, {}}}, {}, {{{}, {}}})".format(
            primitive_type, options, sizes[0], sizes[1], sizes[2], mass, precision[0], precision[1])
        self._inject_lua_code(lua_code)
1356000
def _mathPolarDecomposeInterpolationTransformation(matrix1, matrix2, value):
    
    off, scl, rot = MathTransform(matrix1).decompose()
    m1 = ShallowTransform(off, scl, rot)
    off, scl, rot = MathTransform(matrix2).decompose()
    m2 = ShallowTransform(off, scl, rot)
    m3 = m1 + value * (m2-m1)
    m3 = MathTransform().compose(m3.offset, m3.scale, m3.rotation)
    return tuple(m3)
239772
def _mix_simple(a, b, x):
    """"""
    x = np.clip(x, 0.0, 1.0)
    return (1.0 - x)*a + x*b
779956
def morph(clm1, clm2, t, lmax):
    """"""
    clm = (1 - t) * clm1 + t * clm2
    grid_reco = clm.expand(lmax=lmax)  # cut "high frequency" components
    agrid_reco = grid_reco.to_array()
    pts = []
    for i, longs in enumerate(agrid_reco):
        ilat = grid_reco.lats()[i]
        for j, value in enumerate(longs):
            ilong = grid_reco.lons()[j]
            th = (90 - ilat) / 57.3
            ph = ilong / 57.3
            r = value + rbias
            p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * r
            pts.append(p)
    return pts
885672
function Animation() {
  // create a geometry that will be used by BAS.ModelBufferGeometry
  var modelRadius = 10;
  var modelTube = 4;
  var model = new THREE.TorusGeometry(modelRadius, modelTube, 256, 256);

  // duplicate some vertices so that each face becomes a separate triangle.
  // this is the same as the THREE.ExplodeModifier
  BAS.Utils.separateFaces(model);

  // create a ModelBufferGeometry based on the geometry created above
  // ModelBufferGeometry makes it easier to create animations based on faces of a geometry
  // it is similar to the PrefabBufferGeometry where the prefab is a face (triangle)
  var geometry = new BAS.ModelBufferGeometry(model, {
    // setting this to true will store the vertex positions relative to the face they are in
    // this way it's easier to rotate and scale faces around their own center
    localizeFaces: true,
    // setting this to true will store a centroid for each face in an array
    computeCentroids: true
  });

  // ANIMATION

  // create a BufferAttribute with an item size of 2, so each face has an animation duration and a delay
  var aDelayDuration = geometry.createAttribute('aDelayDuration', 2);
  var minDuration = 1.0;
  var maxDuration = 1.0;
  var centroidDelayFactor = 0.1;

  // animation delay is calculated based on position
  // the max position is equal to the radius + tube of the torus
  this.totalDuration = maxDuration + centroidDelayFactor * (modelRadius + modelTube);

  // calculate a delay and duration FOR EACH FACE
  for (var i = 0, offset = 0; i < geometry.faceCount; i++) {
    var duration = THREE.Math.randFloat(minDuration, maxDuration);
    var centroidLength = geometry.centroids[i].length();
    var delay = centroidLength * centroidDelayFactor;

    // store the delay and duration FOR EACH VERTEX of the face
    // the loop is repeated 3 times because each face has 3 vertices
    for (var j = 0; j < 3; j++) {
      aDelayDuration.array[offset]     = delay;
      aDelayDuration.array[offset + 1] = duration;

      offset += 2;
    }
  }

  // POSITION

  // simply copy the centroid of the face as the position
  // adding the position in the vertex shader will 'reset' the face to its original position in the geometry
  // the function passed as the 3rd argument will be executed for each face
  var aPosition = geometry.createAttribute('aPosition', 3, function(data, i) {
    geometry.centroids[i].toArray(data);
  });

  // ROTATION

  var axis = new THREE.Vector3();

  // give each face a rotation axis and an angle to rotate around that axis
  var aAxisAngle = geometry.createAttribute('aAxisAngle', 4, function(data, i) {
    // base the axis on the position within the geometry
    // this creates a smooth curve/wave effect
    axis.copy(geometry.centroids[i]).normalize();
    axis.toArray(data);
    // two full rotations around the axis
    data[3] = Math.PI * 4;
  });

  var material = new BAS.StandardAnimationMaterial({
    flatShading: true,
    side: THREE.DoubleSide,
    uniforms: {
      uTime: {value: 0},
      // this color will be used for back-facing fragments in fragmentDiffuse
      uBackColor: {value: new THREE.Color().setHSL(0, 1.0, 0.5)}
    },
    uniformValues: {
      diffuse: new THREE.Color(0x000000)
    },
    vertexFunctions: [
      BAS.ShaderChunk['ease_cubic_in_out'],
      BAS.ShaderChunk['quaternion_rotation']
    ],
    vertexParameters: [
      'uniform float uTime;',
      'attribute vec2 aDelayDuration;',
      'attribute vec3 aPosition;',
      'attribute vec4 aAxisAngle;'
    ],
    vertexInit: [
      'float tProgress = clamp(uTime - aDelayDuration.x, 0.0, aDelayDuration.y) / aDelayDuration.y;',
      'tProgress = easeCubicInOut(tProgress);'
    ],
    vertexPosition: [
      'vec4 tQuat = quatFromAxisAngle(aAxisAngle.xyz, aAxisAngle.w * tProgress);',

      // rotate the vertex around (0, 0, 0)
      'transformed = rotateVector(tQuat, transformed);',
      // restore the position
      'transformed += aPosition;'
    ],
    fragmentParameters: [
      'uniform vec3 uBackColor;'
    ],
    fragmentDiffuse: [
      // gl_FrontFacing is a built-in glsl variable that indicates if the current fragment is front-facing
      // if its not front facing, set diffuse color to uBackColor
      'if (!gl_FrontFacing) {',
      ' diffuseColor.rgb = uBackColor.xyz;',
      '}'
    ]
  });

  THREE.Mesh.call(this, geometry, material);

  this.frustumCulled = false;
}
700449
function() {
            var self            = this,
                transformName   = '',
                effectsIn       = self.config.animation.effectsIn || self.config.animation.effects,
                effectsOut      = self.config.animation.effectsOut || self.config.animation.effects;

            self.callActions('beforeParseEffects', arguments);

            self.effectsIn      = new mixitup.StyleData();
            self.effectsOut     = new mixitup.StyleData();
            self.transformIn    = [];
            self.transformOut   = [];

            self.effectsIn.opacity = self.effectsOut.opacity = 1;

            self.parseEffect('fade', effectsIn, self.effectsIn, self.transformIn);
            self.parseEffect('fade', effectsOut, self.effectsOut, self.transformOut, true);

            for (transformName in mixitup.transformDefaults) {
                if (!(mixitup.transformDefaults[transformName] instanceof mixitup.TransformData)) {
                    continue;
                }

                self.parseEffect(transformName, effectsIn, self.effectsIn, self.transformIn);
                self.parseEffect(transformName, effectsOut, self.effectsOut, self.transformOut, true);
            }

            self.parseEffect('stagger', effectsIn, self.effectsIn, self.transformIn);
            self.parseEffect('stagger', effectsOut, self.effectsOut, self.transformOut, true);

            self.callActions('afterParseEffects', arguments);
        }
1178093
def _glsl_mix(controls=None):
    """"""
    assert (controls[0], controls[-1]) == (0., 1.)
    ncolors = len(controls)
    assert ncolors >= 2
    if ncolors == 2:
        s = "    return mix($color_0, $color_1, t);\n"
    else:
        s = ""
        for i in range(ncolors-1):
            if i == 0:
                ifs = 'if (t < %.6f)' % (controls[i+1])
            elif i == (ncolors-2):
                ifs = 'else'
            else:
                ifs = 'else if (t < %.6f)' % (controls[i+1])
            adj_t = '(t - %s) / %s' % (controls[i],
                                       controls[i+1] - controls[i])
            s += ("%s {\n    return mix($color_%d, $color_%d, %s);\n} " %
                  (ifs, i, i+1, adj_t))
    return "vec4 colormap(float t) {\n%s\n}" % s
1353269
function(shape, context, top) {
            var m = shape.getAbsoluteTransform(top).getMatrix();
            context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
        }
158202
def get(img, light=False):
    """"""
    cols = gen_colors(img)
    return adjust(cols, light)
731555
def make_gradients(dims=DEFAULT_DIMS):
    
    return np.meshgrid(
        np.linspace(0.0, 1.0, dims[0]),
        np.linspace(0.0, 1.0, dims[1])
    )
871947
def OnResizeGrid(self, event):
        """"""

        shape = min(event.shape[2], 2**30)
        self.SetItemCount(shape)
        event.Skip()
48441
function (color, elem, prop) {
		var colorObject,
			regexRgba = /^rgba/,
			markup;

		if (color && color.linearGradient) {

			var stopColor,
				stopOpacity,
				linearGradient = color.linearGradient,
				angle,
				color1,
				opacity1,
				color2,
				opacity2;

			each(color.stops, function (stop, i) {
				if (regexRgba.test(stop[1])) {
					colorObject = Color(stop[1]);
					stopColor = colorObject.get('rgb');
					stopOpacity = colorObject.get('a');
				} else {
					stopColor = stop[1];
					stopOpacity = 1;
				}

				if (!i) { // first
					color1 = stopColor;
					opacity1 = stopOpacity;
				} else {
					color2 = stopColor;
					opacity2 = stopOpacity;
				}
			});



			// calculate the angle based on the linear vector
			angle = 90  - math.atan(
				(linearGradient[3] - linearGradient[1]) / // y vector
				(linearGradient[2] - linearGradient[0]) // x vector
				) * 180 / mathPI;

			// when colors attribute is used, the meanings of opacity and o:opacity2
			// are reversed.
			markup = ['<', prop, ' colors="0% ', color1, ',100% ', color2, '" angle="', angle,
				'" opacity="', opacity2, '" o:opacity2="', opacity1,
				'" type="gradient" focus="100%" />'];
			createElement(this.prepVML(markup), null, null, elem);



		// if the color is an rgba color, split it and add a fill node
		// to hold the opacity component
		} else if (regexRgba.test(color) && elem.tagName !== 'IMG') {

			colorObject = Color(color);

			markup = ['<', prop, ' opacity="', colorObject.get('a'), '"/>'];
			createElement(this.prepVML(markup), null, null, elem);

			return colorObject.get('rgb');


		} else {
			var strokeNodes = elem.getElementsByTagName(prop);
			if (strokeNodes.length) {
				strokeNodes[0].opacity = 1;
			}
			return color;
		}

	}
1254184
def _flattenComponent(glyphSet, component):
    """"""

    glyph = glyphSet[component.baseGlyph]
    if not glyph.components:
        transformation = Transform(*component.transformation)
        return [(component.baseGlyph, transformation)]

    all_flattened_components = []
    for nested in glyph.components:
        flattened_components = _flattenComponent(glyphSet, nested)
        for i, (_, tr) in enumerate(flattened_components):
            tr = tr.transform(component.transformation)
            flattened_components[i] = (flattened_components[i][0], tr)
        all_flattened_components.extend(flattened_components)
    return all_flattened_components
678008
def blend_color(color, color2):
    """"""
    r1, g1, b1 = hex_to_rgb(color)
    r2, g2, b2 = hex_to_rgb(color2)

    r3 = int(0.5 * r1 + 0.5 * r2)
    g3 = int(0.5 * g1 + 0.5 * g2)
    b3 = int(0.5 * b1 + 0.5 * b2)

    return rgb_to_hex((r3, g3, b3))
448160
function( wrap ) {
    var gl = this.gl;
    gl.samplerParameteri( this.id, gl.TEXTURE_WRAP_S, wrap );
    gl.samplerParameteri( this.id, gl.TEXTURE_WRAP_T, wrap );
  }
641027
function createStyledElement(component, props, children) {
  return (...chunks) => {
    const classNames = chunks.map(chunk => (chunk ? glamor(chunk) : ''))

    if (props) {
      const { innerRef, forwardRef, css, className, ...restProps } = props

      if (css) {
        classNames.push(glamor(css))
      }

      if (className) {
        classNames.push(className)
      }

      return createElement(
        component,
        {
          [forwardRef ? 'innerRef' : 'ref']: innerRef,
          className: classNames.join(' ').trim(),
          ...restProps,
        },
        restProps.children || children
      )
    } else {
      return ({ innerRef, forwardRef, css, className = '', ...restProps }) => {
        const glamorClass = css ? glamor(css) : ''

        return createElement(component, {
          [forwardRef ? 'innerRef' : 'ref']: innerRef,
          className: classNames.concat(glamorClass, className).join(' ').trim(),
          ...restProps,
        })
      }
    }
  }
}