"use strict";
cc._RF.push(module, 'cfd50rPGoZP/ZMnd/4Dv2dr', 'cocos2');
// Script/cocos2.js

'use strict';

var ShaderUtils = require("ShaderUtils");

cc.Class({
    extends: cc.Component,

    properties: {
        spGray: cc.Sprite,
        fragName: {
            type: cc.String,
            default: '123'
        }
    },

    onLoad: function onLoad() {
        this.scaleX = 1;
        this.preScaleX = this.scaleX;
        this.resolution = { x: 0.0, y: 0.0 };
        this.resolution.x = this.node.getContentSize().width;
        this.resolution.y = this.node.getContentSize().height;

        // this.spGray.setBlendFunc(  771,0 )
        this._program = ShaderUtils.setShader(this.spGray, 'gray', this.fragName);
        if (!cc.sys.isNative) {
            this._program.setUniformLocationWith1f(this._program.getUniformLocationForName("v_maxY"), 0.3);
        } else {
            this.glProgram_state = cc.GLProgramState.getOrCreateWithGLProgram(this._program);
            this.glProgram_state.setUniformFloat("v_maxY", 0.05);
            this.glProgram_state.setUniformFloat("v_maxX", 0.9);
            this.glProgram_state.setUniformFloat("resolution", this.resolution);
        }
    },

    start: function start() {
        this.startTime = new Date();
        this.scaleX_max = 0.9;
        this.scaleX_min = 1.1;
        this.diffScaleX = 0.004;
        this.scaleX = 1.0;
        this.preScaleX = this.scaleX - this.diffScaleX;
        this.ellipse_a = 0.5;
        this.ellipse_b = 0.4;
        this.offset_a_b = 0.05;
    },
    getScaleX: function getScaleX() {
        if (this.scaleX >= this.scaleX_min) {
            this.preScaleX = this.scaleX;
            this.scaleX -= this.diffScaleX;
        } else if (this.scaleX <= this.scaleX_max) {
            this.preScaleX = this.scaleX;
            this.scaleX += this.diffScaleX;
        } else {
            if (this.scaleX < this.preScaleX) {
                //减少阶段
                this.preScaleX = this.scaleX;
                this.scaleX -= this.diffScaleX;
            } else if (this.scaleX > this.preScaleX) {
                this.preScaleX = this.scaleX;
                this.scaleX += this.diffScaleX;
            } else {
                cc.log('error放大倍数不对！！！');
            }
        }
        // this.scaleX = this.scaleX.toFixed( 3 )
    },


    update: function update(dt) {
        this.getScaleX();
        var deltaTime = (new Date() - this.startTime) / 1000;
        var sinValue = Math.sin(deltaTime * 100 * 3.14 / 180) * this.offset_a_b;

        console.log('this.scaleX', sinValue);
        if (!cc.sys.isNative) {
            var ellipse_a = this._program.getUniformLocationForName("a");
            var ellipse_b = this._program.getUniformLocationForName("b");
            this._program.setUniformLocationWith1f(ellipse_a, sinValue + this.ellipse_a);
            this._program.setUniformLocationWith1f(ellipse_b, sinValue + this.ellipse_b);
        } else {
            this.glProgram_state.setUniformFloat("u_scaleX", this.scaleX);
        }
    }
});

cc._RF.pop();