private void UpdatePolyLib(object sender, EventArgs e) { if (_currentTriangulation == null) { _currentTriangulation = _polyLibView.CurrentTriangulation; } var boundsWidth = Int32.Parse(_widthTB.Text); var boundsHeight = Int32.Parse(_heightTB.Text); var variance = float.Parse(_varTB.Text); var cellSize = int.Parse(_sizeTB.Text); if (!boundsWidth.Equals(_polyLibView.Width) || !boundsHeight.Equals(_polyLibView.Height)) { _polyLibView = _polyLibView.ResizeView(boundsWidth, boundsHeight, this); _currentTriangulation = _polyLibView.CurrentTriangulation; } //set props on triangulation _currentTriangulation.Variance = variance; _currentTriangulation.CellSize = cellSize; _currentTriangulation.Frequency = _freqProgress; _currentTriangulation.Seed = _seedProgress; var colors = Triangulation.getRandomColorBruColors(6); var shader = Triangulation.GetRandomGradientShader(colors, _currentTriangulation.BoundsWidth, _currentTriangulation.BoundsHeight); _currentTriangulation.GradientShader = shader; }
void Generate(object sender, EventArgs e) { //convert pixel height/width to point var boundsWidth = (int)(Int32.Parse(widthInput.Text) / UIScreen.MainScreen.Scale); var boundsHeight = (int)(Int32.Parse(heightInput.Text) / UIScreen.MainScreen.Scale); var variance = float.Parse(varInput.Text); var cellSize = int.Parse(cellSizeInput.Text); if (!(boundsWidth == _polyLibViewRef.Frame.Width) || !(boundsHeight == _polyLibViewRef.Frame.Height)) { _polyLibViewRef = _polyLibViewRef.ResizeView(boundsWidth, boundsHeight, new List <UIGestureRecognizer> { _tapGestureRecognizer, _panGestureRecognizer }); _currentTriangulation = _polyLibViewRef.CurrentTriangulation; } //set props on triangulation _currentTriangulation.Variance = variance; _currentTriangulation.CellSize = cellSize; var colors = Triangulation.getRandomColorBruColors(6); var shader = Triangulation.GetRandomGradientShader(colors, _currentTriangulation.BoundsWidth, _currentTriangulation.BoundsHeight); _currentTriangulation.GradientShader = shader; }
protected override void OnDestroy() { base.OnDestroy(); _polyLibView = null; _widthTB = null; _heightTB = null; _varTB = null; _sizeTB = null; _controlsContainer = null; _freqSeek = null; _freqSeek = null; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. _polyLibViewRef = polylibView; //set inputs in pixel width/height widthInput.Text = $"{_polyLibViewRef.Frame.Width * UIScreen.MainScreen.Scale}"; heightInput.Text = $"{_polyLibViewRef.Frame.Height * UIScreen.MainScreen.Scale}"; varInput.Text = ".75"; cellSizeInput.Text = "150"; _tapGestureRecognizer = new UITapGestureRecognizer(HandleTap); _panGestureRecognizer = new UIPanGestureRecognizer(HandlePanTouch); widthInput.ShouldReturn = (textField) => { textField.ResignFirstResponder(); return(true); }; heightInput.ShouldReturn = (textField) => { textField.ResignFirstResponder(); return(true); }; varInput.ShouldReturn = (textField) => { textField.ResignFirstResponder(); return(true); }; cellSizeInput.ShouldReturn = (textField) => { textField.ResignFirstResponder(); return(true); }; generateButton.TouchUpInside += Generate; _polyLibViewRef.AddGestureRecognizer(_tapGestureRecognizer); _polyLibViewRef.AddGestureRecognizer(_panGestureRecognizer); if (_currentTriangulation == null) { _currentTriangulation = _polyLibViewRef.CurrentTriangulation; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it _button = FindViewById <Button>(Resource.Id.button1); _button.Click += UpdatePolyLib; _animSButton = FindViewById <Button>(Resource.Id.animSButton); _animSButton.Click += sweepAnimation; _animGButton = FindViewById <Button>(Resource.Id.animGButton); _animGButton.Click += growAnimation; _polyLibView = FindViewById <PolyLibView>(Resource.Id.imageView1); _polyLibView.SetOnTouchListener(this); _currentTriangulation = _polyLibView.CurrentTriangulation; _widthTB = FindViewById <TextView>(Resource.Id.widthTextBox); _heightTB = FindViewById <TextView>(Resource.Id.heightTextBox); _varTB = FindViewById <TextView>(Resource.Id.varTextBox); _sizeTB = FindViewById <TextView>(Resource.Id.sizeTextBox); _seedSeek = FindViewById <SeekBar>(Resource.Id.seedSeek); _freqSeek = FindViewById <SeekBar>(Resource.Id.frequencySeek); _controlsContainer = FindViewById <LinearLayout>(Resource.Id.controlsContainer); _seedSeek.SetOnSeekBarChangeListener(this); _freqSeek.SetOnSeekBarChangeListener(this); var metrics = Resources.DisplayMetrics; _widthTB.Text = metrics.WidthPixels.ToString(); _heightTB.Text = metrics.HeightPixels.ToString(); _varTB.Text = ".75"; _sizeTB.Text = "150"; }