@inherits RazorFunction @functions { override public string FunctionDescription { get { return "Displays a customizable color cube."; } } // C1 Function parameters defined below... [FunctionParameter(Label = "Total width", Help = "How wide the cube should by, in pixels", DefaultValue = 500)] public int TotalWidth { get; set; } [FunctionParameter(Label = "Number of columns", Help = "Specify how many columns the cube should have across the X axis", DefaultValue = 10)] public int NumOfColumns { get; set; } [FunctionParameter(Label = "Number of rows", Help = "Specify how many rows the cube should have along the Y axis", DefaultValue = 10)] public int NumOfRows { get; set; } [FunctionParameter(Label = "Minimum Red 0 - 255", Help = "A higher number will make this color more dominant", DefaultValue = 10)] public int MinimumRed { get; set; } [FunctionParameter(Label = "Minimum Green 0 - 255", Help = "A higher number will make this color more dominant", DefaultValue = 10)] public int MinimumGreen { get; set; } [FunctionParameter(Label = "Minimum Blue 0 - 255", Help = "A higher number will make this color more dominant", DefaultValue = 10)] public int MinimumBlue { get; set; } [FunctionParameter(Label = "Border width", Help = "Increase to make outset border more dominant", DefaultValue = 3)] public int BorderWidth { get; set; } [FunctionParameter(Label = "Spacing between boxes", Help = "If spacing is desired, specify how many pixels", DefaultValue = 4)] public int SiblingPadding { get; set; } }
@for (int row = 0; row < NumOfRows; row++) { for (int col = 0; col < NumOfColumns; col++) {
}
}
@functions { // plumbing that turns the input numbers into things like css width strings etc... private string RandomColor() { return String.Format("rgb({0},{1},{2})", Math.Max(MinimumRed, random.Next(0, 255)), Math.Max(MinimumGreen, random.Next(0, 255)), Math.Max(MinimumBlue, random.Next(0, 255))); } private string SiblingMarginString { get { return (SiblingPadding == 0 ? "0" : SiblingPadding + "px"); } } private int OuterBoxDimension { get { return TotalWidth / NumOfColumns; } } private int BoxDimension { get { return OuterBoxDimension - (2 * BorderWidth + SiblingPadding); } } private int SurplusSpace { get { return TotalWidth - (BoxDimension * NumOfColumns); } } private Random random = new Random(); private string InstId { get { if (_myId == null) _myId = Guid.NewGuid().GetHashCode().ToString(); return "cube" + _myId; } } private string _myId; }