[c#] color text

  • На форуме работает ручное одобрение пользователей. Это значит, что, если Ваша причина регистрации не соответствует тематике форума, а также Вы используете временную почту, Ваша учётная запись будет отклонена без возможности повторной регистрации. В дальнейшем - пожизненная блокировка обоих аккаунтов за создание мультиаккаунта.
  • Мы обновили Tor зеркало до v3!
    Для входа используйте следующий url: darkv3nw2...bzad.onion/
  • Мы вновь вернули telegram чат форуму, вступайте, общайтесь, задавайте любые вопросы как администрации, так и пользователям!
    Ссылка: https://t.me/chat_dark_time

Dream

VIP

Dream

VIP
3 Май 2016
1,235
972
Переделал клас с vb.net на C#

Class на [C#]

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Color_Text
{
class MyCodeGradient
{
public MyCodeGradient(string text)
{
_text = text;
}

private readonly string _text;

public Color StartColor { get; set; }
public Color EndColor { get; set; }

public string Generate()
{
char[] chars = _text.ToCharArray();
List<Color> colors = BuildGradient(chars.Count(c => !c.Equals(' ')));

StringBuilder sb = new StringBuilder();
int compensator = 0;

for (int i = 0; i <= chars.Count() - 1; i++)
{
if (!chars.Equals(' '))
{
sb.Append(string.Format("[color={0}]{1}[/color]", ColorTranslator.ToHtml(colors[i - compensator]), chars));
}
else
{
sb.Append(' ');
compensator += 1;
}
}

return sb.ToString();
}

private List<Color> BuildGradient(int stepCount)
{
int rMin = EndColor.R;
int rMax = StartColor.R;
int gMin = EndColor.G;
int gMax = StartColor.G;
int bMin = EndColor.B;
int bMax = StartColor.B;

List<Color> colors = new List<Color>();
for (int i = 0; i <= stepCount - 1; i++)
{
int rAvg = rMax + Convert.ToInt32((rMin - rMax) * i / stepCount);
int gAvg = gMax + Convert.ToInt32((gMin - gMax) * i / stepCount);
int bAvg = bMax + Convert.ToInt32((bMin - bMax) * i / stepCount);

colors.Add(Color.FromArgb(rAvg, gAvg, bAvg));
}

return colors;
}
}
}
Class на [vb.net]
Option Strict On
Imports System.Text
Public Class MyCodeGradient
Public Sub New(text As String)
_text = text
End Sub
Private ReadOnly _text As String
Public Property StartColor As Color
Public Property EndColor As Color
Public Function Generate() As String
Dim chars As Char() = _text.ToCharArray()
Dim colors As List(Of Color) = BuildGradient(chars.Count(Function(c) Not c.Equals(" "c)))
Dim sb As New StringBuilder
Dim compensator As Integer = 0
For i As Integer = 0 To chars.Count - 1
If Not chars(i).Equals(" "c) Then
sb.Append(String.Format("[color={0}]{1}[/color]", ColorTranslator.ToHtml(colors(i - compensator)), chars(i)))
Else
sb.Append(" "c)
compensator += 1
End If
Next
Return sb.ToString()
End Function
Private Function BuildGradient(stepCount As Integer) As List(Of Color)
Dim rMin As Integer = EndColor.R, rMax As Integer = StartColor.R
Dim gMin As Integer = EndColor.G, gMax As Integer = StartColor.G
Dim bMin As Integer = EndColor.B, bMax As Integer = StartColor.B
Dim colors As New List(Of Color)
For i As Integer = 0 To stepCount - 1
Dim rAvg As Integer = rMax + Convert.ToInt32((rMin - rMax) * i / stepCount)
Dim gAvg As Integer = gMax + Convert.ToInt32((gMin - gMax) * i / stepCount)
Dim bAvg As Integer = bMax + Convert.ToInt32((bMin - bMax) * i / stepCount)
colors.Add(Color.FromArgb(rAvg, gAvg, bAvg))
Next
Return colors
End Function
End Class
 

О нас

  • Наше сообщество существует уже много лет и гордится тем, что предлагает непредвзятое, критическое обсуждение различных тем среди людей разных слоев общества. Мы работаем каждый день, чтобы убедиться, что наше сообщество является одним из лучших.

    Dark-Time 2015 - 2022

    При поддержке: XenForo.Info

Быстрая навигация

Меню пользователя