Added round rectangle, cicle and triangle.

Applied Antialias on most of elements.
This commit is contained in:
Creeper Lv
2026-01-10 03:40:54 +11:00
parent 98d3cd4717
commit b032249942
15 changed files with 502 additions and 156 deletions

View File

@@ -42,6 +42,15 @@ namespace Progrart.Core.JSExecution
Engine = new Engine();
JsObject _obj = new JsObject(Engine);
Engine.SetValue("math", _obj);
Random r = new Random();
_obj.Set("random", JsObject.FromObject(Engine, new Func<double>(() =>
{
return r.NextDouble();
})));
_obj.Set("seed", JsObject.FromObject(Engine, new Action<JsNumber>((n) =>
{
r = new Random((int)n.AsNumber());
})));
_obj.Set("abs", JsObject.FromObject(Engine, (object)MathFunctions.abs));
_obj.Set("sin", JsObject.FromObject(Engine, (object)MathFunctions.sin));
_obj.Set("cos", JsObject.FromObject(Engine, (object)MathFunctions.cos));

View File

@@ -1,11 +1,8 @@
using Jint;
using Jint.Native;
using Jint.Native.Function;
using Jint.Native.Json;
using Progrart.Core.Graphics;
using Progrart.Core.Storage;
using System.Diagnostics;
using System.Text.Json;
namespace Progrart.Core.JSExecution
{
@@ -35,6 +32,9 @@ namespace Progrart.Core.JSExecution
engine.Engine.SetValue("visual_root", visual_root);
engine.Engine.SetValue("line", line);
engine.Engine.SetValue("rectangle", rectangle);
engine.Engine.SetValue("roundrect", roundrect);
engine.Engine.SetValue("triangle", triangle);
engine.Engine.SetValue("circle", circle);
engine.Engine.SetValue("color4", color4);
engine.Engine.SetValue("color3", color3);
engine.Engine.SetValue("color_hex", color_hex);
@@ -62,14 +62,14 @@ namespace Progrart.Core.JSExecution
public JsObject color_hex(JsString colorString)
{
byte[] bytes = Convert.FromHexString(colorString.AsString());
if (bytes.Length == 4)
if (bytes.Length == 3)
return ProgrartFunctions.color(engine.Engine
, colorFloat(bytes[0])
, colorFloat(bytes[1])
, colorFloat(bytes[2])
);
else
if (bytes.Length == 3)
if (bytes.Length == 4)
return ProgrartFunctions.color(engine.Engine
, colorFloat(bytes[0])
, colorFloat(bytes[1])
@@ -82,16 +82,12 @@ namespace Progrart.Core.JSExecution
{
return ProgrartFunctions.CreateVisualRoot(this);
}
public JsObject line()
{
//return ProgrartFunctions.CreateLine(this);
return ProgrartFunctions.CreateElement<Line>(this);
}
public JsObject rectangle()
{
//return ProgrartFunctions.CreateLine(this);
return ProgrartFunctions.CreateElement<Rectangle>(this);
}
public JsObject line() => ProgrartFunctions.CreateElement<Line>(this);
public JsObject rectangle() => ProgrartFunctions.CreateElement<Rectangle>(this);
public JsObject roundrect() => ProgrartFunctions.CreateElement<RoundRectangle>(this);
public JsObject circle() => ProgrartFunctions.CreateElement<Circle>(this);
public JsObject triangle() => ProgrartFunctions.CreateElement<Triangle>(this);
public RenderContext RenderImage(int Scale, string script, ExecuteArguments arguments)
{
float width = 1;
@@ -106,7 +102,7 @@ namespace Progrart.Core.JSExecution
{
height = (float)(js_height.AsNumber());
}
RenderContext renderContext = new((int)(width * Scale), (int)(width * Scale), StorageProvider)
RenderContext renderContext = new((int)(width * Scale), (int)(height * Scale), StorageProvider)
{
LogicalW = width,
LogicalH = height