Skip to content

Commit 86e7df2

Browse files
committed
切分文字的示例
1 parent 5914752 commit 86e7df2

File tree

3 files changed

+120
-19
lines changed

3 files changed

+120
-19
lines changed

Danmakux/ClipHelper.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,51 @@ public static void TestCase(GraphicHelper helper)
187187
File.WriteAllText("resultTxt.txt", resultValue);
188188
}
189189

190-
public static void ClipChar(GraphicHelper helper, string str)
190+
public static void ClipChar(GraphicHelper helper, string str, string dstStr)
191191
{
192192
var poly = new Polygon(new LinearLineSegment(
193-
new PointF(-400, -1024), new PointF(800, -1024),
194-
new PointF(-400, 2048)));
193+
new PointF(700, -700), new PointF(700, 700),
194+
new PointF(0, 700)));
195+
int index = 0;
195196
foreach (var ch in str)
196197
{
197198
var graphic = helper.graphicData[ch];
199+
var dstGraphic = new GraphicInfo();
200+
dstGraphic.Character = dstStr[index].ToString();
201+
dstGraphic.Height = graphic.Height;
202+
dstGraphic.Width = graphic.Width;
198203
List<string> resultStroke = new List<string>();
199204
foreach (var stroke in graphic.Strokes)
200205
{
201206
resultStroke.AddRange(Clip(stroke, poly));
202207
}
203208

204-
graphic.Strokes = resultStroke;
209+
dstGraphic.Strokes = resultStroke;
210+
helper.graphicData[dstStr[index]] = dstGraphic;
211+
index++;
212+
}
213+
}
214+
215+
public static void ClipChar(GraphicHelper helper, LinearLineSegment clip, string str, string dstStr)
216+
{
217+
var poly = new Polygon(clip);
218+
int index = 0;
219+
foreach (var ch in str)
220+
{
221+
var graphic = helper.graphicData[ch];
222+
var dstGraphic = new GraphicInfo();
223+
dstGraphic.Character = dstStr[index].ToString();
224+
dstGraphic.Height = graphic.Height;
225+
dstGraphic.Width = graphic.Width;
226+
List<string> resultStroke = new List<string>();
227+
foreach (var stroke in graphic.Strokes)
228+
{
229+
resultStroke.AddRange(Clip(stroke, poly));
230+
}
231+
232+
dstGraphic.Strokes = resultStroke;
233+
helper.graphicData[dstStr[index]] = dstGraphic;
234+
index++;
205235
}
206236
}
207237
}

Danmakux/MotionHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public MotionHelper Apply(float duration, TextProperty prop = null, string moti
166166
return this;
167167
}
168168

169+
public void ForceSetBackup(bool value)
170+
{
171+
_allBackupLayerRequired = value;
172+
}
173+
169174
public void ProcessBackupLayer()
170175
{
171176
if (_allBackupLayerRequired)

Danmakux/Program.cs

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using QRCoder;
5+
using SixLabors.ImageSharp;
6+
using SixLabors.ImageSharp.Drawing;
57

68
namespace Danmakux
79
{
@@ -396,30 +398,91 @@ static void Main(string[] args)
396398
{
397399
p.x = 0;
398400
p.alpha = 1;
399-
p.y = -150;
401+
p.y = -75;
400402
p.rotateX = 0;
401403
p.rotateY = 0;
402404
p.rotateZ = 0;
403-
405+
p.scale = 1.0f;
404406
}, (motion, p, noChar, noStroke) =>
405407
{
406408
motion.Apply(strokeOffset * noStroke);
407409

408410
motion.Apply(0.3f, new TextProperty
409411
{
410-
y = 0
412+
y = 100,
413+
scale = 1.2f
411414
}, "cubic-bezier(0,.6,.2,1)");
412415
});
413416
}
414417

418+
419+
420+
var seg1 = new LinearLineSegment(
421+
new PointF(500, -700), new PointF(700, 700),
422+
new PointF(-200, 700));
423+
var seg2 = new LinearLineSegment(
424+
new PointF(500, -700), new PointF(-700, -700),
425+
new PointF(-700, 700), new PointF(-200, 700));
426+
ClipHelper.ClipChar(helper, seg1, "残", "攒");
427+
ClipHelper.ClipChar(helper, seg2, "残", "撰");
428+
415429
helper.DefParent("s6", null, new TextProperty()
416430
{
417431
x = 50,
418432
y = 50,
419-
duration = 0.4f,
433+
duration = 4.4f,
420434
scale = 1.0f
421435
});
436+
{
437+
const int charDistance = 50;
438+
const int rotateDiff = 25;
439+
const float strokeOffset = 0.002f;
440+
const float charOffset = 0f;
441+
442+
TextProperty prop = new TextProperty();
443+
prop.duration = 14;
444+
prop.scale = 1.0f;
445+
prop.fillColor = "0xeeeeee";
446+
prop.alpha = 1.0f;
447+
helper.AddText("攒", "s6", "s6", prop, (p, noChar, noStroke) =>
448+
{
449+
p.x = 0;
450+
p.alpha = 0;
451+
p.y = 100;
452+
p.scale = 1.0f;
453+
454+
}, (motion, p, noChar, noStroke) =>
455+
{
456+
motion.Apply(.4f);
457+
motion.Apply(strokeOffset * noStroke, new TextProperty
458+
{
459+
alpha = 1
460+
});
422461

462+
motion.Apply(1f, new TextProperty
463+
{
464+
y = -100
465+
},"cubic-bezier(0,1,0,1)", true);
466+
467+
motion.Apply(10, isBackup: true);
468+
469+
motion.Apply(1f, new TextProperty
470+
{
471+
x = 300
472+
}, "cubic-bezier(0,.5,0,1)");
473+
474+
motion.ForceSetBackup(true);
475+
});
476+
}
477+
478+
479+
helper.DefParent("s7", null, new TextProperty()
480+
{
481+
x = 50,
482+
y = 50,
483+
duration = 4.4f,
484+
scale = 1.0f
485+
});
423486
{
424487
const int charDistance = 50;
425488
const int rotateDiff = 25;
@@ -431,25 +494,28 @@ static void Main(string[] args)
431494
prop.scale = 1.0f;
432495
prop.fillColor = "0xeeeeee";
433496
prop.alpha = 1.0f;
434-
helper.AddText("", "s6", "s6", prop, (p, noChar, noStroke) =>
497+
helper.AddText("", "s7", "s7", prop, (p, noChar, noStroke) =>
435498
{
436499
p.x = 0;
437-
p.alpha = 1;
438-
p.y = -150;
439-
p.rotateX = 0;
440-
p.rotateY = 0;
441-
p.rotateZ = 0;
500+
p.alpha = 0;
501+
p.y = 100;
442502
p.scale = 1.0f;
443503

444504
}, (motion, p, noChar, noStroke) =>
445505
{
446-
motion.Apply(strokeOffset * noStroke);
506+
motion.Apply(.4f);
507+
motion.Apply(strokeOffset * noStroke, new TextProperty
508+
{
509+
alpha = 1
510+
});
447511

448-
motion.Apply(0.3f, new TextProperty
512+
motion.Apply(1f, new TextProperty
449513
{
450-
y = 0,
451-
scale = 2.0f
452-
}, "cubic-bezier(0,.6,.2,1)");
514+
y = 200,
515+
alpha = 0
516+
}, "cubic-bezier(0,.3,0,1)");
517+
518+
motion.ForceSetBackup(true);
453519
});
454520
}
455521

0 commit comments

Comments
 (0)