summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx/primitives
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/mx/primitives')
-rw-r--r--public/assets/javascripts/mx/primitives/mx.grid.js70
-rw-r--r--public/assets/javascripts/mx/primitives/mx.image.js42
-rw-r--r--public/assets/javascripts/mx/primitives/mx.point.js17
-rw-r--r--public/assets/javascripts/mx/primitives/mx.polyline.js57
-rw-r--r--public/assets/javascripts/mx/primitives/mx.soundcloud.js130
-rw-r--r--public/assets/javascripts/mx/primitives/mx.text.js75
-rw-r--r--public/assets/javascripts/mx/primitives/mx.video.js17
-rw-r--r--public/assets/javascripts/mx/primitives/mx.vimeo.js30
-rw-r--r--public/assets/javascripts/mx/primitives/mx.youtube.js28
9 files changed, 425 insertions, 41 deletions
diff --git a/public/assets/javascripts/mx/primitives/mx.grid.js b/public/assets/javascripts/mx/primitives/mx.grid.js
new file mode 100644
index 0000000..a765c89
--- /dev/null
+++ b/public/assets/javascripts/mx/primitives/mx.grid.js
@@ -0,0 +1,70 @@
+MX.Grid = MX.Object3D.extend({
+ init: function (ops) {
+
+ this.type = "Grid"
+
+ var ops = this.ops = defaults(ops, {
+ x: 0,
+ y: 0,
+ z: 0,
+ space: 20,
+ cells: 20,
+ })
+
+ ops.side = ops.space * ops.cells
+
+ var ctx, canvas = document.createElement("canvas")
+
+ this.el = canvas
+ this.width = this.height = canvas.width = canvas.height = ops.side + 4
+
+ ctx = canvas.getContext('2d')
+
+ this.x = ops.x || 0
+ this.y = ops.y || 0
+ this.z = ops.z || 0
+ this.rotationX = PI/2
+ this.scale = ops.scale || 1
+ this.backface = ops.backface || false
+
+ ops.className && this.el.classList.add(ops.className)
+ this.backface && this.el.classList.add("backface-visible")
+ this.el.classList.add("mx-grid")
+
+ this.draw(ctx)
+ },
+
+ draw: function(ctx, recenter){
+ ctx = ctx || this.ctx
+
+ if (recenter) {
+ ctx.save()
+ ctx.translate( -grid.width/2, -grid.height/2 )
+ }
+
+ var cells = this.ops.cells,
+ space = this.ops.space,
+ side = this.ops.side
+
+ ctx.strokeStyle = "#444"
+ ctx.lineWidth = 1
+ ctx.beginPath()
+ ctx.translate(1,1)
+ for (var i = 0; i <= cells; i++) {
+ ctx.moveTo(i*space, 0)
+ ctx.lineTo(i*space, side)
+ ctx.moveTo(0, i*space)
+ ctx.lineTo(side, i*space)
+ }
+ ctx.closePath()
+ ctx.stroke()
+
+ if (recenter) {
+ ctx.restore()
+ }
+
+ },
+
+})
+
+
diff --git a/public/assets/javascripts/mx/primitives/mx.image.js b/public/assets/javascripts/mx/primitives/mx.image.js
index 575e9c0..ce99592 100644
--- a/public/assets/javascripts/mx/primitives/mx.image.js
+++ b/public/assets/javascripts/mx/primitives/mx.image.js
@@ -1,6 +1,7 @@
MX.Image = MX.Object3D.extend({
init: function (ops) {
-
+ ops = ops || {}
+
this.type = "Image"
this.media = ops.media
this.width = 0
@@ -12,13 +13,13 @@ MX.Image = MX.Object3D.extend({
this.backface = ops.backface || false
ops.className && this.el.classList.add(ops.className)
- this.backface && this.el.classList.add("backface-visible")
+ this.backface && this.el.classList.add("backface-visible")
this.el.classList.add("image")
this.el.classList.add("mx-scenery")
this.el.style.backgroundRepeat = 'no-repeat'
- this.load(ops)
+ ops.src && this.load(ops)
},
load: function(ops){
@@ -41,8 +42,41 @@ MX.Image = MX.Object3D.extend({
layer.el.classList.add('image')
layer.dirty = true
layer.update()
+ layer.ops.onload
+
+ if (ops.keepImage) {
+ layer.image = image
+ }
+ }
+
+ if (ops.src) {
+ image.src = ops.src
+ }
+ else if (ops.media) {
+ image.src = ops.media.url
+ }
+ else if (ops.url) {
+ image.src = ops.url
+ }
+ },
+
+ draw: function(ctx, recenter){
+ if (! this.image) { return }
+
+ if (recenter) {
+ ctx.save()
+ ctx.scale(-1, 1)
+ ctx.translate( -this.width/2 * this.scale, -this.height/2 * this.scale )
+ }
+
+ ctx.drawImage(this.image,
+ 0, 0, this.image.naturalWidth, this.image.naturalHeight,
+ 0, 0, this.image.width * this.scale * devicePixelRatio, this.image.height * this.scale * devicePixelRatio
+ )
+
+ if (recenter) {
+ ctx.restore()
}
- image.src = ops.src;
},
})
diff --git a/public/assets/javascripts/mx/primitives/mx.point.js b/public/assets/javascripts/mx/primitives/mx.point.js
new file mode 100644
index 0000000..41a7732
--- /dev/null
+++ b/public/assets/javascripts/mx/primitives/mx.point.js
@@ -0,0 +1,17 @@
+MX.Point = MX.Object3D.extend({
+ init: function(p){
+ this.updateChildren = false
+ this.move({
+ x: p.a,
+ y: 11,
+ z: p.b,
+ width: 20,
+ height: 20,
+ rotationX: PI/2,
+ })
+ this.el.style.backgroundColor = 'rgb(' + [abs(floor(p.a*30)), 0, abs(floor(p.b*30))] + ')'
+ this.el.style.backfaceVisibility = "visible"
+ this.el.style.borderRadius = "50%"
+ scene.add(this)
+ }
+})
diff --git a/public/assets/javascripts/mx/primitives/mx.polyline.js b/public/assets/javascripts/mx/primitives/mx.polyline.js
new file mode 100644
index 0000000..e549150
--- /dev/null
+++ b/public/assets/javascripts/mx/primitives/mx.polyline.js
@@ -0,0 +1,57 @@
+MX.Polyline = MX.Object3D.extend({
+ init: function(polyline){
+ this.faces = []
+ this.points = polyline.points
+ for (var i = 1; i < this.points.length; i++) {
+ var mx = new MX.Object3D()
+ var head = this.points[i-1]
+ var tail = this.points[i]
+ this.move_face(mx, head, tail)
+ this.faces.push(mx)
+ scene.add(mx)
+ }
+ },
+
+ rebuild: function(){
+ for (var i = 1; i < this.points.length; i++) {
+ var mx = this.faces[i-1]
+ var head = this.points[i-1]
+ var tail = this.points[i]
+ this.move_face(mx, head, tail)
+ }
+ },
+
+ move_face: function (mx, head, tail){
+ var mid_x = (head.a + tail.a)
+ var mid_z = (head.b + tail.b)
+ var len = head.distanceTo( tail )
+ var angle = atan2( head.b - tail.b, head.a - tail.a )
+ mx.move({
+ x: mid_x / 2,
+ y: wallHeight/2 + 1,
+ z: mid_z / 2,
+ width: ceil(len),
+ height: wallHeight,
+ rotationY: angle
+ })
+ // var hue = abs(round( angle / PI * 90 + 300))
+ // mx.el.style.backgroundColor = 'hsl(' + [hue, "100%", "50%"] + ')'
+ var lum = abs(round( angle / PI * 20 + 70))
+ mx.el.style.backgroundColor = 'hsla(' + ["0", "0%", lum + "%", "0.99"] + ')'
+ },
+
+ set_height: function(height){
+ for (var i = 0; i < this.faces.length; i++) {
+ this.faces[i].height = height
+ this.faces[i].y = height / 2 + 1
+ }
+ },
+
+ destroy: function(){
+ this.faces.forEach(function(mx){
+ scene.remove(mx)
+ })
+ this.faces = null
+ this.points = null
+ },
+})
diff --git a/public/assets/javascripts/mx/primitives/mx.soundcloud.js b/public/assets/javascripts/mx/primitives/mx.soundcloud.js
new file mode 100644
index 0000000..fecb2f4
--- /dev/null
+++ b/public/assets/javascripts/mx/primitives/mx.soundcloud.js
@@ -0,0 +1,130 @@
+MX.Soundcloud = MX.Object3D.extend({
+ init: function (ops) {
+
+ this.type = "Soundcloud"
+ this.media = ops.media
+ this.width = 0
+ this.height = 0
+ this.x = ops.x || 0
+ this.y = ops.y || 0
+ this.z = ops.z || 0
+ this.scale = ops.scale || 1
+ this.backface = ops.backface || false
+
+ ops.className && this.el.classList.add(ops.className)
+ this.backface && this.el.classList.add("backface-visible")
+ this.el.classList.add("audio")
+ this.el.classList.add("mx-scenery")
+
+ this.el.style.backgroundRepeat = 'no-repeat'
+ this.paused = true
+
+ this.ops = ops
+ },
+
+ load: function(ops){
+ if (ops) {
+ ops = this.ops = defaults(ops, this.ops)
+ }
+ else {
+ ops = this.ops
+ }
+
+ this.width = ops.media.width
+ this.height = ops.media.height
+
+ var tag = Parser.lookup.soundcloud.tag(ops.media)
+ var $iframe = $(tag)
+ var iframe = $iframe[0]
+ $iframe.css('z-index', '-1')
+ this.el.appendChild( iframe )
+
+ var overlay = this.overlay = document.createElement("div")
+ overlay.style.width = "100%"
+ overlay.style.height = "100%"
+ overlay.style.position = "absolute"
+ overlay.style.top = "0"
+ overlay.style.left = "0"
+ overlay.style.zIndex = "2"
+ overlay.className = "overlay"
+ this.el.appendChild(overlay)
+
+ this.player = SC.Widget( iframe )
+ this.player.setVolume(80)
+
+ this.duration = 0
+
+ this.player.bind(SC.Widget.Events.READY, this.ready.bind(this))
+// this.player.bind(SC.Widget.Events.LOAD_PROGRESS, this.loadProgress.bind(this))
+// this.player.bind(SC.Widget.Events.PLAY_PROGRESS, this.playProgress.bind(this))
+ this.player.bind(SC.Widget.Events.PLAY, this.didPlay.bind(this))
+ this.player.bind(SC.Widget.Events.PAUSE, this.didPause.bind(this))
+ this.player.bind(SC.Widget.Events.FINISH, this.finished.bind(this))
+ },
+
+ ready: function(){
+ this.seek( this.media.keyframe || 0 )
+
+ if (this.media.autoplay) {
+ this.play()
+ }
+
+ this.player.getDuration(function(duration){
+ this.duration = duration
+ }.bind(this))
+ },
+
+ play: function(){
+ this.player.play()
+ },
+
+ pause: function(){
+ this.player.pause()
+ },
+
+ toggle: function(state){
+ if (typeof state === "boolean") {
+ if (state) this.play()
+ else this.pause()
+ }
+ else {
+ this.player.toggle()
+ }
+ },
+
+ seek: function(n){
+ if (n < 1) {
+ n = n * this.duration
+ }
+ this.player.seekTo(n)
+ },
+
+ setLoop: function(state){
+ this.media.loop = state
+ },
+
+ setVolume: function(n){
+ if (this.muted || ! this.player) return
+ this.player.setVolume(floor( n * 100 ))
+ },
+
+ didPlay: function(){
+ this.paused = false
+ },
+
+ didPause: function(){
+ this.paused = true
+ },
+
+ finished: function(){
+ console.log("soundcloud finished")
+ if (this.media.loop) {
+ this.seek(0)
+ this.play()
+ }
+ else if (this.bound) {
+ $(".playButton").removeClass('playing')
+ }
+ },
+
+})
diff --git a/public/assets/javascripts/mx/primitives/mx.text.js b/public/assets/javascripts/mx/primitives/mx.text.js
index 9c7af5c..3095b67 100644
--- a/public/assets/javascripts/mx/primitives/mx.text.js
+++ b/public/assets/javascripts/mx/primitives/mx.text.js
@@ -3,34 +3,57 @@ MX.Text = MX.Object3D.extend({
init: function (ops) {
this.type = "Text"
-
- var layer = new MX.Object3D('text')
- layer.width = ops.width || 100
- layer.height = ops.height || 50
- layer.x = ops.x || 0
- layer.y = ops.y || 0
- layer.z = ops.z || 0
- layer.scale = ops.scale || 1
- layer.el.innerHTML = ops.value || ""
- if (ops.id) layer.el.id = ops.id;
- if (ops.background) layer.el.style.background = ops.background;
- if (ops.color) layer.el.style.color = ops.color;
- if (ops.fontSize) layer.el.style.fontSize = ops.fontSize + "px";
- this.add(layer)
+ this.type = "Image"
+ this.media = ops.media
+ this.width = 0
+ this.height = 0
+ this.x = ops.x || 0
+ this.y = ops.y || 0
+ this.z = ops.z || 0
+ this.scale = ops.scale || 1
+ this.backface = ops.backface || false
+
+ this.scale = ops.scale || 1
+ this.width = ops.media.width
+ this.height = ops.media.height
+ this.x = ops.x || 0
+ this.y = ops.y || 0
+ this.z = ops.z || 0
+ this.rotationX = ops.rotationX || 0
+ this.rotationY = ops.rotationY || 0
+ this.rotationZ = ops.rotationZ || 0
+
+ ops.className && this.el.classList.add(ops.className)
+ this.backface && this.el.classList.add("backface-visible")
+ this.el.classList.add("mx-text")
+ this.el.classList.add("mx-scenery")
+
+ this.inner = document.createElement("div")
+ this.inner.classList.add("inner")
+ this.el.appendChild(this.inner)
+
+ this.load(ops)
+ },
+
+ load: function(ops){
+ var media = ops.media
+ if (media.font) this.setFont(media.font)
- this.children.forEach(function (c, i) {
- if (ops.classname) {
- c.el.classList.add(ops.classname)
- }
- else {
- }
- c.el.style.backgroundRepeat = 'no-repeat'
- })
+ this.setText( media.description )
+ },
+
+ setFont: function(font){
+ if (! font.color || font.color[0] == "#") { font.color = [0,0,0] }
- this.dirty = true
- this.updateChildren = true
- this.update()
- }
+ this.inner.style.fontFamily = "'" + font.family + "',sans-serif"
+ this.el.style.fontSize = (font.size / devicePixelRatio) + "pt"
+ this.el.style.textAlign = font.align
+ this.el.style.color = rgb_string(font.color)
+ },
+
+ setText: function(text){
+ this.inner.innerHTML = marked( text || "" )
+ },
})
diff --git a/public/assets/javascripts/mx/primitives/mx.video.js b/public/assets/javascripts/mx/primitives/mx.video.js
index 12d3dcb..53ccf2e 100644
--- a/public/assets/javascripts/mx/primitives/mx.video.js
+++ b/public/assets/javascripts/mx/primitives/mx.video.js
@@ -21,6 +21,7 @@ MX.Video = MX.Object3D.extend({
this.el.classList.add("video")
this.el.classList.add("mx-scenery")
this.paused = !! this.media.autoplay
+ this.playing = false
this.muted = app.muted || !! this.media.mute
},
@@ -31,8 +32,8 @@ MX.Video = MX.Object3D.extend({
this.player.addEventListener("loadedmetadata", this.ready.bind(this))
this.player.addEventListener("error", this.error.bind(this))
this.player.addEventListener("ended", this.finished.bind(this))
- this.player.width = this.width
- this.player.height = this.height
+ this.player.width = "100%"
+ this.player.height = "100%"
this.player.src = this.media.url
this.player.load()
@@ -45,6 +46,9 @@ MX.Video = MX.Object3D.extend({
if (this.media.mute) {
this.mute()
}
+ else {
+ this.unmute()
+ }
if (this.media.autoplay) {
this.play()
@@ -57,11 +61,13 @@ MX.Video = MX.Object3D.extend({
play: function(){
this.paused = false
+ this.playing = true
this.player.play()
},
pause: function(){
this.paused = true
+ this.playing = false
this.player.pause()
},
@@ -74,14 +80,21 @@ MX.Video = MX.Object3D.extend({
mute: function(){
this.player.muted = true
+ this.player.volume = 0
this.muted = true
},
unmute: function(){
this.player.muted = false
+ this.player.volume = 0.8
this.muted = false
},
+ setVolume: function(n){
+ if (this.muted || ! this.player) return
+ this.player.volume = n
+ },
+
setLoop: function(state){
this.media.loop = state
},
diff --git a/public/assets/javascripts/mx/primitives/mx.vimeo.js b/public/assets/javascripts/mx/primitives/mx.vimeo.js
index 4922519..af138ae 100644
--- a/public/assets/javascripts/mx/primitives/mx.vimeo.js
+++ b/public/assets/javascripts/mx/primitives/mx.vimeo.js
@@ -20,6 +20,7 @@ MX.Vimeo = MX.Object3D.extend({
this.backface && this.el.classList.add("backface-visible")
this.el.classList.add("video")
this.el.classList.add("mx-scenery")
+ this.playing = false
this.paused = !! this.media.autoplay
this.muted = app.muted || !! this.media.mute
this.started = false
@@ -32,8 +33,8 @@ MX.Vimeo = MX.Object3D.extend({
preload.id = uid
preload.setAttribute("src", "//player.vimeo.com/video/" + this.media.token + "?api=1&badge=0&controls=0branding=0&byline=0&portrait=0&title=0&" + loop + "&player_id=" + uid)
preload.style.backgroundImage = "url(" + this.media.thumbnail + ")"
- preload.style.width = this.media.width + "px"
- preload.style.height = this.media.height + "px"
+ preload.style.width = "100%"
+ preload.style.height = "100%"
preload.style.border = "0"
preload.style.pointerEvents = "none"
preload.className = "preload"
@@ -62,6 +63,9 @@ MX.Vimeo = MX.Object3D.extend({
if (this.media.mute) {
this.mute()
}
+ else {
+ this.unmute()
+ }
this.seek( this.media.keyframe || 0 )
@@ -96,7 +100,7 @@ MX.Vimeo = MX.Object3D.extend({
return
}
- if (! this.started || n === 0) {
+ if (! this.started) {
return
}
@@ -127,6 +131,11 @@ MX.Vimeo = MX.Object3D.extend({
this.player.api('setVolume', 0.8)
this.muted = false
},
+
+ setVolume: function(n){
+ if (this.muted || ! this.player) return
+ this.player.api('setVolume', n)
+ },
setLoop: function(state){
this.media.loop = state
@@ -137,19 +146,26 @@ MX.Vimeo = MX.Object3D.extend({
if (this.paused) {
this.pause()
}
+ else {
+ this.playing = true
+ }
},
onPause: function(){
if (! this.paused) {
this.play()
}
+ else {
+ this.playing = false
+ }
},
finished: function(){
-// if (this.media.loop) {
-// this.seek(0)
-// this.play()
-// }
+ console.log("vimeo finished")
+ if (this.media.loop) {
+ this.seek(0)
+ this.play()
+ }
// else if (this.bound) {
if (! this.media.loop && this.bound) {
$(".playButton").removeClass('playing')
diff --git a/public/assets/javascripts/mx/primitives/mx.youtube.js b/public/assets/javascripts/mx/primitives/mx.youtube.js
index 873348f..8cd9f59 100644
--- a/public/assets/javascripts/mx/primitives/mx.youtube.js
+++ b/public/assets/javascripts/mx/primitives/mx.youtube.js
@@ -21,6 +21,7 @@ MX.Youtube = MX.Object3D.extend({
this.el.classList.add("video")
this.el.classList.add("mx-scenery")
this.paused = !! this.media.autoplay
+ this.playing = false
this.muted = app.muted || !! this.media.mute
},
@@ -31,12 +32,25 @@ MX.Youtube = MX.Object3D.extend({
preload.id = uid
preload.style.backgroundImage = "url(" + this.media.thumbnail + ")"
preload.style.backgroundSize = "cover"
- preload.style.width = this.media.width + "px"
- preload.style.height = this.media.height + "px"
+ preload.style.width = "100%"
+ preload.style.height = "100%"
preload.style.pointerEvents = "none"
+ preload.style.position = "absolute"
+ preload.style.top = "0"
+ preload.style.left = "0"
+ preload.style.zIndex = "1"
preload.className = "preload"
this.el.appendChild(preload)
+ var overlay = this.overlay = document.createElement("div")
+ overlay.style.width = "100%"
+ overlay.style.height = "100%"
+ overlay.style.position = "absolute"
+ overlay.style.top = "0"
+ overlay.style.left = "0"
+ overlay.style.zIndex = "2"
+ overlay.className = "overlay"
+ this.el.appendChild(overlay)
this.defer(uid)
},
@@ -96,6 +110,9 @@ MX.Youtube = MX.Object3D.extend({
if (this.media.mute) {
this.mute()
}
+ else {
+ this.unmute()
+ }
this.seek( this.media.keyframe || 0 )
},
@@ -127,11 +144,13 @@ MX.Youtube = MX.Object3D.extend({
play: function(){
this.paused = false
+ this.playing = true
this.player.playVideo()
},
pause: function(){
this.paused = true
+ this.playing = false
this.player.pauseVideo()
},
@@ -157,6 +176,11 @@ MX.Youtube = MX.Object3D.extend({
this.player.setVolume(80)
this.muted = false
},
+
+ setVolume: function(n){
+ if (this.muted || ! this.player || ! this.player.setVolume) return
+ this.player.setVolume( floor(n * 100) )
+ },
setLoop: function(state){
this.media.loop = state