Skip to content

Commit

Permalink
Pruning.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJWayne committed Dec 30, 2013
1 parent bfb38c8 commit e807c78
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 54 deletions.
29 changes: 0 additions & 29 deletions js/vendor/accurate_interval.coffee

This file was deleted.

25 changes: 0 additions & 25 deletions js/vendor/accurate_interval.js

This file was deleted.

19 changes: 19 additions & 0 deletions layers/background/pistonchute/frag.glsl
@@ -0,0 +1,19 @@
varying vec2 uvCoord;
varying vec3 vNormal;
varying float depth;

uniform vec3 baseColor;

void main() {
gl_FragColor.xyz = baseColor;

// Apply some basic lighting
vec3 light = vec3(0.5, 0.4, 1.0);
float lightScalar = abs(dot(vNormal, light));
lightScalar += 0.2; // ambient
gl_FragColor.xyz *= lightScalar;

// Apply fog
float fog = smoothstep(1000.0, 150.0, depth);
gl_FragColor.xyz *= fog;
}
105 changes: 105 additions & 0 deletions layers/background/pistonchute/main.coffee
@@ -0,0 +1,105 @@
module.exports = class PistonChute extends Lysertron.Layer
uniformAttrs:
baseColor: 'c'

initialize: ->
@radialQty = 24
@lengthQty = 24

@radius = 120
@length = 5000

@currentBeatCount = 0

@rotationSpeed = new THREE.Vector3(
0
THREE.Math.randFloatSpread(40.degToRad)
0
)

@baseColor = new THREE.Color().setHSV(
Math.random()
0.5
0.5
)


@chute = new THREE.Mesh(
new THREE.CylinderGeometry(@radius, @radius, @length, 64, 1, true)
new THREE.ShaderMaterial(
uniforms: @uniforms
vertexShader: assets['vert.glsl']
fragmentShader: assets['frag.glsl']
side: THREE.DoubleSide
)
)
@chute.rotation.x = 90.degToRad
@add @chute

# Pistons
@pistonGeom = new THREE.CubeGeometry(20, 20, 20)
@pistonMat = new THREE.ShaderMaterial(
uniforms: @uniforms
vertexShader: assets['vert.glsl']
fragmentShader: assets['frag.glsl']
)

@pistons = []
for u in [0...@radialQty]
for v in [0..@lengthQty]
piston = new THREE.Mesh(
@pistonGeom
@pistonMat
)
piston.direction = -1
piston.scale.z = @getScale piston

piston.direction = [1, -1].random()
piston.beatNum = [0..3].random()

angle = u / @radialQty * 2 * Math.PI
angle += v * 2

piston.position.set(
Math.sin(angle) * @radius
v * 30
Math.cos(angle) * @radius
)

piston.rotation.y = angle
piston.rotation.z = 45.degToRad

@pistons.push piston
@chute.add piston

getScale: (piston) ->
if piston.direction is 1
3.2
else
0.5


update: (elapsed) ->
rotation = THREE.Vector3.temp(@rotationSpeed)
rotation.multiplyScalar elapsed
@chute.rotation.add rotation

onBeat: (beat) ->
@currentBeatCount++

animateUpBeat = @currentBeatCount % 4
for piston in @pistons when piston.beatNum is animateUpBeat
# easing = [TWEEN.Easing.Cubic, TWEEN.Easing.Quadratic, ]
piston.direction = 1
new TWEEN.Tween(piston.scale)
.to({z: @getScale(piston)}, beat.duration * 1000)
.easing(TWEEN.Easing.Back.In)
.start()

animateDownBeat = (@currentBeatCount - 1) % 4
for piston in @pistons when piston.beatNum is animateDownBeat
piston.direction = -1
new TWEEN.Tween(piston.scale)
.to({z: @getScale(piston)}, beat.duration * 3 * 1000)
.easing(TWEEN.Easing.Cubic.InOut)
.start()
11 changes: 11 additions & 0 deletions layers/background/pistonchute/vert.glsl
@@ -0,0 +1,11 @@
varying vec2 uvCoord;
varying vec3 vNormal;
varying float depth;

void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);

uvCoord = uv;
vNormal = normal;
depth = gl_Position.z;
}

0 comments on commit e807c78

Please sign in to comment.