Add vertical slicing (#30)

* Add vertical slicing
* New slice drawing; allows horizontal and vertical slicing
master
JerwuQu 8 years ago committed by Will
parent 0bfd21ac7c
commit 0400358f7f
  1. 92
      src/js/HuesCanvas.js
  2. 12
      src/js/HuesCore.js
  3. 8
      src/js/HuesInfo.js

@ -59,12 +59,12 @@ class HuesCanvas {
this.xBlur = false; this.xBlur = false;
this.yBlur = false; this.yBlur = false;
this.sliceAvgSegments = 15;
this.sliceCount = 0;
this.sliceSegments = [];
this.sliceDistances = [];
this.sliceDistance = 0; this.sliceDistance = 0;
this.sliceStart = 0; this.sliceStart = 0;
this.slices = {
x : this.makeSliceObj(25),
y : this.makeSliceObj(15)
};
// trippy mode // trippy mode
this.trippyStart = [0, 0]; // x, y this.trippyStart = [0, 0]; // x, y
@ -105,6 +105,15 @@ class HuesCanvas {
this.resize(); this.resize();
} }
makeSliceObj(avgSegments) {
return {
count : 0,
avgSegments : avgSegments,
segments : [],
distances : []
};
}
setInvert(invert) { setInvert(invert) {
this.invert = invert; this.invert = invert;
this.needsRedraw = true; this.needsRedraw = true;
@ -233,19 +242,34 @@ class HuesCanvas {
drawSlice(bitmap, drawWidth, drawHeight, width, height) { drawSlice(bitmap, drawWidth, drawHeight, width, height) {
this.offContext.clearRect(0,0,width,height); this.offContext.clearRect(0,0,width,height);
let bitmapoffset = 0; let bitmapXOffset = 0;
let drawOffset = 0; let drawXOffset = 0;
for(let i = 0; i < this.sliceCount; i++) { for (let i = 0; i < this.slices.x.count; i++) {
let segment = this.sliceSegments[i]; let xSegment = this.slices.x.segments[i];
let segmentBitmapHeight = Math.round(segment * bitmap.height); let sliceXDistance = this.slices.x.distances[i] * this.sliceDistance;
let segmentDrawHeight = Math.round(segment * drawHeight); let segmentBitmapWidth = Math.round(xSegment * bitmap.width);
let segmentDrawWidth = Math.round(xSegment * drawWidth);
let bitmapYOffset = 0;
let drawYOffset = 0;
for (let j = 0; j < this.slices.y.count; j++) {
let ySegment = this.slices.y.segments[j];
let sliceYDistance = this.slices.y.distances[j] * this.sliceDistance;
let segmentBitmapHeight = Math.round(ySegment * bitmap.height);
let segmentDrawHeight = Math.round(ySegment * drawHeight);
this.offContext.drawImage(bitmap, this.offContext.drawImage(bitmap,
0 , bitmapoffset, // subsection x, y bitmapXOffset, bitmapYOffset, // subsection x, y
bitmap.width, segmentBitmapHeight, // sub w/h segmentBitmapWidth, segmentBitmapHeight, // subsection w, h
this.sliceDistances[i] * this.sliceDistance, drawOffset, // drawn section x, y drawXOffset + sliceYDistance, drawYOffset + sliceXDistance, // drawn x, y
drawWidth, segmentDrawHeight); // drawn w/h segmentDrawWidth, segmentDrawHeight); // drawn w, h
bitmapoffset += segmentBitmapHeight;
drawOffset += segmentDrawHeight; bitmapYOffset += segmentBitmapHeight;
drawYOffset += segmentDrawHeight;
}
bitmapXOffset += segmentBitmapWidth;
drawXOffset += segmentDrawWidth;
} }
return this.offCanvas; return this.offCanvas;
@ -573,7 +597,7 @@ class HuesCanvas {
this.trippyOn = saveTrippy; this.trippyOn = saveTrippy;
} }
doSlice(beatLength, beatCount) { doSlice(beatLength, beatCount, sliceX, sliceY) {
let transitionTime = Math.min(0.06, beatLength); let transitionTime = Math.min(0.06, beatLength);
this.sliceStart = this.audio.currentTime; this.sliceStart = this.audio.currentTime;
@ -581,30 +605,44 @@ class HuesCanvas {
this.sliceRampDown = this.sliceStart + (beatLength * beatCount) - transitionTime; this.sliceRampDown = this.sliceStart + (beatLength * beatCount) - transitionTime;
this.sliceTransitionTime = transitionTime; this.sliceTransitionTime = transitionTime;
this.generateSliceSegments(); if (sliceX)
this.generateSliceSegments('x');
else
this.resetSliceSegments('x');
if (sliceY)
this.generateSliceSegments('y');
else
this.resetSliceSegments('y');
this.needsRedraw = true; this.needsRedraw = true;
} }
generateSliceSegments() { generateSliceSegments(direction) {
let even = 1.0 / this.sliceAvgSegments; let even = 1.0 / this.slices[direction].avgSegments;
let spread = even / 2; let spread = even / 2;
let total = 0; let total = 0;
let i; let i;
for(i = 0; ; i++) { for(i = 0; ; i++) {
let deviation = Math.random() * spread*2 - spread; let rando = even + Math.random() * spread * 2 - spread;
let rando = even + deviation; this.slices[direction].segments[i] = rando;
this.sliceSegments[i] = rando; total += rando;
total += this.sliceSegments[i];
this.sliceDistances[i] = Math.random() * this.blurAmount - this.blurAmount/2; this.slices[direction].distances[i] =
Math.random() * this.blurAmount - this.blurAmount / 2;
if(total > 1.0) { if(total > 1.0) {
this.sliceSegments[i] -= total - 1.0; this.slices[direction].segments[i] -= total - 1.0;
break; break;
} }
} }
this.sliceCount = i+1;
this.slices[direction].count = i + 1;
}
resetSliceSegments(direction) {
this.slices[direction].count = 1;
this.slices[direction].segments[0] = 1;
this.slices[direction].distances[0] = 0;
} }
setBlurDecay(decay) { setBlurDecay(decay) {

@ -795,7 +795,15 @@ class HuesCore {
break; break;
case 'S': case 'S':
case 's': case 's':
this.renderer.doSlice(this.getBeatLength(), this.charsToNextBeat()); this.renderer.doSlice(this.getBeatLength(), this.charsToNextBeat(), false, true);
break;
case 'V':
case 'v':
this.renderer.doSlice(this.getBeatLength(), this.charsToNextBeat(), true, false);
break;
case '@':
case '#':
this.renderer.doSlice(this.getBeatLength(), this.charsToNextBeat(), true, true);
break; break;
case 'I': case 'I':
if (this.isFullAuto) { if (this.isFullAuto) {
@ -809,7 +817,7 @@ class HuesCore {
if ([".", "+", "|", "¤"].indexOf(beat) == -1) { if ([".", "+", "|", "¤"].indexOf(beat) == -1) {
this.renderer.clearBlackout(); this.renderer.clearBlackout();
} }
if([".", "+", "¤", ":", "*", "X", "O", "~", "=", "i", "I", "s"].indexOf(beat) == -1) { if([".", "+", "¤", ":", "*", "X", "O", "~", "=", "i", "I", "s", "v", "#"].indexOf(beat) == -1) {
this.randomColour(); this.randomColour();
if (this.isFullAuto) { if (this.isFullAuto) {
this.randomImage(); this.randomImage();

@ -43,8 +43,12 @@ const beatGlossary = [
"= Fade and change image", "= Fade and change image",
"i Invert all colours", "i Invert all colours",
"I Invert & change image", "I Invert & change image",
"s Slice", "s Horizontal slice",
"S Slice and change image" "S Horizontal slice and change image",
"v Vertical slice",
"V Vertical slice and change image",
"# Double slice",
"@ Double slice and change image"
]; ];
const shortcuts = [ const shortcuts = [

Loading…
Cancel
Save