Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 1.0
- import Qt.labs.shaders 1.0 // http://labs.qt.nokia.com/2011/05/03/qml-shadereffectitem-on-qgraphicsview/
- Item {
- id: root
- width: 300
- height: 300
- TextInput {
- id: url
- anchors {
- left: parent.left
- right: parent.right
- top: parent.top
- }
- height: 20
- font.pixelSize: 15
- text: "http://food.foto.ne.jp/free/resize.php?image=images/images_big/fd401360.jpg"
- Keys.onReturnPressed: image.source = text
- }
- Image {
- id: image
- anchors {
- top: url.bottom
- left: parent.left
- right: parent.right
- bottom: parent.bottom
- }
- source: "http://food.foto.ne.jp/free/resize.php?image=images/images_big/fd401360.jpg"
- smooth: true
- fillMode: Image.PreserveAspectFit
- }
- ShaderEffectItem {
- id: effect
- anchors.fill: image
- property variant source: ShaderEffectSource {
- sourceItem: image
- live: true
- hideSource: true
- }
- MouseArea {
- anchors.fill: parent
- onPressed: {
- effect.centerX = mouse.x / effect.width
- effect.centerY = 1.0 - mouse.y / effect.height
- }
- }
- property real centerX: -1
- property real centerY: -1
- property real radius: width * 0.0005
- property real amplitude: 1.0
- SequentialAnimation on amplitude {
- loops: Animation.Infinite
- NumberAnimation {
- easing.type: Easing.InOutSine
- from: 0.1
- to: -0.1
- }
- NumberAnimation {
- easing.type: Easing.InOutSine
- from: -0.1
- to: 0.1
- }
- }
- fragmentShader: "
- varying highp vec2 qt_TexCoord0;
- uniform lowp sampler2D source;
- uniform highp float centerX;
- uniform highp float centerY;
- uniform highp float radius;
- uniform highp float amplitude;
- void main(void)
- {
- highp vec2 springTexCoord = qt_TexCoord0;
- highp float x = centerX;
- highp float y = centerY;
- highp float r = radius;
- highp float d = ((qt_TexCoord0.s - x) * (qt_TexCoord0.s - x) + (qt_TexCoord0.t - y) * (qt_TexCoord0.t - y)) / (r * r);
- if ( d < 1.0 ) {
- springTexCoord.t += amplitude * r * (1.0 - d);
- }
- gl_FragColor = texture2D(source, springTexCoord.st);
- }
- "
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment