Experiment() {

  Context() {

    AssignmentGroup() {
      ExperimentName = "Moving Gabor Pattern";
	SubjectCode = "pxlab";
	new BGColor = colorAtLum(white(), 30.0);
	ScreenBackgroundColor = BGColor;
	SkipBoundingBlockDisplays = 0;
	RandomizeBlocks = 1;
    }

    Session() {
      Instruction() {
        Text = ["Moving Sinusoidal Gratings",
		" ",
		"We show you patterns of moving sinusoidal gratings. No response is required.",
		"Note that image computation may take same time!",
		" ",
		"Press any key now to start!"];
      }
      ClearScreen() {
        Timer = de.pxlab.pxl.TimerCodes.NO_TIMER;
      }
    }

    SessionEnd() {
      SessionEndMessage();
    } 

    Block() {
	BlockStartMessage() {
          Timer = de.pxlab.pxl.TimerCodes.NO_TIMER;
	  Text = "Computing animation ...";
        }        
    }

    Trial( TrialCounter,
	GaborPatternAnimation.VerticalFrequency, 
	GaborPatternAnimation.VerticalOrientation,
	GaborPatternAnimation.HighColor) { 
      ClearScreen() {
        Timer = de.pxlab.pxl.TimerCodes.CLOCK_TIMER;
	Duration = 500;
      }
      RandomGenerator() {
	ResponseSet = [0, 45, 90];
        ProbabilityDistribution = [0.3333, 0.3333]; 
      }
      GaborPatternAnimation() {
        Timer = de.pxlab.pxl.TimerCodes.CLOCK_TIMER;
	Duration = 5000;
    	FramesPerCycle = 86 / Trial.GaborPatternAnimation.VerticalFrequency;
	FrameDuration = 26;
	AmplitudeModulation = 0;
	Width = 256;
	Height = 256;
	MeanColor = BGColor;
        VerticalFrequency = 8.0;
        VerticalPhase = 0.0;
	VerticalAmplitude = 1.0;
	VerticalOrientation = Trial.RandomGenerator.ResponseCode;
	HorizontalGaussianStandardDeviation = 48;
	VerticalGaussianStandardDeviation = 48;
      }
      ClearScreen:Post() {
        Timer = de.pxlab.pxl.TimerCodes.NO_TIMER;
      }
    }
  }

  Procedure() {
    Session() {
      Block() {
        Trial(?, 4, ?, [34.0, 0.309, 0.329]);
      }
      Block() {
        Trial(?, 8, ?, [34.0, 0.309, 0.329]);
      }
      Block() {
        Trial(?, 16, ?, [34.0, 0.309, 0.329]);
      }
      Block() {
        Trial(?, 4, ?, [30.0, 0.34, 0.329]);
      }
      Block() {
        Trial(?, 8, ?, [30.0, 0.34, 0.329]);
      }
      Block() {
        Trial(?, 16, ?, [30.0, 0.34, 0.329]);
      }
      Block() {
        Trial(?, 4, ?, [30.0, 0.325, 0.37]);
      }
      Block() {
        Trial(?, 8, ?, [30.0, 0.325, 0.37]);
      }
      Block() {
        Trial(?, 16, ?, [30.0, 0.325, 0.37]);
      }
    }
  }
}
