-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMain.hxBackUp
388 lines (321 loc) · 12.3 KB
/
Main.hxBackUp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
package ;
//=======================================================================================================
import flash.display.Bitmap;
import flash.display.PixelSnapping;
import flash.display.BitmapData;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.system.ApplicationDomain;
import flash.Lib;
import aggx.color.RgbaColor;
import lib.ha.aggx.rasterizer.Scanline;
import lib.ha.aggx.rasterizer.ScanlineRasterizer;
import lib.ha.aggx.renderer.ClippingRenderer;
import lib.ha.aggx.renderer.PixelFormatRenderer;
import lib.ha.aggx.renderer.SolidScanlineRenderer;
import lib.ha.aggx.typography.FontEngine;
import lib.ha.aggx.vectorial.converters.ConvCurve;
import lib.ha.aggx.vectorial.converters.ConvDash;
import lib.ha.aggx.vectorial.converters.ConvStroke;
import lib.ha.aggx.vectorial.LineCap;
import lib.ha.aggx.vectorial.VectorPath;
import aggxtest.AADemo;
import aggxtest.AATest;
import aggxtest.AlphaGradient;
import aggxtest.Circles;
import aggxtest.TransCurve1;
import lib.ha.core.geometry.AffineTransformer;
import lib.ha.core.memory.MemoryBlock;
import lib.ha.core.memory.MemoryManager;
import lib.ha.core.memory.RgbaReaderWriter;
import lib.ha.core.utils.SWFProfiler;
import lib.ha.rfpx.TrueTypeCollection;
import lib.ha.rfpx.TrueTypeLoader;
import lib.ha.aggx.RenderingBuffer;
using lib.ha.core.memory.RgbaReaderWriter;
//=======================================================================================================
@:access(lib.ha.core.memory.MemoryBlock)
class Main
{
//---------------------------------------------------------------------------------------------------
static var pixelBufferWidth:UInt = 800;
static var pixelBufferHeight:UInt = 600;
static var pixelBufferSize:UInt = pixelBufferWidth * pixelBufferHeight * 4;
//---------------------------------------------------------------------------------------------------
static var pixelBuffer:MemoryBlock = MemoryManager.malloc(pixelBufferSize);
static var renderingBuffer = new RenderingBuffer(pixelBuffer, pixelBufferWidth, pixelBufferHeight, pixelBufferWidth * 4);
static var pixelFormatRenderer = new PixelFormatRenderer(renderingBuffer);
static var clippingRenderer = new ClippingRenderer(pixelFormatRenderer);
static var scanline = new Scanline();
static var rasterizer = new ScanlineRasterizer();
static var scanlineRenderer = new SolidScanlineRenderer(clippingRenderer);
//---------------------------------------------------------------------------------------------------
static var bitmapRectangle = new Rectangle(0, 0, pixelBufferWidth, pixelBufferHeight);
static var bitmapData = new BitmapData(pixelBufferWidth, pixelBufferHeight);
static var bitmap = new Bitmap(bitmapData, PixelSnapping.NEVER, false);
//---------------------------------------------------------------------------------------------------
static function main()
{
SWFProfiler.init();
clippingRenderer.clear(new RgbaColor(255, 255, 255));
t0();
//t3();
//t4();
//t5();
//t6();
//t7();
//t8();
//t9();
//t10();
Lib.current.addChild(bitmap);
}
//---------------------------------------------------------------------------------------------------
static inline function blit():Void
{
blitToBitmap(pixelBuffer, bitmapData, bitmapRectangle);
}
//---------------------------------------------------------------------------------------------------
static function t0():Void
{
var loader = new TrueTypeLoader("arial.ttf");
loader.load(t1);
//loader.load(t2);
}
//---------------------------------------------------------------------------------------------------
static function t1(ttc:TrueTypeCollection):Void
{
var string1 = "ABCDEFGHJIKLMNOPQRSTUVWXYZ";
var string2 = "abcdefghjiklmnopqrstuvwxyz";
var string3 = "1234567890";
var string4 = "!@#$%^&*()_+|{}:?><~`';/.,";
var string5 = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦШЩЭЮЯ";
var string6 = "абвгдеёжзийклмнопрстуфхцшщэюя";
var fontEngine = new FontEngine(ttc);
var fontSize = 30;
scanlineRenderer.color = new RgbaColor(240, 27, 106);
var x = 10;
var y = 50;
fontEngine.renderString(string1, fontSize, x, y, scanlineRenderer);
scanlineRenderer.color = new RgbaColor(27, 106, 240);
var x = 10;
var y = 70;
fontEngine.renderString(string2, fontSize, x, y, scanlineRenderer);
scanlineRenderer.color = new RgbaColor(227, 200, 26);
var x = 10;
var y = 90;
fontEngine.renderString(string3, fontSize, x, y, scanlineRenderer);
scanlineRenderer.color = new RgbaColor(106, 27, 240);
var x = 10;
var y = 110;
fontEngine.renderString(string4, fontSize, x, y, scanlineRenderer);
scanlineRenderer.color = new RgbaColor(136, 207, 100);
var x = 10;
var y = 130;
fontEngine.renderString(string5, fontSize, x, y, scanlineRenderer);
scanlineRenderer.color = new RgbaColor(136, 20, 50);
var x = 10;
var y = 150;
fontEngine.renderString(string6, fontSize, x, y, scanlineRenderer);
blit();
}
//---------------------------------------------------------------------------------------------------
static function t2(ttc:TrueTypeCollection):Void
{
var t = new TransCurve1(renderingBuffer, ttc);
t.run();
Lib.current.addEventListener(Event.ENTER_FRAME, function(e:Event) {
clippingRenderer.clear(new RgbaColor(255, 255, 255));
t.animate();
blit();
});
}
//---------------------------------------------------------------------------------------------------
static function t3():Void
{
var t = new AlphaGradient(renderingBuffer);
t.run();
blit();
}
//---------------------------------------------------------------------------------------------------
static function t4():Void
{
var t = new AADemo(renderingBuffer);
t.run();
blit();
}
//---------------------------------------------------------------------------------------------------
static function t5():Void
{
var t = new AATest(renderingBuffer);
t.run();
blit();
}
//---------------------------------------------------------------------------------------------------
static function t6():Void
{
var pixelOffset = 0.5;
var pexelAligner = new AffineTransformer();
pexelAligner.multiply(AffineTransformer.translator(.5, .5));
var tr = 10.;
var path = new VectorPath();
path.moveTo(tr, tr);
path.lineTo(pixelBufferWidth - tr, tr);
path.lineTo(pixelBufferWidth - tr, pixelBufferHeight - tr);
path.lineTo(tr, pixelBufferHeight - tr);
path.curve4(pixelBufferWidth - tr, pixelBufferHeight - tr, pixelBufferWidth - tr, tr, tr, tr);
path.closePolygon();
path.transformAllPaths(pexelAligner);
var curve = new ConvCurve(path);
var stroke = new ConvStroke(curve);
stroke.width = 0.3;
rasterizer.addPath(stroke);
scanlineRenderer.color = new RgbaColor(255, 0, 0, 255);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
rasterizer.addPath(curve);
scanlineRenderer.color = new RgbaColor(255, 0, 0, 20);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
blit();
}
//---------------------------------------------------------------------------------------------------
static function t7():Void
{
var pixelOffset = 0.5;
var tr = 10.;
var path = new VectorPath();
path.removeAll();
path.moveTo(tr + pixelOffset, tr + pixelOffset);
path.lineTo(pixelBufferWidth + pixelOffset - tr, tr + pixelOffset);
path.lineTo(pixelBufferWidth + pixelOffset - tr, pixelBufferHeight + pixelOffset - tr);
path.lineTo(tr + pixelOffset, pixelBufferHeight + pixelOffset - tr);
path.lineTo(tr + pixelOffset, pixelBufferHeight + pixelOffset - tr);
path.curve4(pixelBufferWidth + pixelOffset - tr, pixelBufferHeight + pixelOffset - tr, pixelBufferWidth + pixelOffset - tr, pixelOffset + tr, pixelOffset + tr, pixelOffset + tr);
path.closePolygon();
var curve = new ConvCurve(path);
var dash = new ConvDash(curve);
var stroke = new ConvStroke(dash);
dash.addDash(10, 10);
stroke.width = 5;
stroke.lineCap = LineCap.ROUND;
rasterizer.addPath(curve);
scanlineRenderer.color = new RgbaColor(160, 180, 80, 80);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
rasterizer.addPath(stroke);
scanlineRenderer.color = new RgbaColor(120, 100, 0);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
blit();
}
//---------------------------------------------------------------------------------------------------
static function t8():Void
{
var pixelOffset = 0.5;
var tr = 10.;
var path = new VectorPath();
path.removeAll();
path.moveTo(tr + pixelOffset, tr + pixelOffset);
path.lineTo(pixelBufferWidth + pixelOffset - tr, tr + pixelOffset);
path.lineTo(pixelBufferWidth + pixelOffset - tr, pixelBufferHeight + pixelOffset - tr);
path.lineTo(tr + pixelOffset, pixelBufferHeight + pixelOffset - tr);
path.lineTo(tr + pixelOffset, pixelBufferHeight + pixelOffset - tr);
path.curve4(pixelBufferWidth + pixelOffset - tr, pixelBufferHeight + pixelOffset - tr, pixelBufferWidth + pixelOffset - tr, pixelOffset + tr, pixelOffset + tr, pixelOffset + tr);
path.closePolygon();
var curve = new ConvCurve(path);
var stroke0 = new ConvStroke(curve);
var dash = new ConvDash(stroke0);
var stroke = new ConvStroke(dash);
stroke0.width = 5;
stroke0.lineCap = LineCap.ROUND;
dash.addDash(10, 10);
stroke.width = 1;
stroke.lineCap = LineCap.ROUND;
rasterizer.addPath(curve);
scanlineRenderer.color = new RgbaColor(160, 180, 80, 80);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
rasterizer.addPath(stroke);
scanlineRenderer.color = new RgbaColor(120, 100, 0);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
blit();
}
//---------------------------------------------------------------------------------------------------
static function t9():Void
{
var t = new Circles(renderingBuffer);
t.run();
//blit();
Lib.current.addEventListener(Event.ENTER_FRAME, function(e:Event) {
t.animate();
blit();
});
}
//---------------------------------------------------------------------------------------------------
static function t10():Void
{
var pixelOffset = 0.5;
var pexelAligner = new AffineTransformer();
pexelAligner.multiply(AffineTransformer.translator(.5, .5));
var tr = 10.;
var toCenter = true;
var path = new VectorPath();
path.transformAllPaths(pexelAligner);
var curve = new ConvCurve(path);
var dash = new ConvDash(curve);
var stroke = new ConvStroke(dash);
dash.addDash(10, 10);
stroke.width = 7;
Lib.current.addEventListener(Event.ENTER_FRAME, function(e:Event) {
var r = Std.int(Math.random() * 255);
var g = Std.int(Math.random() * 255);
var b = Std.int(Math.random() * 255);
var a = Std.int(Math.random() * 255);
clippingRenderer.clear(new RgbaColor(255, 255, 255));
//t5();
path.removeAll();
path.moveTo(tr, tr);
path.lineTo(pixelBufferWidth - tr, tr);
path.lineTo(pixelBufferWidth - tr, pixelBufferHeight - tr);
path.lineTo(tr, pixelBufferHeight - tr);
path.lineTo(tr, tr);
path.closePolygon();
if (toCenter)
{
tr += 3;
stroke.width -= 0.04;
if (tr > pixelBufferHeight / 2)
{
tr = pixelBufferHeight / 2;
toCenter = false;
stroke.width = 0.5;
}
}
else
{
tr -= 3;
stroke.width += 0.06;
if (tr < 10.)
{
tr = 10.;
toCenter = true;
stroke.width = 7;
}
}
rasterizer.addPath(stroke);
scanlineRenderer.color = new RgbaColor(g, r, b);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
rasterizer.addPath(curve);
scanlineRenderer.color = new RgbaColor(r, g, b, a);
SolidScanlineRenderer.renderScanlines(rasterizer, scanline, scanlineRenderer);
//
blit();
//t6();
});
}
//---------------------------------------------------------------------------------------------------
public static inline function blitToBitmap(block:MemoryBlock, bitmap:BitmapData, rect:Rectangle):Void
{
var pos = ApplicationDomain.currentDomain.domainMemory.position;
ApplicationDomain.currentDomain.domainMemory.position = block._start;
bitmap.lock();
bitmap.setPixels(rect, ApplicationDomain.currentDomain.domainMemory);
bitmap.unlock();
ApplicationDomain.currentDomain.domainMemory.position = pos;
}
}