HeavenStudioPlus/Assets/Plugins/Starpelly/Textures.cs
2021-12-18 23:10:43 -05:00

21 lines
No EOL
582 B
C#

using UnityEngine;
namespace Starpelly.Textures
{
public static class Draw
{
public static void DrawLine(this Texture2D tex, Vector2 p1, Vector2 p2, Color col)
{
Vector2 t = p1;
float frac = 1 / Mathf.Sqrt(Mathf.Pow(p2.x - p1.x, 2) + Mathf.Pow(p2.y - p1.y, 2));
float ctr = 0;
while ((int)t.x != (int)p2.x || (int)t.y != (int)p2.y)
{
t = Vector2.Lerp(p1, p2, ctr);
ctr += frac;
tex.SetPixel((int)t.x, (int)t.y, col);
}
}
}
}