Commit 233b7a57 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

better demo

parent 77367906
const React = require("react-native"); const React = require("react-native");
const { View, Text, StyleSheet } = React;
const GL = require("gl-react-native"); const GL = require("gl-react-native");
const TransitionGenerator = require("./TransitionGenerator"); const TransitionGenerator = require("./TransitionGenerator");
const Transition = require("./Transition"); const Transition = require("./Transition");
...@@ -11,9 +12,10 @@ class Slideshow extends React.Component { ...@@ -11,9 +12,10 @@ class Slideshow extends React.Component {
this._currentTransition = -1; this._currentTransition = -1;
} }
render () { render () {
const { duration, width, height, time, images } = this.props; const { transitionDuration, pauseDuration, width, height, time, images } = this.props;
const duration = transitionDuration + pauseDuration;
const slide = time / duration; const slide = time / duration;
let transitionProgress = slide % 1; let transitionProgress = Math.min(1, (duration/transitionDuration) * (slide % 1));
let transitionFrom = images[Math.floor(slide) % images.length]; let transitionFrom = images[Math.floor(slide) % images.length];
let transitionTo = images[Math.floor(slide+1) % images.length]; let transitionTo = images[Math.floor(slide+1) % images.length];
...@@ -21,49 +23,54 @@ class Slideshow extends React.Component { ...@@ -21,49 +23,54 @@ class Slideshow extends React.Component {
if (currentTransition !== this._currentTransition) { if (currentTransition !== this._currentTransition) {
this._currentTransition = currentTransition; this._currentTransition = currentTransition;
const { name, uniforms } = TransitionGenerator.random(); const { name, uniforms } = TransitionGenerator.random();
console.log(name);
this._name = name;
this._shader = shaders[name]; this._shader = shaders[name];
this._uniforms = uniforms; this._uniforms = uniforms;
} }
const transitionName = this._name;
const transitionShader = this._shader; const transitionShader = this._shader;
const transitionUniforms = this._uniforms; const transitionUniforms = this._uniforms;
/* return <View style={styles.root}>
switch (Math.floor(slide/4) % 3) { <Transition
case 0: width={width}
transitionShader = shaders.transitionRandomSquares; height={height}
const w = 3 * (1 + Math.floor(slide % 8)); progress={transitionProgress}
transitionUniforms = { from={transitionFrom}
size: [w, w * 2 / 3], to={transitionTo}
smoothness: 0.5 shader={transitionShader}
}; uniforms={transitionUniforms}
break; />
case 1: <View style={styles.legend}>
transitionShader = shaders.transitionDirectionalWipe; <Text style={styles.textName}>{transitionName}</Text>
transitionUniforms = { <Text style={styles.textInfo}>(GLSL.io)</Text>
direction: [Math.cos(time/2), Math.sin(time/2)], </View>
smoothness: 0.5 </View>;
};
break;
case 2:
transitionShader = shaders.transitionWind;
transitionUniforms = {
size: 0.2
};
break;
}
*/
return <Transition
width={width}
height={height}
progress={transitionProgress}
from={transitionFrom}
to={transitionTo}
shader={transitionShader}
uniforms={transitionUniforms}
/>;
} }
} }
const styles = StyleSheet.create({
root: {
position: "relative"
},
legend: {
position: "absolute",
bottom: 5,
right: 4,
backgroundColor: "transparent",
flexDirection: "row"
},
textName: {
color: "#fff",
fontWeight: "bold",
},
textInfo: {
color: "#fff",
marginLeft: 8,
opacity: 0.5
}
});
module.exports = Slideshow; module.exports = Slideshow;
...@@ -12,8 +12,6 @@ const transitions = [ ...@@ -12,8 +12,6 @@ const transitions = [
return { strength: 0.5 * Math.random() }; return { strength: 0.5 * Math.random() };
} ], } ],
"glitch displace", "glitch displace",
"crosshatch",
"PageCurl",
[ "Mosaic", function () { [ "Mosaic", function () {
const dx = Math.round(Math.random() * 6 - 3), dy = Math.round(Math.random() * 6 - 3); const dx = Math.round(Math.random() * 6 - 3), dy = Math.round(Math.random() * 6 - 3);
if (dx===0 && dy===0) dy = -1; if (dx===0 && dy===0) dy = -1;
...@@ -38,23 +36,12 @@ const transitions = [ ...@@ -38,23 +36,12 @@ const transitions = [
} ], } ],
"Star Wipe", "Star Wipe",
"pinwheel", "pinwheel",
[ "Slide", function () {
const choices = [
{ translateX: 0, translateY: -1 },
{ translateX: 0, translateY: 1 },
{ translateX: -1, translateY: 0 },
{ translateX: 1, translateY: 0 }
];
return choices[Math.floor(choices.length * Math.random())];
} ],
"SimpleFlip", "SimpleFlip",
"TilesScanline", "TilesScanline",
"Dreamy", "Dreamy",
"Swirl", "Swirl",
"HSVfade", "HSVfade",
[ "burn", function () { "burn",
return { color: [0,0,0].map(Math.random) };
} ],
"Radial", "Radial",
[ "ripple", function () { [ "ripple", function () {
return { return {
...@@ -74,7 +61,7 @@ const transitions = [ ...@@ -74,7 +61,7 @@ const transitions = [
return { flashIntensity: 4 * Math.random() }; return { flashIntensity: 4 * Math.random() };
} ], } ],
[ "randomsquares", function () { [ "randomsquares", function () {
const size = Math.round(4 + 30 * Math.random()); const size = Math.round(4 + 20 * Math.random());
return { return {
size: [ size, size ], size: [ size, size ],
smoothness: Math.random() smoothness: Math.random()
...@@ -96,10 +83,7 @@ const transitions = [ ...@@ -96,10 +83,7 @@ const transitions = [
} ], } ],
"circleopen", "circleopen",
[ "wind", function () { [ "wind", function () {
return { size: 0.5 * Math.random() }; return { size: 0.1+0.2 * Math.random() };
} ],
[ "fadecolor", function () {
return { color: [0,0,0].map(Math.random) };
} ] } ]
].map(function (obj) { ].map(function (obj) {
let name, genUniforms; let name, genUniforms;
......
...@@ -81,7 +81,8 @@ class AdvancedEffects extends React.Component { ...@@ -81,7 +81,8 @@ class AdvancedEffects extends React.Component {
width={viewportW} width={viewportW}
height={transitionH} height={transitionH}
images={images.slice(2)} images={images.slice(2)}
duration={3} pauseDuration={0.5}
transitionDuration={1.5}
/> />
</View> </View>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment