Best Python code snippet using molotov_python
ShaderLib.js
Source:ShaderLib.js  
1/**2 * Webgl Shader Library for three.js3 *4 * @author alteredq / http://alteredqualia.com/5 * @author mrdoob / http://mrdoob.com/6 * @author mikael emtinger / http://gomo.se/7 */8THREE.ShaderLib = {9	'basic': {10		uniforms: THREE.UniformsUtils.merge( [11			THREE.UniformsLib[ "common" ],12			THREE.UniformsLib[ "aomap" ],13			THREE.UniformsLib[ "fog" ],14			THREE.UniformsLib[ "shadowmap" ]15		] ),16		vertexShader: [17			THREE.ShaderChunk[ "common" ],18			THREE.ShaderChunk[ "uv_pars_vertex" ],19			THREE.ShaderChunk[ "uv2_pars_vertex" ],20			THREE.ShaderChunk[ "envmap_pars_vertex" ],21			THREE.ShaderChunk[ "color_pars_vertex" ],22			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],23			THREE.ShaderChunk[ "skinning_pars_vertex" ],24			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],25			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],26			"void main() {",27				THREE.ShaderChunk[ "uv_vertex" ],28				THREE.ShaderChunk[ "uv2_vertex" ],29				THREE.ShaderChunk[ "color_vertex" ],30				THREE.ShaderChunk[ "skinbase_vertex" ],31			"	#ifdef USE_ENVMAP",32				THREE.ShaderChunk[ "beginnormal_vertex" ],33				THREE.ShaderChunk[ "morphnormal_vertex" ],34				THREE.ShaderChunk[ "skinnormal_vertex" ],35				THREE.ShaderChunk[ "defaultnormal_vertex" ],36			"	#endif",37				THREE.ShaderChunk[ "begin_vertex" ],38				THREE.ShaderChunk[ "morphtarget_vertex" ],39				THREE.ShaderChunk[ "skinning_vertex" ],40				THREE.ShaderChunk[ "project_vertex" ],41				THREE.ShaderChunk[ "logdepthbuf_vertex" ],42				THREE.ShaderChunk[ "worldpos_vertex" ],43				THREE.ShaderChunk[ "envmap_vertex" ],44				THREE.ShaderChunk[ "shadowmap_vertex" ],45			"}"46		].join( "\n" ),47		fragmentShader: [48			"uniform vec3 diffuse;",49			"uniform float opacity;",50			THREE.ShaderChunk[ "common" ],51			THREE.ShaderChunk[ "color_pars_fragment" ],52			THREE.ShaderChunk[ "uv_pars_fragment" ],53			THREE.ShaderChunk[ "uv2_pars_fragment" ],54			THREE.ShaderChunk[ "map_pars_fragment" ],55			THREE.ShaderChunk[ "alphamap_pars_fragment" ],56			THREE.ShaderChunk[ "aomap_pars_fragment" ],57			THREE.ShaderChunk[ "envmap_pars_fragment" ],58			THREE.ShaderChunk[ "fog_pars_fragment" ],59			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],60			THREE.ShaderChunk[ "specularmap_pars_fragment" ],61			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],62			"void main() {",63			"	vec3 outgoingLight = vec3( 0.0 );",64			"	vec4 diffuseColor = vec4( diffuse, opacity );",65			"	vec3 totalAmbientLight = vec3( 1.0 );", // hardwired66			"	vec3 shadowMask = vec3( 1.0 );",67				THREE.ShaderChunk[ "logdepthbuf_fragment" ],68				THREE.ShaderChunk[ "map_fragment" ],69				THREE.ShaderChunk[ "color_fragment" ],70				THREE.ShaderChunk[ "alphamap_fragment" ],71				THREE.ShaderChunk[ "alphatest_fragment" ],72				THREE.ShaderChunk[ "specularmap_fragment" ],73				THREE.ShaderChunk[ "aomap_fragment" ],74				THREE.ShaderChunk[ "shadowmap_fragment" ],75			"	outgoingLight = diffuseColor.rgb * totalAmbientLight * shadowMask;",76				THREE.ShaderChunk[ "envmap_fragment" ],77				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],78				THREE.ShaderChunk[ "fog_fragment" ],79			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",80			"}"81		].join( "\n" )82	},83	'lambert': {84		uniforms: THREE.UniformsUtils.merge( [85			THREE.UniformsLib[ "common" ],86			THREE.UniformsLib[ "fog" ],87			THREE.UniformsLib[ "lights" ],88			THREE.UniformsLib[ "shadowmap" ],89			{90				"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }91			}92		] ),93		vertexShader: [94			"#define LAMBERT",95			"varying vec3 vLightFront;",96			"#ifdef DOUBLE_SIDED",97			"	varying vec3 vLightBack;",98			"#endif",99			THREE.ShaderChunk[ "common" ],100			THREE.ShaderChunk[ "uv_pars_vertex" ],101			THREE.ShaderChunk[ "uv2_pars_vertex" ],102			THREE.ShaderChunk[ "envmap_pars_vertex" ],103			THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],104			THREE.ShaderChunk[ "color_pars_vertex" ],105			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],106			THREE.ShaderChunk[ "skinning_pars_vertex" ],107			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],108			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],109			"void main() {",110				THREE.ShaderChunk[ "uv_vertex" ],111				THREE.ShaderChunk[ "uv2_vertex" ],112				THREE.ShaderChunk[ "color_vertex" ],113				THREE.ShaderChunk[ "beginnormal_vertex" ],114				THREE.ShaderChunk[ "morphnormal_vertex" ],115				THREE.ShaderChunk[ "skinbase_vertex" ],116				THREE.ShaderChunk[ "skinnormal_vertex" ],117				THREE.ShaderChunk[ "defaultnormal_vertex" ],118				THREE.ShaderChunk[ "begin_vertex" ],119				THREE.ShaderChunk[ "morphtarget_vertex" ],120				THREE.ShaderChunk[ "skinning_vertex" ],121				THREE.ShaderChunk[ "project_vertex" ],122				THREE.ShaderChunk[ "logdepthbuf_vertex" ],123				THREE.ShaderChunk[ "worldpos_vertex" ],124				THREE.ShaderChunk[ "envmap_vertex" ],125				THREE.ShaderChunk[ "lights_lambert_vertex" ],126				THREE.ShaderChunk[ "shadowmap_vertex" ],127			"}"128		].join( "\n" ),129		fragmentShader: [130			"uniform vec3 diffuse;",131			"uniform vec3 emissive;",132			"uniform float opacity;",133			"uniform vec3 ambientLightColor;",134			"varying vec3 vLightFront;",135			"#ifdef DOUBLE_SIDED",136			"	varying vec3 vLightBack;",137			"#endif",138			THREE.ShaderChunk[ "common" ],139			THREE.ShaderChunk[ "color_pars_fragment" ],140			THREE.ShaderChunk[ "uv_pars_fragment" ],141			THREE.ShaderChunk[ "uv2_pars_fragment" ],142			THREE.ShaderChunk[ "map_pars_fragment" ],143			THREE.ShaderChunk[ "alphamap_pars_fragment" ],144			THREE.ShaderChunk[ "envmap_pars_fragment" ],145			THREE.ShaderChunk[ "fog_pars_fragment" ],146			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],147			THREE.ShaderChunk[ "specularmap_pars_fragment" ],148			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],149			"void main() {",150			"	vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does151			"	vec4 diffuseColor = vec4( diffuse, opacity );",152			"	vec3 totalAmbientLight = ambientLightColor;",153			"	vec3 shadowMask = vec3( 1.0 );",154				THREE.ShaderChunk[ "logdepthbuf_fragment" ],155				THREE.ShaderChunk[ "map_fragment" ],156				THREE.ShaderChunk[ "color_fragment" ],157				THREE.ShaderChunk[ "alphamap_fragment" ],158				THREE.ShaderChunk[ "alphatest_fragment" ],159				THREE.ShaderChunk[ "specularmap_fragment" ],160				THREE.ShaderChunk[ "shadowmap_fragment" ],161			"	#ifdef DOUBLE_SIDED",162			"		if ( gl_FrontFacing )",163			"			outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",164			"		else",165			"			outgoingLight += diffuseColor.rgb * ( vLightBack * shadowMask + totalAmbientLight ) + emissive;",166			"	#else",167			"		outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",168			"	#endif",169				THREE.ShaderChunk[ "envmap_fragment" ],170				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],171				THREE.ShaderChunk[ "fog_fragment" ],172			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",173			"}"174		].join( "\n" )175	},176	'phong': {177		uniforms: THREE.UniformsUtils.merge( [178			THREE.UniformsLib[ "common" ],179			THREE.UniformsLib[ "aomap" ],180			THREE.UniformsLib[ "lightmap" ],181			THREE.UniformsLib[ "emissivemap" ],182			THREE.UniformsLib[ "bumpmap" ],183			THREE.UniformsLib[ "normalmap" ],184			THREE.UniformsLib[ "displacementmap" ],185			THREE.UniformsLib[ "fog" ],186			THREE.UniformsLib[ "lights" ],187			THREE.UniformsLib[ "shadowmap" ],188			{189				"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },190				"specular" : { type: "c", value: new THREE.Color( 0x111111 ) },191				"shininess": { type: "f", value: 30 }192			}193		] ),194		vertexShader: [195			"#define PHONG",196			"varying vec3 vViewPosition;",197			"#ifndef FLAT_SHADED",198			"	varying vec3 vNormal;",199			"#endif",200			THREE.ShaderChunk[ "common" ],201			THREE.ShaderChunk[ "uv_pars_vertex" ],202			THREE.ShaderChunk[ "uv2_pars_vertex" ],203			THREE.ShaderChunk[ "displacementmap_pars_vertex" ],204			THREE.ShaderChunk[ "envmap_pars_vertex" ],205			THREE.ShaderChunk[ "lights_phong_pars_vertex" ],206			THREE.ShaderChunk[ "color_pars_vertex" ],207			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],208			THREE.ShaderChunk[ "skinning_pars_vertex" ],209			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],210			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],211			"void main() {",212				THREE.ShaderChunk[ "uv_vertex" ],213				THREE.ShaderChunk[ "uv2_vertex" ],214				THREE.ShaderChunk[ "color_vertex" ],215				THREE.ShaderChunk[ "beginnormal_vertex" ],216				THREE.ShaderChunk[ "morphnormal_vertex" ],217				THREE.ShaderChunk[ "skinbase_vertex" ],218				THREE.ShaderChunk[ "skinnormal_vertex" ],219				THREE.ShaderChunk[ "defaultnormal_vertex" ],220			"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED221			"	vNormal = normalize( transformedNormal );",222			"#endif",223				THREE.ShaderChunk[ "begin_vertex" ],224				THREE.ShaderChunk[ "displacementmap_vertex" ],225				THREE.ShaderChunk[ "morphtarget_vertex" ],226				THREE.ShaderChunk[ "skinning_vertex" ],227				THREE.ShaderChunk[ "project_vertex" ],228				THREE.ShaderChunk[ "logdepthbuf_vertex" ],229			"	vViewPosition = - mvPosition.xyz;",230				THREE.ShaderChunk[ "worldpos_vertex" ],231				THREE.ShaderChunk[ "envmap_vertex" ],232				THREE.ShaderChunk[ "lights_phong_vertex" ],233				THREE.ShaderChunk[ "shadowmap_vertex" ],234			"}"235		].join( "\n" ),236		fragmentShader: [237			"#define PHONG",238			"uniform vec3 diffuse;",239			"uniform vec3 emissive;",240			"uniform vec3 specular;",241			"uniform float shininess;",242			"uniform float opacity;",243			THREE.ShaderChunk[ "common" ],244			THREE.ShaderChunk[ "color_pars_fragment" ],245			THREE.ShaderChunk[ "uv_pars_fragment" ],246			THREE.ShaderChunk[ "uv2_pars_fragment" ],247			THREE.ShaderChunk[ "map_pars_fragment" ],248			THREE.ShaderChunk[ "alphamap_pars_fragment" ],249			THREE.ShaderChunk[ "aomap_pars_fragment" ],250			THREE.ShaderChunk[ "lightmap_pars_fragment" ],251			THREE.ShaderChunk[ "emissivemap_pars_fragment" ],252			THREE.ShaderChunk[ "envmap_pars_fragment" ],253			THREE.ShaderChunk[ "fog_pars_fragment" ],254			THREE.ShaderChunk[ "lights_phong_pars_fragment" ],255			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],256			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],257			THREE.ShaderChunk[ "normalmap_pars_fragment" ],258			THREE.ShaderChunk[ "specularmap_pars_fragment" ],259			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],260			"void main() {",261			"	vec3 outgoingLight = vec3( 0.0 );",262			"	vec4 diffuseColor = vec4( diffuse, opacity );",263			"	vec3 totalAmbientLight = ambientLightColor;",264			"	vec3 totalEmissiveLight = emissive;",265			"	vec3 shadowMask = vec3( 1.0 );",266				THREE.ShaderChunk[ "logdepthbuf_fragment" ],267				THREE.ShaderChunk[ "map_fragment" ],268				THREE.ShaderChunk[ "color_fragment" ],269				THREE.ShaderChunk[ "alphamap_fragment" ],270				THREE.ShaderChunk[ "alphatest_fragment" ],271				THREE.ShaderChunk[ "specularmap_fragment" ],272				THREE.ShaderChunk[ "normal_phong_fragment" ],273				THREE.ShaderChunk[ "lightmap_fragment" ],274				THREE.ShaderChunk[ "hemilight_fragment" ],275				THREE.ShaderChunk[ "aomap_fragment" ],276				THREE.ShaderChunk[ "emissivemap_fragment" ],277				THREE.ShaderChunk[ "lights_phong_fragment" ],278				THREE.ShaderChunk[ "shadowmap_fragment" ],279				"totalDiffuseLight *= shadowMask;",280				"totalSpecularLight *= shadowMask;",281				"#ifdef METAL",282				"	outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;",283				"#else",284				"	outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;",285				"#endif",286				THREE.ShaderChunk[ "envmap_fragment" ],287				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],288				THREE.ShaderChunk[ "fog_fragment" ],289			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",290			"}"291		].join( "\n" )292	},293	'points': {294		uniforms: THREE.UniformsUtils.merge( [295			THREE.UniformsLib[ "points" ],296			THREE.UniformsLib[ "shadowmap" ]297		] ),298		vertexShader: [299			"uniform float size;",300			"uniform float scale;",301			THREE.ShaderChunk[ "common" ],302			THREE.ShaderChunk[ "color_pars_vertex" ],303			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],304			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],305			"void main() {",306				THREE.ShaderChunk[ "color_vertex" ],307			"	vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",308			"	#ifdef USE_SIZEATTENUATION",309			"		gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",310			"	#else",311			"		gl_PointSize = size;",312			"	#endif",313			"	gl_Position = projectionMatrix * mvPosition;",314				THREE.ShaderChunk[ "logdepthbuf_vertex" ],315				THREE.ShaderChunk[ "worldpos_vertex" ],316				THREE.ShaderChunk[ "shadowmap_vertex" ],317			"}"318		].join( "\n" ),319		fragmentShader: [320			"uniform vec3 psColor;",321			"uniform float opacity;",322			THREE.ShaderChunk[ "common" ],323			THREE.ShaderChunk[ "color_pars_fragment" ],324			THREE.ShaderChunk[ "map_particle_pars_fragment" ],325			THREE.ShaderChunk[ "fog_pars_fragment" ],326			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],327			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],328			"void main() {",329			"	vec3 outgoingLight = vec3( 0.0 );",330			"	vec4 diffuseColor = vec4( psColor, opacity );",331			"	vec3 shadowMask = vec3( 1.0 );",332				THREE.ShaderChunk[ "logdepthbuf_fragment" ],333				THREE.ShaderChunk[ "map_particle_fragment" ],334				THREE.ShaderChunk[ "color_fragment" ],335				THREE.ShaderChunk[ "alphatest_fragment" ],336				THREE.ShaderChunk[ "shadowmap_fragment" ],337			"	outgoingLight = diffuseColor.rgb * shadowMask;",338				THREE.ShaderChunk[ "fog_fragment" ],339			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",340			"}"341		].join( "\n" )342	},343	'dashed': {344		uniforms: THREE.UniformsUtils.merge( [345			THREE.UniformsLib[ "common" ],346			THREE.UniformsLib[ "fog" ],347			{348				"scale"    : { type: "f", value: 1 },349				"dashSize" : { type: "f", value: 1 },350				"totalSize": { type: "f", value: 2 }351			}352		] ),353		vertexShader: [354			"uniform float scale;",355			"attribute float lineDistance;",356			"varying float vLineDistance;",357			THREE.ShaderChunk[ "common" ],358			THREE.ShaderChunk[ "color_pars_vertex" ],359			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],360			"void main() {",361				THREE.ShaderChunk[ "color_vertex" ],362			"	vLineDistance = scale * lineDistance;",363			"	vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",364			"	gl_Position = projectionMatrix * mvPosition;",365				THREE.ShaderChunk[ "logdepthbuf_vertex" ],366			"}"367		].join( "\n" ),368		fragmentShader: [369			"uniform vec3 diffuse;",370			"uniform float opacity;",371			"uniform float dashSize;",372			"uniform float totalSize;",373			"varying float vLineDistance;",374			THREE.ShaderChunk[ "common" ],375			THREE.ShaderChunk[ "color_pars_fragment" ],376			THREE.ShaderChunk[ "fog_pars_fragment" ],377			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],378			"void main() {",379			"	if ( mod( vLineDistance, totalSize ) > dashSize ) {",380			"		discard;",381			"	}",382			"	vec3 outgoingLight = vec3( 0.0 );",383			"	vec4 diffuseColor = vec4( diffuse, opacity );",384				THREE.ShaderChunk[ "logdepthbuf_fragment" ],385				THREE.ShaderChunk[ "color_fragment" ],386			"	outgoingLight = diffuseColor.rgb;", // simple shader387				THREE.ShaderChunk[ "fog_fragment" ],388			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",389			"}"390		].join( "\n" )391	},392	'depth': {393		uniforms: {394			"mNear": { type: "f", value: 1.0 },395			"mFar" : { type: "f", value: 2000.0 },396			"opacity" : { type: "f", value: 1.0 }397		},398		vertexShader: [399			THREE.ShaderChunk[ "common" ],400			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],401			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],402			"void main() {",403				THREE.ShaderChunk[ "begin_vertex" ],404				THREE.ShaderChunk[ "morphtarget_vertex" ],405				THREE.ShaderChunk[ "project_vertex" ],406				THREE.ShaderChunk[ "logdepthbuf_vertex" ],407			"}"408		].join( "\n" ),409		fragmentShader: [410			"uniform float mNear;",411			"uniform float mFar;",412			"uniform float opacity;",413			THREE.ShaderChunk[ "common" ],414			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],415			"void main() {",416				THREE.ShaderChunk[ "logdepthbuf_fragment" ],417			"	#ifdef USE_LOGDEPTHBUF_EXT",418			"		float depth = gl_FragDepthEXT / gl_FragCoord.w;",419			"	#else",420			"		float depth = gl_FragCoord.z / gl_FragCoord.w;",421			"	#endif",422			"	float color = 1.0 - smoothstep( mNear, mFar, depth );",423			"	gl_FragColor = vec4( vec3( color ), opacity );",424			"}"425		].join( "\n" )426	},427	'normal': {428		uniforms: {429			"opacity" : { type: "f", value: 1.0 }430		},431		vertexShader: [432			"varying vec3 vNormal;",433			THREE.ShaderChunk[ "common" ],434			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],435			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],436			"void main() {",437			"	vNormal = normalize( normalMatrix * normal );",438				THREE.ShaderChunk[ "begin_vertex" ],439				THREE.ShaderChunk[ "morphtarget_vertex" ],440				THREE.ShaderChunk[ "project_vertex" ],441				THREE.ShaderChunk[ "logdepthbuf_vertex" ],442			"}"443		].join( "\n" ),444		fragmentShader: [445			"uniform float opacity;",446			"varying vec3 vNormal;",447			THREE.ShaderChunk[ "common" ],448			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],449			"void main() {",450			"	gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",451				THREE.ShaderChunk[ "logdepthbuf_fragment" ],452			"}"453		].join( "\n" )454	},455	/* -------------------------------------------------------------------------456	//	Cube map shader457	 ------------------------------------------------------------------------- */458	'cube': {459		uniforms: { "tCube": { type: "t", value: null },460					"tFlip": { type: "f", value: - 1 } },461		vertexShader: [462			"varying vec3 vWorldPosition;",463			THREE.ShaderChunk[ "common" ],464			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],465			"void main() {",466			"	vWorldPosition = transformDirection( position, modelMatrix );",467			"	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",468				THREE.ShaderChunk[ "logdepthbuf_vertex" ],469			"}"470		].join( "\n" ),471		fragmentShader: [472			"uniform samplerCube tCube;",473			"uniform float tFlip;",474			"varying vec3 vWorldPosition;",475			THREE.ShaderChunk[ "common" ],476			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],477			"void main() {",478			"	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",479				THREE.ShaderChunk[ "logdepthbuf_fragment" ],480			"}"481		].join( "\n" )482	},483	/* -------------------------------------------------------------------------484	//	Cube map shader485	 ------------------------------------------------------------------------- */486	'equirect': {487		uniforms: { "tEquirect": { type: "t", value: null },488					"tFlip": { type: "f", value: - 1 } },489		vertexShader: [490			"varying vec3 vWorldPosition;",491			THREE.ShaderChunk[ "common" ],492			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],493			"void main() {",494			"	vWorldPosition = transformDirection( position, modelMatrix );",495			"	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",496				THREE.ShaderChunk[ "logdepthbuf_vertex" ],497			"}"498		].join( "\n" ),499		fragmentShader: [500			"uniform sampler2D tEquirect;",501			"uniform float tFlip;",502			"varying vec3 vWorldPosition;",503			THREE.ShaderChunk[ "common" ],504			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],505			"void main() {",506				// "	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",507				"vec3 direction = normalize( vWorldPosition );",508				"vec2 sampleUV;",509				"sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",510				"sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",511				"gl_FragColor = texture2D( tEquirect, sampleUV );",512				THREE.ShaderChunk[ "logdepthbuf_fragment" ],513			"}"514		].join( "\n" )515	},516	/* Depth encoding into RGBA texture517	 *518	 * based on SpiderGL shadow map example519	 * http://spidergl.org/example.php?id=6520	 *521	 * originally from522	 * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD523	 *524	 * see also525	 * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/526	 */527	'depthRGBA': {528		uniforms: {},529		vertexShader: [530			THREE.ShaderChunk[ "common" ],531			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],532			THREE.ShaderChunk[ "skinning_pars_vertex" ],533			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],534			"void main() {",535				THREE.ShaderChunk[ "skinbase_vertex" ],536				THREE.ShaderChunk[ "begin_vertex" ],537				THREE.ShaderChunk[ "morphtarget_vertex" ],538				THREE.ShaderChunk[ "skinning_vertex" ],539				THREE.ShaderChunk[ "project_vertex" ],540				THREE.ShaderChunk[ "logdepthbuf_vertex" ],541			"}"542		].join( "\n" ),543		fragmentShader: [544			THREE.ShaderChunk[ "common" ],545			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],546			"vec4 pack_depth( const in float depth ) {",547			"	const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",548			"	const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",549			"	vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // "	vec4 res = fract( depth * bit_shift );",550			"	res -= res.xxyz * bit_mask;",551			"	return res;",552			"}",553			"void main() {",554				THREE.ShaderChunk[ "logdepthbuf_fragment" ],555			"	#ifdef USE_LOGDEPTHBUF_EXT",556			"		gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",557			"	#else",558			"		gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",559			"	#endif",560				//"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",561				//"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",562				//"gl_FragData[ 0 ] = pack_depth( z );",563				//"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",564			"}"565		].join( "\n" )566	},567	'distanceRGBA': {568		uniforms: {569			"lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }570		},571		vertexShader: [572			"varying vec4 vWorldPosition;",573			THREE.ShaderChunk[ "common" ],574			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],575			THREE.ShaderChunk[ "skinning_pars_vertex" ],576			"void main() {",577				THREE.ShaderChunk[ "skinbase_vertex" ],578				THREE.ShaderChunk[ "begin_vertex" ],579				THREE.ShaderChunk[ "morphtarget_vertex" ],580				THREE.ShaderChunk[ "skinning_vertex" ],581				THREE.ShaderChunk[ "project_vertex" ],582				THREE.ShaderChunk[ "worldpos_vertex" ],583				"vWorldPosition = worldPosition;",584			"}"585		].join( "\n" ),586		fragmentShader: [587			"uniform vec3 lightPos;",588			"varying vec4 vWorldPosition;",589			THREE.ShaderChunk[ "common" ],590			"vec4 pack1K ( float depth ) {",591			"   depth /= 1000.0;",592			"   const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",593  			"	const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",594   			"	vec4 res = fract( depth * bitSh );",595   			"	res -= res.xxyz * bitMsk;",596   			"	return res; ",597			"}",598			"float unpack1K ( vec4 color ) {",599			"	const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",600			"	return dot( color, bitSh ) * 1000.0;",601			"}",602			"void main () {",603			"	gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",604			"}"605		].join( "\n" )606	}...test.py
Source:test.py  
1#!/usr/bin/python32import unittest3from primitive_calculator import optimal_sequence, \4    optimal_sequence_simplified, Operation5class OptimalSequenceTestCase(unittest.TestCase):6    def assert_sequences_and_operations(self, n, sequences, operations):7        self.assertEqual(len(sequences), len(operations))8        sequence_length = -19        for i in range(0, len(sequences)):10            if sequence_length == -1:11                sequence_length = len(sequences[i])12            self.assertEqual(sequence_length, len(sequences[i]))13            self.assertEqual(len(sequences[i]), len(operations[i]) + 1)14            x = 115            self.assertEqual(sequences[i][0], x)16            for j in range(0, len(sequences[i]) - 1):17                if operations[i][j] == Operation.multiply_by_three.name:18                    x *= 319                elif operations[i][j] == Operation.multiply_by_two.name:20                    x *= 221                elif operations[i][j] == Operation.add_one.name:22                    x += 123                self.assertEqual(sequences[i][j + 1], x)24            self.assertEqual(n, x)25    def test_with_negative(self):26        with self.assertRaisesRegex(AssertionError, ''):27            optimal_sequence(0)28    def test_with_0(self):29        with self.assertRaisesRegex(AssertionError, ''):30            optimal_sequence(0)31    def test_with_1(self):32        n = 133        sequences, operations = optimal_sequence(n)34        self.assertEqual([ [ 1 ] ], sequences)35        self.assertEqual([ [] ], operations)36        self.assert_sequences_and_operations(n, sequences, operations)37    def test_with_2(self):38        n = 239        sequences, operations = optimal_sequence(n)40        self.assertEqual(41            [42                [ 1, 2 ],43                [ 1, 2 ]44            ],45            sequences)46        self.assertEqual(47            [48                [ 'multiply_by_two' ],49                [ 'add_one' ]50            ],51            operations)52        self.assert_sequences_and_operations(n, sequences, operations)53    def test_with_3(self):54        n = 355        sequences, operations = optimal_sequence(n)56        self.assertEqual(57            [58                [ 1, 3 ]59            ],60            sequences)61        self.assertEqual(62            [63                [ 'multiply_by_three' ],64            ],65            operations)66        self.assert_sequences_and_operations(n, sequences, operations)67    def test_with_4(self):68        n = 469        sequences, operations = optimal_sequence(n)70        self.assertEqual(71            [72                [ 1, 2, 4 ],73                [ 1, 2, 4 ],74                [ 1, 3, 4 ]75            ],76            sequences)77        self.assertEqual(78            [79                [ 'multiply_by_two', 'multiply_by_two' ],80                [ 'add_one', 'multiply_by_two' ],81                [ 'multiply_by_three', 'add_one' ]82            ],83            operations)84        self.assert_sequences_and_operations(n, sequences, operations)85    def test_with_5(self):86        n = 587        sequences, operations = optimal_sequence(n)88        self.assertEqual(89            [90                [ 1, 2, 4, 5 ],91                [ 1, 2, 4, 5 ],92                [ 1, 3, 4, 5 ]93            ],94            sequences)95        self.assertEqual(96            [97                [ 'multiply_by_two', 'multiply_by_two', 'add_one' ],98                [ 'add_one', 'multiply_by_two', 'add_one' ],99                [ 'multiply_by_three', 'add_one', 'add_one' ]100            ],101            operations)102        self.assert_sequences_and_operations(n, sequences, operations)103    def test_with_6(self):104        n = 6105        sequences, operations = optimal_sequence(n)106        self.assertEqual(107            [108                [ 1, 2, 6 ],109                [ 1, 2, 6 ],110                [ 1, 3, 6 ]111            ],112            sequences)113        self.assertEqual(114            [115                [ 'multiply_by_two', 'multiply_by_three' ],116                [ 'add_one', 'multiply_by_three' ],117                [ 'multiply_by_three', 'multiply_by_two' ]118            ],119            operations)120        self.assert_sequences_and_operations(n, sequences, operations)121    def test_with_7(self):122        n = 7123        sequences, operations = optimal_sequence(n)124        self.assertEqual(125            [126                [ 1, 2, 6, 7 ],127                [ 1, 2, 6, 7 ],128                [ 1, 3, 6, 7 ]129            ],130            sequences)131        self.assertEqual(132            [133                [ 'multiply_by_two', 'multiply_by_three', 'add_one' ],134                [ 'add_one', 'multiply_by_three', 'add_one' ],135                [ 'multiply_by_three', 'multiply_by_two', 'add_one' ]136            ],137            operations)138        self.assert_sequences_and_operations(n, sequences, operations)139    def test_with_8(self):140        n = 8141        sequences, operations = optimal_sequence(n)142        self.assertEqual(143            [144                [ 1, 2, 4, 8 ],145                [ 1, 2, 4, 8 ],146                [ 1, 3, 4, 8 ]147            ],148            sequences)149        self.assertEqual(150            [151                [ 'multiply_by_two', 'multiply_by_two', 'multiply_by_two' ],152                [ 'add_one', 'multiply_by_two', 'multiply_by_two' ],153                [ 'multiply_by_three', 'add_one', 'multiply_by_two' ]154            ],155            operations)156        self.assert_sequences_and_operations(n, sequences, operations)157    def test_with_9(self):158        n = 9159        sequences, operations = optimal_sequence(n)160        self.assertEqual(161            [162                [ 1, 3, 9 ]163            ],164            sequences)165        self.assertEqual(166            [167                [ 'multiply_by_three', 'multiply_by_three' ]168            ],169            operations)170        self.assert_sequences_and_operations(n, sequences, operations)171    def test_with_10(self):172        n = 10173        sequences, operations = optimal_sequence(n)174        self.assertEqual(175            [176                [ 1, 3, 9, 10 ]177            ],178            sequences)179        self.assertEqual(180            [181                [ 'multiply_by_three', 'multiply_by_three', 'add_one' ]182            ],183            operations)184        self.assert_sequences_and_operations(n, sequences, operations)185    def test_with_96234(self):186        n = 96234187        sequences, operations = optimal_sequence(n)188        self.assertEqual(189            [190                [191                    1, 3, 9, 10, 11, 22, 66, 198, 594, 1782, 5346, 16038,192                    16039, 32078, 96234193                ],194                [195                    1, 2, 6, 7, 21, 22, 66, 198, 594, 1782, 5346, 16038,196                    16039, 32078, 96234197                ],198                [199                    1, 2, 6, 7, 21, 22, 66, 198, 594, 1782, 5346, 16038,200                    16039, 32078, 96234201                ],202                [203                    1, 3, 6, 7, 21, 22, 66, 198, 594, 1782, 5346, 16038,204                    16039, 32078, 96234205                ],206                [207                    1, 3, 9, 10, 11, 33, 66, 198, 594, 1782, 5346, 16038,208                    16039, 32078, 96234209                ],210                [211                    1, 3, 9, 10, 11, 33, 99, 198, 594, 1782, 5346, 16038,212                    16039, 32078, 96234213                ],214                [215                    1, 3, 9, 10, 11, 33, 99, 297, 594, 1782, 5346, 16038,216                    16039, 32078, 96234217                ],218                [219                    1, 3, 9, 10, 11, 33, 99, 297, 891, 1782, 5346, 16038,220                    16039, 32078, 96234221                ],222                [223                    1, 3, 9, 10, 11, 33, 99, 297, 891, 2673, 5346, 16038,224                    16039, 32078, 96234225                ],226                [227                    1, 3, 9, 10, 11, 33, 99, 297, 891, 2673, 8019, 16038,228                    16039, 32078, 96234229                ],230                [231                    1, 3, 9, 10, 11, 22, 66, 198, 594, 1782, 5346, 16038,232                    16039, 48117, 96234233                ],234                [235                    1, 2, 6, 7, 21, 22, 66, 198, 594, 1782, 5346, 16038,236                    16039, 48117, 96234237                ],238                [239                    1, 2, 6, 7, 21, 22, 66, 198, 594, 1782, 5346, 16038,240                    16039, 48117, 96234241                ],242                [243                    1, 3, 6, 7, 21, 22, 66, 198, 594, 1782, 5346, 16038,244                    16039, 48117, 96234245                ],246                [247                    1, 3, 9, 10, 11, 33, 66, 198, 594, 1782, 5346, 16038,248                    16039, 48117, 96234249                ],250                [251                    1, 3, 9, 10, 11, 33, 99, 198, 594, 1782, 5346, 16038,252                    16039, 48117, 96234253                ],254                [255                    1, 3, 9, 10, 11, 33, 99, 297, 594, 1782, 5346, 16038,256                    16039, 48117, 96234257                ],258                [259                    1, 3, 9, 10, 11, 33, 99, 297, 891, 1782, 5346, 16038,260                    16039, 48117, 96234261                ],262                [263                    1, 3, 9, 10, 11, 33, 99, 297, 891, 2673, 5346, 16038,264                    16039, 48117, 96234265                ],266                [267                    1, 3, 9, 10, 11, 33, 99, 297, 891, 2673, 8019, 16038,268                    16039, 48117, 96234269                ]270            ],271            sequences)272        self.assertEqual(273            [274                [275                    'multiply_by_three', 'multiply_by_three', 'add_one',276                    'add_one', 'multiply_by_two',277                    'multiply_by_three', 'multiply_by_three',278                    'multiply_by_three', 'multiply_by_three',279                    'multiply_by_three', 'multiply_by_three',280                    'add_one', 'multiply_by_two', 'multiply_by_three'281                ],282                [283                    'multiply_by_two', 'multiply_by_three', 'add_one',284                    'multiply_by_three', 'add_one', 'multiply_by_three',285                    'multiply_by_three', 'multiply_by_three',286                    'multiply_by_three', 'multiply_by_three',287                    'multiply_by_three', 'add_one', 'multiply_by_two',288                    'multiply_by_three'289                ],290                [291                    'add_one', 'multiply_by_three', 'add_one',292                    'multiply_by_three', 'add_one', 'multiply_by_three',293                    'multiply_by_three', 'multiply_by_three',294                    'multiply_by_three', 'multiply_by_three',295                    'multiply_by_three', 'add_one', 'multiply_by_two',296                    'multiply_by_three'297                ],298                [299                    'multiply_by_three', 'multiply_by_two', 'add_one',300                    'multiply_by_three', 'add_one', 'multiply_by_three',301                    'multiply_by_three', 'multiply_by_three',302                    'multiply_by_three', 'multiply_by_three',303                    'multiply_by_three', 'add_one', 'multiply_by_two',304                    'multiply_by_three'305                ],306                [307                    'multiply_by_three', 'multiply_by_three', 'add_one',308                    'add_one', 'multiply_by_three', 'multiply_by_two',309                    'multiply_by_three', 'multiply_by_three',310                    'multiply_by_three', 'multiply_by_three',311                    'multiply_by_three', 'add_one', 'multiply_by_two',312                    'multiply_by_three'313                ],314                [315                    'multiply_by_three', 'multiply_by_three', 'add_one',316                    'add_one', 'multiply_by_three', 'multiply_by_three',317                    'multiply_by_two', 'multiply_by_three',318                    'multiply_by_three', 'multiply_by_three',319                    'multiply_by_three', 'add_one', 'multiply_by_two',320                    'multiply_by_three'321                ],322                [323                    'multiply_by_three', 'multiply_by_three', 'add_one',324                    'add_one', 'multiply_by_three', 'multiply_by_three',325                    'multiply_by_three', 'multiply_by_two',326                    'multiply_by_three', 'multiply_by_three',327                    'multiply_by_three', 'add_one', 'multiply_by_two',328                    'multiply_by_three'329                ],330                [331                    'multiply_by_three', 'multiply_by_three', 'add_one',332                    'add_one', 'multiply_by_three', 'multiply_by_three',333                    'multiply_by_three', 'multiply_by_three',334                    'multiply_by_two', 'multiply_by_three',335                    'multiply_by_three', 'add_one', 'multiply_by_two',336                    'multiply_by_three'337                ],338                [339                    'multiply_by_three', 'multiply_by_three', 'add_one',340                    'add_one', 'multiply_by_three', 'multiply_by_three',341                    'multiply_by_three', 'multiply_by_three',342                    'multiply_by_three', 'multiply_by_two',343                    'multiply_by_three', 'add_one', 'multiply_by_two',344                    'multiply_by_three'345                ],346                [347                    'multiply_by_three', 'multiply_by_three', 'add_one',348                    'add_one', 'multiply_by_three', 'multiply_by_three',349                    'multiply_by_three', 'multiply_by_three',350                    'multiply_by_three', 'multiply_by_three',351                    'multiply_by_two', 'add_one', 'multiply_by_two',352                    'multiply_by_three'353                ],354                [355                    'multiply_by_three', 'multiply_by_three', 'add_one',356                    'add_one', 'multiply_by_two', 'multiply_by_three',357                    'multiply_by_three', 'multiply_by_three',358                    'multiply_by_three', 'multiply_by_three',359                    'multiply_by_three', 'add_one', 'multiply_by_three',360                    'multiply_by_two'361                ],362                [363                    'multiply_by_two', 'multiply_by_three', 'add_one',364                    'multiply_by_three', 'add_one', 'multiply_by_three',365                    'multiply_by_three', 'multiply_by_three',366                    'multiply_by_three', 'multiply_by_three',367                    'multiply_by_three', 'add_one', 'multiply_by_three',368                    'multiply_by_two'369                ],370                [371                    'add_one', 'multiply_by_three', 'add_one',372                    'multiply_by_three', 'add_one', 'multiply_by_three',373                    'multiply_by_three', 'multiply_by_three',374                    'multiply_by_three', 'multiply_by_three',375                    'multiply_by_three', 'add_one', 'multiply_by_three',376                    'multiply_by_two'377                ],378                [379                    'multiply_by_three', 'multiply_by_two', 'add_one',380                    'multiply_by_three', 'add_one', 'multiply_by_three',381                    'multiply_by_three', 'multiply_by_three',382                    'multiply_by_three', 'multiply_by_three',383                    'multiply_by_three', 'add_one', 'multiply_by_three',384                    'multiply_by_two'385                ],386                [387                    'multiply_by_three', 'multiply_by_three', 'add_one',388                    'add_one', 'multiply_by_three', 'multiply_by_two',389                    'multiply_by_three', 'multiply_by_three',390                    'multiply_by_three', 'multiply_by_three',391                    'multiply_by_three', 'add_one', 'multiply_by_three',392                    'multiply_by_two'393                ],394                [395                    'multiply_by_three', 'multiply_by_three', 'add_one',396                    'add_one', 'multiply_by_three', 'multiply_by_three',397                    'multiply_by_two', 'multiply_by_three',398                    'multiply_by_three', 'multiply_by_three',399                    'multiply_by_three', 'add_one', 'multiply_by_three',400                    'multiply_by_two'401                ],402                [403                    'multiply_by_three', 'multiply_by_three', 'add_one',404                    'add_one', 'multiply_by_three', 'multiply_by_three',405                    'multiply_by_three', 'multiply_by_two',406                    'multiply_by_three', 'multiply_by_three',407                    'multiply_by_three', 'add_one', 'multiply_by_three',408                    'multiply_by_two'409                ],410                [411                    'multiply_by_three', 'multiply_by_three', 'add_one',412                    'add_one', 'multiply_by_three', 'multiply_by_three',413                    'multiply_by_three', 'multiply_by_three',414                    'multiply_by_two', 'multiply_by_three',415                    'multiply_by_three', 'add_one', 'multiply_by_three',416                    'multiply_by_two'417                ],418                [419                    'multiply_by_three', 'multiply_by_three', 'add_one',420                    'add_one', 'multiply_by_three', 'multiply_by_three',421                    'multiply_by_three', 'multiply_by_three',422                    'multiply_by_three', 'multiply_by_two',423                    'multiply_by_three', 'add_one', 'multiply_by_three',424                    'multiply_by_two'425                ],426                [427                    'multiply_by_three', 'multiply_by_three', 'add_one',428                    'add_one', 'multiply_by_three', 'multiply_by_three',429                    'multiply_by_three', 'multiply_by_three',430                    'multiply_by_three', 'multiply_by_three',431                    'multiply_by_two', 'add_one', 'multiply_by_three',432                    'multiply_by_two'433                ]434            ],435            operations)436        self.assert_sequences_and_operations(n, sequences, operations)437class OptimalSequenceSimplifiedTestCase(unittest.TestCase):438    def test_with_negative(self):439        with self.assertRaisesRegex(AssertionError, ''):440            optimal_sequence_simplified(0)441    def test_with_0(self):442        with self.assertRaisesRegex(AssertionError, ''):443            optimal_sequence_simplified(0)444    def test_with_1(self):445        n = 1446        sequence = optimal_sequence_simplified(n)447        self.assertEqual([ 1 ], sequence)448    def test_with_2(self):449        n = 2450        sequence = optimal_sequence_simplified(n)451        self.assertEqual(452            [ 1, 2 ],453            sequence)454    def test_with_3(self):455        n = 3456        sequence = optimal_sequence_simplified(n)457        self.assertEqual(458            [ 1, 3 ],459            sequence)460    def test_with_4(self):461        n = 4462        sequence = optimal_sequence_simplified(n)463        self.assertEqual(464            [ 1, 2, 4 ],465            sequence)466    def test_with_5(self):467        n = 5468        sequence = optimal_sequence_simplified(n)469        self.assertEqual(470            [ 1, 2, 4, 5 ],471            sequence)472    def test_with_6(self):473        n = 6474        sequence = optimal_sequence_simplified(n)475        self.assertEqual(476            [ 1, 2, 6 ],477            sequence)478    def test_with_7(self):479        n = 7480        sequence = optimal_sequence_simplified(n)481        self.assertEqual(482            [ 1, 2, 6, 7 ],483            sequence)484    def test_with_8(self):485        n = 8486        sequence = optimal_sequence_simplified(n)487        self.assertEqual(488            [ 1, 2, 4, 8 ],489            sequence)490    def test_with_9(self):491        n = 9492        sequence = optimal_sequence_simplified(n)493        self.assertEqual(494            [ 1, 3, 9 ],495            sequence)496    def test_with_10(self):497        n = 10498        sequence = optimal_sequence_simplified(n)499        self.assertEqual(500            [ 1, 3, 9, 10 ],501            sequence)502    def test_with_96234(self):503        n = 96234504        sequence = optimal_sequence_simplified(n)505        self.assertEqual(506            [507                1, 3, 9, 10, 11, 22, 66, 198, 594, 1782, 5346, 16038,508                16039, 32078, 96234509            ],510            sequence)511if __name__ == '__main__':...multi-color-cube.js
Source:multi-color-cube.js  
1"use strict"; // good practice - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode2////////////////////////////////////////////////////////////////////////////////3/*global THREE, window, document, $*/4var camera, scene, renderer;5var cameraControls;6var clock = new THREE.Clock();7var ambientLight, light;8function drawCube0(x1, y1, z1, x2, y2, z2) {9	scene = new THREE.Scene();10	// CUBE MESH11	var material, geometry, mesh;12	material = new THREE.MeshBasicMaterial( { vertexColors: THREE.VertexColors } );13	geometry = new THREE.Geometry();14	geometry.vertices.push( new THREE.Vector3( x1, y1, z1 ) ); //vertex 015	geometry.vertices.push( new THREE.Vector3( x2, y1, z1 ) ); //vertex 116	geometry.vertices.push( new THREE.Vector3( x1, y2, z1 ) ); //vertex 217  geometry.vertices.push( new THREE.Vector3( x2, y2, z1 ) ); //vertex 318	geometry.vertices.push( new THREE.Vector3( x1, y2, z2 ) ); //vertex 419  geometry.vertices.push( new THREE.Vector3( x2, y2, z2 ) ); //vertex 520  geometry.vertices.push( new THREE.Vector3( x1, y1, z2 ) ); //vertex 621	geometry.vertices.push( new THREE.Vector3( x2, y1, z2 ) ); //vertex 722	var triangle0 = new THREE.Face3( 2, 1, 0);23  var triangle1 = new THREE.Face3( 2, 3, 1);24  var triangle2 = new THREE.Face3( 3, 2, 4);25  var triangle3 = new THREE.Face3( 3, 4, 5);26  var triangle4 = new THREE.Face3( 2, 0, 6);27  var triangle5 = new THREE.Face3( 2, 6, 4);28  var triangle6 = new THREE.Face3( 0, 1, 7);29  var triangle7 = new THREE.Face3( 0, 7, 6);30  var triangle8 = new THREE.Face3( 1, 3, 5);31  var triangle9 = new THREE.Face3( 1, 5, 7);32  var triangle10 = new THREE.Face3( 6, 7, 5);33  var triangle11 = new THREE.Face3( 6, 5, 4);34	triangle0.vertexColors[0] = new THREE.Color(0x000000);35	triangle0.vertexColors[1] = new THREE.Color(0x000000);36	triangle0.vertexColors[2] = new THREE.Color(0x000000);37  triangle1.vertexColors[0] = new THREE.Color(0x000000);38	triangle1.vertexColors[1] = new THREE.Color(0x000000);39	triangle1.vertexColors[2] = new THREE.Color(0x000000);40  triangle2.vertexColors[0] = new THREE.Color(0xff0000);41	triangle2.vertexColors[1] = new THREE.Color(0xff0000);42	triangle2.vertexColors[2] = new THREE.Color(0xff0000);43  triangle3.vertexColors[0] = new THREE.Color(0xff0000);44	triangle3.vertexColors[1] = new THREE.Color(0xff0000);45	triangle3.vertexColors[2] = new THREE.Color(0xff0000);46  triangle4.vertexColors[0] = new THREE.Color(0x00ff00);47	triangle4.vertexColors[1] = new THREE.Color(0x00ff00);48	triangle4.vertexColors[2] = new THREE.Color(0x00ff00);49  triangle5.vertexColors[0] = new THREE.Color(0x00ff00);50	triangle5.vertexColors[1] = new THREE.Color(0x00ff00);51	triangle5.vertexColors[2] = new THREE.Color(0x00ff00);52  triangle6.vertexColors[0] = new THREE.Color(0x0000ff);53	triangle6.vertexColors[1] = new THREE.Color(0x0000ff);54	triangle6.vertexColors[2] = new THREE.Color(0x0000ff);55  triangle7.vertexColors[0] = new THREE.Color(0x0000ff);56	triangle7.vertexColors[1] = new THREE.Color(0x0000ff);57	triangle7.vertexColors[2] = new THREE.Color(0x0000ff);58  triangle8.vertexColors[0] = new THREE.Color(0xffff00);59	triangle8.vertexColors[1] = new THREE.Color(0xffff00);60	triangle8.vertexColors[2] = new THREE.Color(0xffff00);61  triangle9.vertexColors[0] = new THREE.Color(0xffff00);62	triangle9.vertexColors[1] = new THREE.Color(0xffff00);63	triangle9.vertexColors[2] = new THREE.Color(0xffff00);64  triangle10.vertexColors[0] = new THREE.Color(0x00ffff);65	triangle10.vertexColors[1] = new THREE.Color(0x00ffff);66	triangle10.vertexColors[2] = new THREE.Color(0x00ffff);67  triangle11.vertexColors[0] = new THREE.Color(0x00ffff);68	triangle11.vertexColors[1] = new THREE.Color(0x00ffff);69	triangle11.vertexColors[2] = new THREE.Color(0x00ffff);70  geometry.faces.push( triangle0 );71	geometry.faces.push( triangle1 );72  geometry.faces.push( triangle2 ); //triangle73  geometry.faces.push( triangle3 ); //triangle74  geometry.faces.push( triangle4 ); //triangle75  geometry.faces.push( triangle5 ); //triangle76  geometry.faces.push( triangle6 ); //triangle77  geometry.faces.push( triangle7 ); //triangle78  geometry.faces.push( triangle8 ); //triangle79  geometry.faces.push( triangle9 ); //triangle80  geometry.faces.push( triangle10 ); //triangle81  geometry.faces.push( triangle11 ); //triangle82	mesh = new THREE.Mesh( geometry, material );83	scene.add( mesh );84}85function drawCube1(x1, y1, z1, x2, y2, z2) {86	scene = new THREE.Scene();87	// CUBE MESH88	var material, geometry, mesh;89	material = new THREE.MeshLambertMaterial( { vertexColors: THREE.VertexColors } );90	geometry = new THREE.Geometry();91	geometry.vertices.push( new THREE.Vector3( x1, y1, z1 ) ); //vertex 092	geometry.vertices.push( new THREE.Vector3( x2, y1, z1 ) ); //vertex 193	geometry.vertices.push( new THREE.Vector3( x1, y2, z1 ) ); //vertex 294  geometry.vertices.push( new THREE.Vector3( x2, y2, z1 ) ); //vertex 395	geometry.vertices.push( new THREE.Vector3( x1, y2, z2 ) ); //vertex 496  geometry.vertices.push( new THREE.Vector3( x2, y2, z2 ) ); //vertex 597  geometry.vertices.push( new THREE.Vector3( x1, y1, z2 ) ); //vertex 698	geometry.vertices.push( new THREE.Vector3( x2, y1, z2 ) ); //vertex 799	var triangle0 = new THREE.Face3( 2, 1, 0);100  var triangle1 = new THREE.Face3( 2, 3, 1);101  var triangle2 = new THREE.Face3( 3, 2, 4);102  var triangle3 = new THREE.Face3( 3, 4, 5);103  var triangle4 = new THREE.Face3( 2, 0, 6);104  var triangle5 = new THREE.Face3( 2, 6, 4);105  var triangle6 = new THREE.Face3( 0, 1, 7);106  var triangle7 = new THREE.Face3( 0, 7, 6);107  var triangle8 = new THREE.Face3( 1, 3, 5);108  var triangle9 = new THREE.Face3( 1, 5, 7);109  var triangle10 = new THREE.Face3( 6, 7, 5);110  var triangle11 = new THREE.Face3( 6, 5, 4);111	triangle0.vertexColors[0] = new THREE.Color(0x000000);112	triangle0.vertexColors[1] = new THREE.Color(0x000000);113	triangle0.vertexColors[2] = new THREE.Color(0x000000);114  triangle1.vertexColors[0] = new THREE.Color(0x000000);115	triangle1.vertexColors[1] = new THREE.Color(0x000000);116	triangle1.vertexColors[2] = new THREE.Color(0x000000);117  triangle2.vertexColors[0] = new THREE.Color(0xff0000);118	triangle2.vertexColors[1] = new THREE.Color(0xff0000);119	triangle2.vertexColors[2] = new THREE.Color(0xff0000);120  triangle3.vertexColors[0] = new THREE.Color(0xff0000);121	triangle3.vertexColors[1] = new THREE.Color(0xff0000);122	triangle3.vertexColors[2] = new THREE.Color(0xff0000);123  triangle4.vertexColors[0] = new THREE.Color(0x00ff00);124	triangle4.vertexColors[1] = new THREE.Color(0x00ff00);125	triangle4.vertexColors[2] = new THREE.Color(0x00ff00);126  triangle5.vertexColors[0] = new THREE.Color(0x00ff00);127	triangle5.vertexColors[1] = new THREE.Color(0x00ff00);128	triangle5.vertexColors[2] = new THREE.Color(0x00ff00);129  triangle6.vertexColors[0] = new THREE.Color(0x0000ff);130	triangle6.vertexColors[1] = new THREE.Color(0x0000ff);131	triangle6.vertexColors[2] = new THREE.Color(0x0000ff);132  triangle7.vertexColors[0] = new THREE.Color(0x0000ff);133	triangle7.vertexColors[1] = new THREE.Color(0x0000ff);134	triangle7.vertexColors[2] = new THREE.Color(0x0000ff);135  triangle8.vertexColors[0] = new THREE.Color(0xffff00);136	triangle8.vertexColors[1] = new THREE.Color(0xffff00);137	triangle8.vertexColors[2] = new THREE.Color(0xffff00);138  triangle9.vertexColors[0] = new THREE.Color(0xffff00);139	triangle9.vertexColors[1] = new THREE.Color(0xffff00);140	triangle9.vertexColors[2] = new THREE.Color(0xffff00);141  triangle10.vertexColors[0] = new THREE.Color(0x00ffff);142	triangle10.vertexColors[1] = new THREE.Color(0x00ffff);143	triangle10.vertexColors[2] = new THREE.Color(0x00ffff);144  triangle11.vertexColors[0] = new THREE.Color(0x00ffff);145	triangle11.vertexColors[1] = new THREE.Color(0x00ffff);146	triangle11.vertexColors[2] = new THREE.Color(0x00ffff);147  geometry.faces.push( triangle0 );148	geometry.faces.push( triangle1 );149  geometry.faces.push( triangle2 ); //triangle150  geometry.faces.push( triangle3 ); //triangle151  geometry.faces.push( triangle4 ); //triangle152  geometry.faces.push( triangle5 ); //triangle153  geometry.faces.push( triangle6 ); //triangle154  geometry.faces.push( triangle7 ); //triangle155  geometry.faces.push( triangle8 ); //triangle156  geometry.faces.push( triangle9 ); //triangle157  geometry.faces.push( triangle10 ); //triangle158  geometry.faces.push( triangle11 ); //triangle159	geometry.computeVertexNormals();160	mesh = new THREE.Mesh( geometry, material );161	scene.add( mesh );162  // LIGHTS163	scene.add( ambientLight );164	scene.add( light );165}166function drawCubes(x1, y1, z1, x2, y2, z2){167	scene = new THREE.Scene();168	for (var i = 0; i < 1000; i++){169		var x = Math.random()*100-50;170		var y = Math.random()*100-50;171		var z = Math.random()*100-50;172		if (x*x + y*y + z*z < 1000){173			var material = new THREE.MeshLambertMaterial({color:0xa6b3d8, opacity: 1-(x*x + y*y + z*z)/1000, transparent: true});174			var geometry = new THREE.Mesh( new THREE.CubeGeometry(5, 5, 5), material);175			geometry.position.set(x, y, z);176			scene.add(geometry);177		}178	}179	// LIGHTS180	scene.add( ambientLight );181	scene.add( light );182}183function init() {184	var canvasWidth = 846;185	var canvasHeight = 494;186	// For grading the window is fixed in size; here's general code:187	//var canvasWidth = window.innerWidth;188	//var canvasHeight = window.innerHeight;189	var canvasRatio = canvasWidth / canvasHeight;190	// RENDERER191	renderer = new THREE.WebGLRenderer( { antialias: true } );192	renderer.gammaInput = true;193	renderer.gammaOutput = true;194	renderer.setSize(canvasWidth, canvasHeight);195	renderer.setClearColor( 0xAAAAAA, 1.0 );196  // LIGHTS197	ambientLight = new THREE.AmbientLight( 0x222222, 0.6 );198	light = new THREE.DirectionalLight( 0xFFFFFF );199	light.position.set( -1, -1, -1 );200	// CAMERA201	camera = new THREE.PerspectiveCamera( 55, canvasRatio, 1, 4000 );202	camera.position.set( 100, 150, 130 );203	// CONTROLS204	cameraControls = new THREE.OrbitControls(camera, renderer.domElement);205	cameraControls.target.set(0,0,0);206}207function addToDOM() {208	var container = document.getElementById('container5');209	var canvas = container.getElementsByTagName('canvas');210	if (canvas.length>0) {211		container.removeChild(canvas[0]);212	}213	container.appendChild( renderer.domElement );214}215function animate() {216	window.requestAnimationFrame(animate);217	render();218}219function render() {220	var delta = clock.getDelta();221	cameraControls.update(delta);222	renderer.render(scene, camera);223}224try {225	init();226	drawCubes();227	addToDOM();228	animate();229} catch(e) {230	var errorReport = "Your program encountered an unrecoverable error, can not draw on canvas. Error was:<br/><br/>";231	$('#container').append(errorReport+e);...challenge-1.py
Source:challenge-1.py  
1"""2This is a dumb calculator that can add and subtract whole numbers from zero to five.3When you run the code, you are prompted to enter two numbers (in the form of English4word instead of number) and the operator sign (also in the form of English word).5The code will perform the calculation and give the result if your input is what it6expects.7The code is very long and messy. Refactor it according to what you have learned about8code simplicity and efficiency.9"""10print('Welcome to this calculator!')11print('It can add and subtract whole numbers from zero to five')12a = input('Please choose your first number (zero to five): ')13b = input('What do you want to do? plus or minus: ')14c = input('Please choose your second number (zero to five): ')15if a == 'zero' and b == 'plus'  and c == 'zero':16    print("zero plus zero equals zero")17if a == 'zero' and b == 'plus'  and c == 'one':18    print("zero plus one equals one")19if a == 'zero' and b == 'plus'  and c == 'two':20    print("zero plus two equals two")21if a == 'zero' and b == 'plus'  and c == 'three':22    print("zero plus three equals three")23if a == 'zero' and b == 'plus'  and c == 'four':24    print("zero plus four equals four")25if a == 'zero' and b == 'plus'  and c == 'five':26    print("zero plus five equals five")27if a == 'one' and b == 'plus'  and c == 'zero':28    print("one plus zero equals one")29if a == 'one' and b == 'plus'  and c == 'one':30    print("one plus one equals two")31if a == 'one' and b == 'plus'  and c == 'two':32    print("one plus two equals three")33if a == 'one' and b == 'plus'  and c == 'three':34    print("one plus three equals four")35if a == 'one' and b == 'plus'  and c == 'four':36    print("one plus four equals five")37if a == 'one' and b == 'plus'  and c == 'five':38    print("one plus five equals six")39if a == 'two' and b == 'plus'  and c == 'zero':40    print("two plus zero equals two")41if a == 'two' and b == 'plus'  and c == 'one':42    print("two plus one equals three")43if a == 'two' and b == 'plus'  and c == 'two':44    print("two plus two equals four")45if a == 'two' and b == 'plus'  and c == 'three':46    print("two plus three equals five")47if a == 'two' and b == 'plus'  and c == 'four':48    print("two plus four equals six")49if a == 'two' and b == 'plus'  and c == 'five':50    print("two plus five equals seven")51if a == 'three' and b == 'plus'  and c == 'zero':52    print("three plus zero equals three")53if a == 'three' and b == 'plus'  and c == 'one':54    print("three plus one equals four")55if a == 'three' and b == 'plus'  and c == 'two':56    print("three plus two equals five")57if a == 'three' and b == 'plus'  and c == 'three':58    print("three plus three equals six")59if a == 'three' and b == 'plus'  and c == 'four':60    print("three plus four equals seven")61if a == 'three' and b == 'plus'  and c == 'five':62    print("three plus five equals eight")63if a == 'four' and b == 'plus'  and c == 'zero':64    print("four plus zero equals four")65if a == 'four' and b == 'plus'  and c == 'one':66    print("four plus one equals five")67if a == 'four' and b == 'plus'  and c == 'two':68    print("four plus two equals six")69if a == 'four' and b == 'plus'  and c == 'three':70    print("four plus three equals seven")71if a == 'four' and b == 'plus'  and c == 'four':72    print("four plus four equals eight")73if a == 'four' and b == 'plus'  and c == 'five':74    print("four plus five equals nine")75if a == 'five' and b == 'plus'  and c == 'zero':76    print("five plus zero equals five")77if a == 'five' and b == 'plus'  and c == 'one':78    print("five plus one equals six")79if a == 'five' and b == 'plus'  and c == 'two':80    print("five plus two equals seven")81if a == 'five' and b == 'plus'  and c == 'three':82    print("five plus three equals eight")83if a == 'five' and b == 'plus'  and c == 'four':84    print("five plus four equals nine")85if a == 'five' and b == 'plus'  and c == 'five':86    print("five plus five equals ten")87if a == 'zero' and b == 'minus' and c == 'zero':88    print("zero minus zero equals zero")89if a == 'zero' and b == 'minus' and c == 'one':90    print("zero minus one equals negative one")91if a == 'zero' and b == 'minus' and c == 'two':92    print("zero minus two equals negative two")93if a == 'zero' and b == 'minus' and c == 'three':94    print("zero minus three equals negative three")95if a == 'zero' and b == 'minus' and c == 'four':96    print("zero minus four equals negative four")97if a == 'zero' and b == 'minus' and c == 'five':98    print("zero minus five equals negative five")99if a == 'one' and b == 'minus' and c == 'zero':100    print("one minus zero equals one")101if a == 'one' and b == 'minus' and c == 'one':102    print("one minus one equals zero")103if a == 'one' and b == 'minus' and c == 'two':104    print("one minus two equals negative one")105if a == 'one' and b == 'minus' and c == 'three':106    print("one minus three equals negative three")107if a == 'one' and b == 'minus' and c == 'four':108    print("one minus four equals negative three")109if a == 'one' and b == 'minus' and c == 'five':110    print("one minus five equals negative four")111if a == 'two' and b == 'minus' and c == 'zero':112    print("two minus zero equals two")113if a == 'two' and b == 'minus' and c == 'one':114    print("two minus one equals one")115if a == 'two' and b == 'minus' and c == 'two':116    print("two minus two equals zero")117if a == 'two' and b == 'minus' and c == 'three':118    print("two minus three equals negative one")119if a == 'two' and b == 'minus' and c == 'four':120    print("two minus four equals negative two")121if a == 'two' and b == 'minus' and c == 'five':122    print("two minus five equals negative three")123if a == 'three' and b == 'minus' and c == 'zero':124    print("three minus zero equals three")125if a == 'three' and b == 'minus' and c == 'one':126    print("three minus one equals two")127if a == 'three' and b == 'minus' and c == 'two':128    print("three minus two equals one")129if a == 'three' and b == 'minus' and c == 'three':130    print("three minus three equals zero")131if a == 'three' and b == 'minus' and c == 'four':132    print("three minus four equals negative one")133if a == 'three' and b == 'minus' and c == 'five':134    print("three minus five equals negative two")135if a == 'four' and b == 'minus' and c == 'zero':136    print("four minus zero equals four")137if a == 'four' and b == 'minus' and c == 'one':138    print("four minus one equals three")139if a == 'four' and b == 'minus' and c == 'two':140    print("four minus two equals two")141if a == 'four' and b == 'minus' and c == 'three':142    print("four minus three equals one")143if a == 'four' and b == 'minus' and c == 'four':144    print("four minus four equals zero")145if a == 'four' and b == 'minus' and c == 'five':146    print("four minus five equals negative one")147if a == 'five' and b == 'minus' and c == 'zero':148    print("five minus zero equals five")149if a == 'five' and b == 'minus' and c == 'one':150    print("five minus one equals four")151if a == 'five' and b == 'minus' and c == 'two':152    print("five minus two equals three")153if a == 'five' and b == 'minus' and c == 'three':154    print("five minus three equals two")155if a == 'five' and b == 'minus' and c == 'four':156    print("five minus four equals one")157if a == 'five' and b == 'minus' and c == 'five':158    print("five minus five equals zero")159if (not a == 'zero' and not a == 'one' and not a == 'two' and not a == 'three' and not a == 'four' and not a == 'five') or (not c == 'zero' and not c == 'one' and not c == 'two' and not c == 'three' and not c == 'four' and not c == 'five') or (not b == 'plus' and not b == 'minus'):160    print("I am not able to answer this question. Check your input.")...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
