Pixel DoRenderPlanet(IntCoordinate c, int width, int height, RenderInfo info, Vector3 sunvec) { const double starClose = 2; info.InitializeRow(c.Y); var sv = new Vector3(sunvec.X, sunvec.Y * info.dy, sunvec.Z * info.sqomdysq); double azimuth = Math.Asin(((double)c.Y / (height - 1)) * 2 - 1); int lcos = (int)((height / 2) * Math.Abs(Math.Cos(azimuth))); if (c.X >= width / 2 - lcos && c.X <= width / 2 + lcos) { double r = info.CalculateR(c.X); var rgb = (r >= 128) ? RenderLand(r) : RenderWater(r); double icet = Math.Pow(Math.Abs(Math.Sin(azimuth)), 1.0 / _icelevel) - 0.5; RenderPolarIceCaps(r, icet, rgb); return(ApplyDarkening(width, height, c.X, sv, info.dysq, rgb)); } else if (c.X < width / 2 - (lcos + starClose) || c.X > width / 2 + (lcos + starClose)) { return(_starFactory.Generate()); } else { return(new Pixel(3)); } }
public Preview(Drawable drawable, SliceData sliceData) { MaxSize = drawable.Dimensions; ExposeEvent += delegate {sliceData.Draw(Renderer);}; Realized += delegate { var gc = new Gdk.GC(GdkWindow); Renderer = new PreviewRenderer(this, gc, drawable.Dimensions); Draw(drawable); }; SizeAllocated += delegate {Draw(drawable);}; Events = EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionHintMask | EventMask.PointerMotionMask | EventMask.LeaveNotifyMask; ButtonPressEvent += (o, args) => { var c = new IntCoordinate((int) args.Event.X, (int) args.Event.Y); Func.GetActualFunc(c).OnButtonPress(o, args); }; MotionNotifyEvent += (o, args) => { GdkWindow.Cursor = Func.GetCursor(GetXY(args)); }; Func = new SelectFunc(sliceData, this); }
public static MouseFunc GetActualFunc(IntCoordinate c, MouseFunc func) { var slice = func.SliceData.FindSlice(c); return(func.SliceIsSelectable(slice) ? new MoveSliceFunc(func.SliceData, func.Preview, slice) : func); }
public Preview(Drawable drawable, SliceData sliceData) { MaxSize = drawable.Dimensions; ExposeEvent += delegate { sliceData.Draw(Renderer); }; Realized += delegate { var gc = new Gdk.GC(GdkWindow); Renderer = new PreviewRenderer(this, gc, drawable.Dimensions); Draw(drawable); }; SizeAllocated += delegate { Draw(drawable); }; Events = EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionHintMask | EventMask.PointerMotionMask | EventMask.LeaveNotifyMask; ButtonPressEvent += (o, args) => { var c = new IntCoordinate((int)args.Event.X, (int)args.Event.Y); Func.GetActualFunc(c).OnButtonPress(o, args); }; MotionNotifyEvent += (o, args) => { GdkWindow.Cursor = Func.GetCursor(GetXY(args)); }; Func = new SelectFunc(sliceData, this); }
protected override void OnPress(IntCoordinate c) { var slice = SliceData.MayRemove(c); if (slice != null) { SliceData.Remove(slice); Redraw(); } }
public Pixel GetColor(IntCoordinate c) { int row = c.Y * _matrixRows / _height; int col = c.X * _matrixColumns / _width; var list = _matrix[row, col]; return((list == null) ? _backgroundColor : GetNearestColor(list, c)); }
/// <summary> /// Left hand normal /// </summary> /// <param name="c1"></param> /// <param name="c2"></param> /// <returns></returns> public static Coordinate<double> Normal(IntCoordinate c1, IntCoordinate c2) { var normal = new Coordinate<double>(c1.Y - c2.Y, -(c1.X - c2.X)); var mag = Math.Sqrt(normal.X*normal.X + normal.Y*normal.Y); normal.X = normal.X/mag; normal.Y = normal.Y/mag; return normal; }
public Raindrop(IntCoordinate coordinate, int newSize, double newCoeff) { _newSize = newSize; _radius = newSize / 2; // Half of current raindrop _newCoeff = newCoeff; _s = _radius / Math.Log(newCoeff * _radius + 1); X = coordinate.X; Y = coordinate.Y; }
override protected void OnPress(IntCoordinate c) { _x = c.X; _y = c.Y; _rectangle = SliceData.FindRectangle(c); _slice = _rectangle.CreateHorizontalSlice(_y); _horizontal = true; Preview.Renderer.Function = Gdk.Function.Equiv; _slice.Draw(Preview.Renderer); }
public bool Fits(Painter painter, BoolMatrix A, IntCoordinate p) { var color = painter.GetPixel(p); return(TrueForAll(offset => { var c = new IntCoordinate(p.X + offset.X, p.Y + offset.Y); return A.IsInside(c) && !A.Get(c) && painter.IsSameColor(c, color); })); }
public void Fits(BoolMatrix A, IntCoordinate c) { foreach (var shape in this) { if (shape.Fits(A, c)) { break; } } }
override protected void OnPress(IntCoordinate c) { var slice = SliceData.MayRemove(c); if (slice != null) { SliceData.Remove(slice); Redraw(); } }
public int Calc(int b, IntCoordinate c) { for (int k = 0; k < _points * 4; k++) { _distances[k] = c.Distance(_vp[b, k]); } int val = (int)(255.0 * Math.Sqrt((double)Select(_closest) / _area)); return(255 - val); // invert }
Pixel DoRenderClouds(IntCoordinate c, RenderInfo info) { const double rgbQuant = 255; info.InitializeRow(c.Y); double r = info.CalculateR(c.X); byte w = (byte)((r > 127.0) ? (rgbQuant * ((r - 127.0) / 128.0)) : 0); return(new Pixel(w, w, (byte)rgbQuant)); }
public void Rectangle(IntCoordinate c, int w, int h) { w *= Size; h *= Size; LineStart(c); HLine(w); VLine(h); HLine(-w); VLine(-h); }
void Draw(IntCoordinate c, int hline1, int vline1, int hline2, int vline2, int hline3, int vline3) { LineStart(c); HLine(hline1); VLine(vline1); HLine(hline2); VLine(vline2); HLine(hline3); VLine(vline3); }
public bool Fits(BoolMatrix A, IntCoordinate c) { foreach (var shape in _set[_random.Next(0, _set.Count)]) { if (shape.Fits(Painter, A, c)) { shape.Fill(A, c); return true; } } return false; }
public bool Fits(BoolMatrix A, IntCoordinate c) { foreach (var shape in _set[_random.Next(0, _set.Count)]) { if (shape.Fits(Painter, A, c)) { shape.Fill(A, c); return(true); } } return(false); }
protected override void OnPress(IntCoordinate c) { var rows = new Variable<int>(3); var columns = new Variable<int>(3); var dialog = new TableDialog(rows, columns); dialog.ShowAll(); if (dialog.Run() == ResponseType.Ok) { SliceData.CreateTable(c, rows.Value, columns.Value); Redraw(); } dialog.Destroy(); }
override protected void OnPress(IntCoordinate c) { var rows = new Variable <int>(3); var columns = new Variable <int>(3); var dialog = new TableDialog(rows, columns); dialog.ShowAll(); if (dialog.Run() == ResponseType.Ok) { SliceData.CreateTable(c, rows.Value, columns.Value); Redraw(); } dialog.Destroy(); }
Pixel DoNCP(IntCoordinate c) { int b = 0; Func<int> func = () => _calculator.Calc(b++, c); if (_color) { _pixel.Fill(func); } else { _pixel.FillSame(func); } return _pixel; }
Pixel DoNCP(IntCoordinate c) { int b = 0; Func <int> func = () => _calculator.Calc(b++, c); if (_color) { _pixel.Fill(func); } else { _pixel.FillSame(func); } return(_pixel); }
override protected void OnMove(IntCoordinate c) { var coordinate = (_horizontal) ? new IntCoordinate(c.X, _y) : new IntCoordinate(_x, c.Y); var rectangle = SliceData.FindRectangle(coordinate); bool rectangleChanged = rectangle != _endRectangle; _endRectangle = rectangle; bool horizontal = Math.Abs(c.X - _x) > Math.Abs(c.Y - _y); bool orientationChanged = horizontal != _horizontal; _horizontal = horizontal; if (orientationChanged || rectangleChanged) { _slice.Draw(Preview.Renderer); if (_horizontal) { if (rectangle.X1 <= _rectangle.X1) { _slice = new HorizontalSlice(rectangle.Left, _rectangle.Right, _y); } else { _slice = new HorizontalSlice(_rectangle.Left, rectangle.Right, _y); } } else { if (rectangle.Y1 <= _rectangle.Y1) { _slice = new VerticalSlice(rectangle.Top, _rectangle.Bottom, _x); } else { _slice = new VerticalSlice(_rectangle.Top, rectangle.Bottom, _x); } } _slice.Draw(Preview.Renderer); } }
Pixel GetNearestColor(List <ColorCoordinate> list, IntCoordinate c) { int distance = int.MaxValue; ColorCoordinate closest = null; list.ForEach(coordinate => { int d = coordinate.Distance(c); if (d < distance) { distance = d; closest = coordinate; } }); return(distance < _cellSize2 / 4 ? closest.Color : _backgroundColor); }
protected override void OnMove(IntCoordinate c) { var coordinate = (_horizontal) ? new IntCoordinate(c.X, _y) : new IntCoordinate(_x, c.Y); var rectangle = SliceData.FindRectangle(coordinate); bool rectangleChanged = rectangle != _endRectangle; _endRectangle = rectangle; bool horizontal = Math.Abs(c.X - _x) > Math.Abs(c.Y - _y); bool orientationChanged = horizontal != _horizontal; _horizontal = horizontal; if (orientationChanged || rectangleChanged) { _slice.Draw(Preview.Renderer); if (_horizontal) { if (rectangle.X1 <= _rectangle.X1) { _slice = new HorizontalSlice(rectangle.Left, _rectangle.Right, _y); } else { _slice = new HorizontalSlice(_rectangle.Left, rectangle.Right, _y); } } else { if (rectangle.Y1 <= _rectangle.Y1) { _slice = new VerticalSlice(rectangle.Top, _rectangle.Bottom, _x); } else { _slice = new VerticalSlice(_rectangle.Top, rectangle.Bottom, _x); } } _slice.Draw(Preview.Renderer); } }
public Rectangle MinDistanceRegion(Rectangle sourceRect, Drawable drawable, SelectionMask selectionMask) { Debug.Assert(sourceRect.Width == sourceRect.Height); var windowSize = sourceRect.Width; var windowDelta = windowSize/2; Rectangle minRegionRect = null; var minDistance = 0.0; var sourceRgn = new PixelRgn(drawable, sourceRect.AdjustedToImageEdges(drawable.Bounds), false, false); var sourceArray = sourceRgn.ToArrayWithoutSelection(selectionMask); var currentCoordinate = new IntCoordinate(0, 0); for (int i = windowDelta; i < drawable.Width - windowDelta; i++) { for (int j = windowDelta; j < drawable.Height - windowDelta; j++) { if (j == sourceRect.Y1 + windowDelta && i == sourceRect.X1 + windowDelta) { continue; } currentCoordinate.X = i; currentCoordinate.Y = j; var currentRgnRect = currentCoordinate.PointCenteredRectangle(windowSize); var dist = RegionDistance(sourceArray, currentRgnRect, drawable, selectionMask); if (dist == null) { continue; } if (dist == 0) { return currentRgnRect; } if ((minDistance > dist || minRegionRect == null)) { minDistance = (double) dist; minRegionRect = currentRgnRect; } } } return minRegionRect; }
public Calculator(int points, int closest, int bpp, Rectangle rectangle, int seed) { _points = points; _closest = closest; int width = rectangle.Width; int height = rectangle.Height; _area = rectangle.Area; int xmid = width / 2; int ymid = height / 2; _distances = new int[4 * _points]; _data = new int[4 * _points]; _under = new int[4 * _points]; _over = new int[4 * _points]; _vp = new IntCoordinate[bpp, 4 * _points]; var generator = new RandomCoordinateGenerator(seed, width - 1, height - 1, _points); for (int b = 0; b < bpp; b++) { int i = 0; foreach (var c in generator) { int px = c.X; int py = c.Y; int offx = (px < xmid) ? width : -width; int offy = (py < ymid) ? height : -height; _vp[b, i] = new IntCoordinate(px, py); _vp[b, i + _points] = new IntCoordinate(px + offx, py); _vp[b, i + 2 * _points] = new IntCoordinate(px, py + offy); _vp[b, i + 3 * _points] = new IntCoordinate(px + offx, py + offy); i++; } } }
public void CreateTable(IntCoordinate c, int rows, int columns) { var rectangle = new Rectangle(_rectangles.Find(c)); int width = rectangle.Width; int height = rectangle.Height; int x1 = rectangle.X1; int y1 = rectangle.Y1; for (int row = 1; row < rows; row++) { int ypos = y1 + row * height / rows; AddSlice(rectangle.CreateHorizontalSlice(ypos)); } for (int col = 1; col < columns; col++) { int xpos = x1 + col * width / columns; AddSlice(rectangle.CreateVerticalSlice(xpos)); } }
public Slice Find(IntCoordinate c) { return _set.Find(slice => slice.PointOn(c)); }
override protected void OnMove(IntCoordinate c) { _slice.Draw(Preview.Renderer); _slice.SetPosition(c); _slice.Draw(Preview.Renderer); }
override public bool PointOn(IntCoordinate c) => c.X >= X1 && c.X <= X2 && Math.Abs(c.Y - Y) < 5;
public abstract bool PointOn(IntCoordinate c);
public abstract void SetPosition(IntCoordinate c);
public virtual Cursor GetCursor(IntCoordinate c) { return _defaultCursor; }
override public MouseFunc GetActualFunc(IntCoordinate c) => MoveSliceFunc.GetActualFunc(c, this);
Pixel DoRenderPlanet(IntCoordinate c, int width, int height, RenderInfo info, Vector3 sunvec) { const double starClose = 2; info.InitializeRow(c.Y); var sv = new Vector3(sunvec.X, sunvec.Y * info.dy, sunvec.Z * info.sqomdysq); double azimuth = Math.Asin(((double) c.Y / (height - 1)) * 2 - 1); int lcos = (int) ((height / 2) * Math.Abs(Math.Cos(azimuth))); if (c.X >= width / 2 - lcos && c.X <= width / 2 + lcos) { double r = info.CalculateR(c.X); var rgb = (r >= 128) ? RenderLand(r) : RenderWater(r); double icet = Math.Pow(Math.Abs(Math.Sin(azimuth)), 1.0 / _icelevel) - 0.5; RenderPolarIceCaps(r, icet, rgb); return ApplyDarkening(width, height, c.X, sv, info.dysq, rgb); } else if (c.X < width / 2 - (lcos + starClose) || c.X > width / 2 + (lcos + starClose)) { return _starFactory.Generate(); } else { return new Pixel(3); } }
override protected void OnPress(IntCoordinate c) { SliceData.SelectRectangle(c); }
public Slice MayRemove(SliceSet orthogonal, IntCoordinate c) { var slice = Find(c); return (slice == null || orthogonal.IsEndPoint(slice)) ? null : slice; }
public static bool IsInside(this Rectangle rect, IntCoordinate coordinate) { return rect.IsInside(coordinate.X, coordinate.Y); }
void ShapeFor(IntCoordinate c) { Draw(c, Size, 2 * Size, -2 * Size, -Size, Size + 1, -Size - 1); }
public void Set() { const int width = 43; const int height = 29; var b = new BoolMatrix(width, height); var c = new IntCoordinate(11, 13); b.Set(c, true); Assert.IsTrue(b.Get(c)); }
virtual public MouseFunc GetActualFunc(IntCoordinate c) => this;
override public Cursor GetCursor(IntCoordinate c) => (SliceData.MayRemove(c) == null) ? base.GetCursor(c) : _cursor;
override public Cursor GetCursor(IntCoordinate c) { var slice = SliceData.FindSlice(c); return((SliceIsSelectable(slice)) ? slice.Cursor : base.GetCursor(c)); }
void ShapeThree(IntCoordinate c) { Draw(c, Size, Size + 1, Size + 1, Size, -2 * Size, -2 * Size); }
public virtual MouseFunc GetActualFunc(IntCoordinate c) { return this; }
void ShapeOne(IntCoordinate c) { Draw(c, 2 * Size, Size, -Size - 1, Size + 1, -Size, -2 * Size); }
public Rectangle Find(IntCoordinate c) { return(_set.Find(rectangle => rectangle.IsInside(c))); }
void ShapeTwo(IntCoordinate c) { Draw(c, 2 * Size, 2 * Size, -Size, -Size - 1, -Size - 1, -Size); }
public void Select(IntCoordinate c) { Selected = Find(c); }
override public void SetPosition(IntCoordinate c) { Y = c.Y; }
Pixel DoRenderClouds(IntCoordinate c, RenderInfo info) { const double rgbQuant = 255; info.InitializeRow(c.Y); double r = info.CalculateR(c.X); byte w = (byte)((r > 127.0) ? (rgbQuant * ((r - 127.0) / 128.0)) : 0); return new Pixel(w, w, (byte) rgbQuant); }
public ColorCoordinate(IntCoordinate c, Pixel color) : base(c) { Color = color; }
protected virtual void OnPress(IntCoordinate c) { }
public Rectangle MinDistanceRegion(Rectangle sourceRect, ImgGradient gradient, Pixel[,] layerPixels, SelectionMask selectionMask) { Debug.Assert(sourceRect.Width == sourceRect.Height); var windowSize = sourceRect.Width; var windowDelta = windowSize/2; var layerWidth = layerPixels.GetLength(0); var layerHeight = layerPixels.GetLength(1); Rectangle minRegionRect = null; var minDistance = 0.0; var adjustedSourceRect = sourceRect.AdjustedToImageEdges(new Rectangle(new IntCoordinate(0, 0), layerWidth, layerHeight)); var currentCoordinate = new IntCoordinate(0, 0); var orthoGradient = new Coordinate<double>(-gradient.YMagnitude*windowDelta, gradient.XMagnitude*windowDelta); for (int i = windowDelta; i < layerWidth - windowDelta; i++) { for (int j = windowDelta; j < layerHeight - windowDelta; j++) { if (j == sourceRect.Y1 + windowDelta && i == sourceRect.X1 + windowDelta) { continue; } currentCoordinate.X = i; currentCoordinate.Y = j; var currentRgnRect = currentCoordinate.PointCenteredRectangle(windowSize); var dist = RegionDistance(adjustedSourceRect, currentRgnRect, layerPixels, selectionMask); if (dist == null) { continue; } if (dist == 0) { return currentRgnRect; } if ((minDistance > dist || minRegionRect == null)) { minDistance = (double) dist; minRegionRect = currentRgnRect; } } } return minRegionRect; }
protected virtual void OnMove(IntCoordinate c) { }