/
Reprocessing_Draw.rei
648 lines (554 loc) · 20.4 KB
/
Reprocessing_Draw.rei
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/** # The Draw module
*
* This is where all the fancy things happen.
*
* ```reason;shared(sandbox)
* [@bs.val] external sandboxCanvasId: string = "";
* [@bs.val] external sandboxCanvas: 'canvas = "";
* [@bs.val] external containerDiv: 'node = "";
* [@bs.send] external addEventListener: ('node, string, 'eventT => unit) => unit = "addEventListener";
* let id = sandboxCanvasId;
* addEventListener(containerDiv, "mouseleave", (_) => Reprocessing.playPause(id, false) |> ignore);
* addEventListener(containerDiv, "mouseenter", (_) => Reprocessing.playPause(id, true) |> ignore);
* Reprocessing.setScreenId(sandboxCanvasId);
* ```
*
* ```reason;shared(draw);use(sandbox)
* open Reprocessing;
* open Draw;
* run(~setup=env => Env.size(~width=200, ~height=200, env), ~draw=((), env) => {
* %{code}%
* }, ())
* ```
*
* ```canvas;use(draw)
* fill(Constants.red, env);
* rect(~pos=Env.mouse(env), ~width=5, ~height=5, env);
* ```
*
* ## Core drawing operations
*
* @doc rect, rectf, clear, background, line, linef, ellipse, ellipsef, quad, quadf, pixel, pixelf, triangle, trianglef, bexier, arc, arcf, curve
*
* ## Style operations
*
* @doc fill, noFill, stroke, noStroke, strokeWeight, strokeCap, tint, noTint, pushStyle, popStyle
*
* ## Text
*
* @doc loadFont, text
*
* ## Images
*
* @doc loadImage, image, subImage, subImagef
*
* ## Matrix/transform operations
*
* @doc translate, rotate, scale, shear, pushMatrix, popMatrix, rectMode
*
*/;
/** Specifies an amount to displace objects within the display window.
* The dx parameter specifies left/right translation, the dy parameter
* specifies up/down translation.
*
* Transformations are cumulative and apply to everything that happens
* after and subsequent calls to the function accumulates the effect.
* For example, calling `translate dx::50 dy::0 env` and then
* `translate dx::20 dy::0 env` is the same as `translate dx::70 dy::0 env`.
* If `translate` is called within `draw`, the transformation is reset
* when the loop begins again. This function can be further controlled
* by using `pushMatrix` and `popMatrix`.
*/
let translate: (~x: float, ~y: float, Reprocessing_Types.Types.glEnvT) => unit;
/** Rotates the amount specified by the angle parameter. Angles must be
* specified in radians (values from 0 to two_pi), or they can be converted
* from degrees to radians with the `radians` function.
* The coordinates are always rotated around their relative position to the
* origin. Positive numbers rotate objects in a clockwise direction and
* negative numbers rotate in the couterclockwise direction. Transformations
* apply to everything that happens afterward, and subsequent calls to the
* function compound the effect. For example, calling
* `rotate Constants.pi/2. env` once and then calling `rotate Constants.pi/2. env`
* a second time is the same as a single `rotate Constants.pi env`. All
* tranformations are reset when `draw` begins again.
* Technically, `rotate` multiplies the current transformation matrix by a
* rotation matrix. This function can be further controlled by `pushMatrix`
* and `popMatrix`.
*/
let rotate: (float, Reprocessing_Types.Types.glEnvT) => unit;
/** The scale() function increases or decreases the size of a shape by expanding
* and contracting vertices.
*/
let scale: (~x: float, ~y: float, Reprocessing_Types.Types.glEnvT) => unit;
/** The shear() function shears the matrix along the axes the amount
* specified by the angle parameters. Angles should be specified in radians
* (values from 0 to PI*2) or converted to radians with the Utils.radians()
* function.
*/
let shear: (~x: float, ~y: float, Reprocessing_Types.Types.glEnvT) => unit;
/** Sets the color used to fill shapes.*/
let fill:
(Reprocessing_Types.Types.colorT, Reprocessing_Types.Types.glEnvT) => unit;
/** Disables filling geometry. If both `noStroke` and `noFill` are called,
* nothing will be drawn to the screen.
*/
let noFill: Reprocessing_Types.Types.glEnvT => unit;
/** Sets the fill value for displaying images. Images can be tinted to specified colors
* or made transparent by including an alpha value.
*/
let tint:
(Reprocessing_Types.Types.colorT, Reprocessing_Types.Types.glEnvT) => unit;
/** Removes the current fill value for displaying images and reverts to displaying
* images with their original hues.
*/
let noTint: Reprocessing_Types.Types.glEnvT => unit;
/** Sets the color used to draw lines and borders around shapes. */
let stroke:
(Reprocessing_Types.Types.colorT, Reprocessing_Types.Types.glEnvT) => unit;
/** Disables drawing the stroke (outline). If both noStroke() and noFill()
* are called, nothing will be drawn to the screen.
*/
let noStroke: Reprocessing_Types.Types.glEnvT => unit;
/** Sets the width of the stroke used for lines, points, and the border around
* shapes. All widths are set in units of pixels.
*/
let strokeWeight: (int, Reprocessing_Types.Types.glEnvT) => unit;
/** Sets the style for rendering line endings. These ends are either squared,
* extended, or rounded.
*/
let strokeCap:
(Reprocessing_Types.Types.strokeCapT, Reprocessing_Types.Types.glEnvT) =>
unit;
/** Sets the style to modify the location from which rectangles are drawn by
* changing the way in which parameters given to rect() and rectf() are intepreted.
*
* The default mode is rectMode(Corner), which interprets the position of rect()
* as the upper-left corner of the shape, while the third and fourth parameters
* are its width and height.
*
* rectMode(Center) interprets the position of rect() as the shape's center point,
* while the third and fourth parameters are its width and height.
*
* rectMode(Radius) also uses the position of rect() as the shape's center point,
* but uses the third and fourth parameters to specify half of the shapes's width
* and height.
*/
let rectMode:
(Reprocessing_Types.Types.rectModeT, Reprocessing_Types.Types.glEnvT) => unit;
/** The `pushStyle` function saves the current style settings and `popStyle`
* restores the prior settings. Note that these functions are always used
* together. They allow you to change the style settings and later return to
* what you had. When a new style is started with `pushStyle`, it builds on the
* current style information. The `pushStyle` and `popStyle` functions can be
* embedded to provide more control.
*
* The style information controlled by the following functions are included in
* the style: fill, stroke, strokeWeight
*/
let pushStyle: Reprocessing_Types.Types.glEnvT => unit;
/** The `pushStyle` function saves the current style settings and
* `popStyle` restores the prior settings; these functions are always used
* together. They allow you to change the style settings and later return to
* what you had. When a new style is started with `pushStyle`, it builds on the
* current style information. The `pushStyle` and `popStyle` functions can be
* embedded to provide more control.
*
* The style information controlled by the following functions are included in
* the style: fill, stroke, strokeWeight
*/
let popStyle: Reprocessing_Types.Types.glEnvT => unit;
/** Pushes the current transformation matrix onto the matrix stack. Understanding pushMatrix() and popMatrix()
* requires understanding the concept of a matrix stack. The pushMatrix() function saves the current coordinate
* system to the stack and popMatrix() restores the prior coordinate system. pushMatrix() and popMatrix() are
* used in conjuction with the other transformation methods and may be embedded to control the scope of
* the transformations.
*/
let pushMatrix: Reprocessing_Types.Types.glEnvT => unit;
/** Pops the current transformation matrix off the matrix stack. Understanding pushing and popping requires
* understanding the concept of a matrix stack. The pushMatrix() function saves the current coordinate system to
* the stack and popMatrix() restores the prior coordinate system. pushMatrix() and popMatrix() are used in
* conjuction with the other transformation methods and may be embedded to control the scope of the transformations.
*/
let popMatrix: Reprocessing_Types.Types.glEnvT => unit;
/** Loads an image and returns a handle to it. This will lazily load and
* attempting to draw an image that has not finished loading will result
* in nothing being drawn.
* In general, all images should be loaded in `setup` to preload them at
* the start of the program.
* If isPixel is set to true, then when scaling the image, it will use
* GL_NEAREST (you want this setting if your image is meant to look
* pixelated)
*/
let loadImage:
(~filename: string, ~isPixel: bool=?, Reprocessing_Types.Types.glEnvT) =>
Reprocessing_Types.Types.imageT;
/** The `imagef` function draws an image to the display window.
* The image should be loaded using the `loadImage` function.
* The image is displayed at its original size unless width and
* height are optionally specified.
*/
let imagef:
(
Reprocessing_Types.Types.imageT,
~pos: (float, float),
~width: float=?,
~height: float=?,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** The `image` function draws an image to the display window.
* The image should be loaded using the `loadImage` function.
* The image is displayed at its original size unless width and
* height are optionally specified.
*
* This is the same as `imagef` but takes in integers instead of floats for convenience.
*/
let image:
(
Reprocessing_Types.Types.imageT,
~pos: (int, int),
~width: int=?,
~height: int=?,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** The `subImage` function draws a section of an image to the
* display window. The image should be loaded using the
* `loadImage` function. The image is displayed at the size
* specified by width and height. texPos, texWidth, and
* texHeight describe the section of the full image that
* should be drawn.
*
* This function is useful for a spritesheet-style of
* drawing strategy.
*/
let subImage:
(
Reprocessing_Types.Types.imageT,
~pos: (int, int),
~width: int,
~height: int,
~texPos: (int, int),
~texWidth: int,
~texHeight: int,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** The `subImagef` function draws a section of an image to the
* display window. The image should be loaded using the
* `loadImage` function. The image is displayed at the size
* specified by width and height. texPos, texWidth, and
* texHeight describe the section of the full image that
* should be drawn.
*
* This function is useful for a spritesheet-style of
* drawing strategy.
*/
let subImagef:
(
Reprocessing_Types.Types.imageT,
~pos: (float, float),
~width: float,
~height: float,
~texPos: (int, int),
~texWidth: int,
~texHeight: int,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws a rectangle to the screen. A rectangle is a four-sided shape with
* every angle at ninety degrees.
*/
let rectf:
(
~pos: (float, float),
~width: float,
~height: float,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws a rectangle to the screen. A rectangle is a four-sided shape with
* every angle at ninety degrees.
*
* This is the same as `rectf` but takes in integers instead of floats for convenience.
*/
let rect:
(
~pos: (int, int),
~width: int,
~height: int,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws a curved line on the screen. The first parameter specifies
* the beginning control point and the last parameter specifies the ending
* control point. The middle parameters specify the start and stop of the curve.
*/
let curve:
(
(float, float),
(float, float),
(float, float),
(float, float),
Reprocessing_Common.glEnv
) =>
unit;
/** Draws a line (a direct path between two points) to the screen.
* To color a line, use the `stroke` function. A line cannot be filled,
* therefore the `fill` function will not affect the color of a line. Lines are
* drawn with a width of one pixel by default, but this can be changed with
* the `strokeWeight` function.
*/
let linef:
(
~p1: (float, float),
~p2: (float, float),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws a line (a direct path between two points) to the screen.
* To color a line, use the `stroke` function. A line cannot be filled,
* therefore the `fill` function will not affect the color of a line. Lines are
* drawn with a width of one pixel by default, but this can be changed with
* the `strokeWeight` function.
*
* This is the same as `linef`, but converts all its integer arguments to floats
* as a convenience.
*/
let line:
(~p1: (int, int), ~p2: (int, int), Reprocessing_Types.Types.glEnvT) => unit;
/** Draws an ellipse (oval) to the screen. An ellipse with equal width and
* height is a circle.
*/
let ellipsef:
(
~center: (float, float),
~radx: float,
~rady: float,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws an ellipse (oval) to the screen. An ellipse with equal width and
* height is a circle.
*
* This is the same as `ellipsef`, but converts all its integer arguments to
* floats as a convenience.
*/
let ellipse:
(
~center: (int, int),
~radx: int,
~rady: int,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** A quad is a quadrilateral, a four sided polygon. It is similar to a
* rectangle, but the angles between its edges are not constrained to ninety
* degrees. The parameter p1 sets the first vertex and the subsequest points
* should proceed clockwise or counter-clockwise around the defined shape.
*/
let quadf:
(
~p1: (float, float),
~p2: (float, float),
~p3: (float, float),
~p4: (float, float),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** A quad is a quadrilateral, a four sided polygon. It is similar to a
* rectangle, but the angles between its edges are not constrained to ninety
* degrees. The parameter p1 sets the first vertex and the subsequest points
* should proceed clockwise or counter-clockwise around the defined shape.
*
* This is the same as `quadf`, but converts all its integer arguments to
* floats as a convenience.
*/
let quad:
(
~p1: (int, int),
~p2: (int, int),
~p3: (int, int),
~p4: (int, int),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Adds a single point with a radius defined by strokeWeight */
let pixelf:
(
~pos: (float, float),
~color: Reprocessing_Types.Types.colorT,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Adds a single point with a radius defined by strokeWeight
*
* This is the same as `pixelf`, but converts all its integer arguments to
* floats as a convenience.
*/
let pixel:
(
~pos: (int, int),
~color: Reprocessing_Types.Types.colorT,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** A triangle is a plane created by connecting three points. */
let trianglef:
(
~p1: (float, float),
~p2: (float, float),
~p3: (float, float),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** A triangle is a plane created by connecting three points.
*
* This is the same as `trianglef`, but converts all its integer arguments to
* floats as a convenience.
*/
let triangle:
(
~p1: (int, int),
~p2: (int, int),
~p3: (int, int),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws a Bezier curve on the screen. These curves are defined by a
* series of anchor and control points. The parameter p1 specifies the
* first anchor point and the last parameter specifies the other anchor
* point. The middle parameters p2 and p3 specify the control points
* which define the shape of the curve. Bezier curves were developed
* by French engineer Pierre Bezier.
*/
let bezier:
(
~p1: (float, float),
~p2: (float, float),
~p3: (float, float),
~p4: (float, float),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws an arc to the screen. Arcs are drawn along the outer edge of an
* ellipse defined by the center, radx, and rady parameters. Use the
* start and stop parameters to specify the angles (in radians) at which
* to draw the arc. isPie defines whether or not lines should be drawn to
* the center at the start and stop points of the arc rather than simply
* connecting the points. If isOpen is true, no line will be drawn other
* than the arc between start and stop.
*/
let arcf:
(
~center: (float, float),
~radx: float,
~rady: float,
~start: float,
~stop: float,
~isOpen: bool,
~isPie: bool,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Draws an arc to the screen. Arcs are drawn along the outer edge of an
* ellipse defined by the center, radx, and rady parameters. Use the
* start and stop parameters to specify the angles (in radians) at which
* to draw the arc. isPie defines whether or not lines should be drawn to
* the center at the start and stop points of the arc rather than simply
* connecting the points. If isOpen is true, no line will be drawn other
* than the arc between start and stop.
*
* This is the same as `arcf`, but converts all its integer arguments to
* floats as a convenience.
*/
let arc:
(
~center: (int, int),
~radx: int,
~rady: int,
~start: float,
~stop: float,
~isOpen: bool,
~isPie: bool,
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Loads a font and returns a handle to it. This will lazily load and
* attempting to draw an font that has not finished loading will result
* in nothing being drawn.
* In general, all fonts should be loaded in `setup` to preload them at
* the start of the program.
* If isPixel is set to true, then when scaling the font, it will use
* GL_NEAREST (you want this setting if your font is meant to look
* pixelated)
*/
let loadFont:
(~filename: string, ~isPixel: bool=?, Reprocessing_Types.Types.glEnvT) =>
Reprocessing_Font.fontT;
/** Draws text to the screen.
*
* To use a font, use [loadFont](#value-loadFont) in your `setup()` function. If you don't specify a font, the default font is used.
*
* ```canvas;use(draw)
* Draw.background(Constants.white, env);
* text(~body="Hello folks", ~pos=(5, 40), env);
* ```
*/
let text:
(
~font: Reprocessing_Font.fontT=?,
~body: string,
~pos: (int, int),
Reprocessing_Types.Types.glEnvT
) =>
unit;
/** Calculates width of text using a specific font.
* The font should be loaded using the `loadFont` function.
*/
let textWidth:
(
~font: Reprocessing_Font.fontT=?,
~body: string,
Reprocessing_Types.Types.glEnvT
) =>
int;
/** Clears the entire screen. Normally, background is used for this purpose,
* clear will have different results in web and native.
*/
let clear: Reprocessing_Types.Types.glEnvT => unit;
/** The `background` function sets the color used for the background of the
* Processing window. The default background is black. This function is
* typically used within `draw` to clear the display window at the beginning of
* each frame, but it can be used inside `setup` to set the background on the
* first frame of animation or if the backgound need only be set once.
*/
let background:
(Reprocessing_Types.Types.colorT, Reprocessing_Types.Types.glEnvT) => unit;
/** Makes draw calls inside the callback draw to the given image instead of to the screen.
* The callback is called with a new env which will make all draw calls done inside the callback
* draw on the image instead of the main canvas.
* This is useful to basically cache draw calls onto an image which can then be drawn to the
* screen very cheaply at any point after.
*/
let withImage:
(
Reprocessing_Types.Types.imageT,
Reprocessing_Types.Types.glEnvT,
Reprocessing_Types.Types.glEnvT => unit
) =>
unit;
/** Returns a new image which can be drawn to.
*/
let createImage:
(~width: int, ~height: int, Reprocessing_Types.Types.glEnvT) =>
Reprocessing_Types.Types.imageT;
/** Checks whether the given image has been drawn to since created or since last time clearImage
* was called. This is useful when using images as a caching mechanism, to check if the image is
* up to date.
*/
let isImageDrawnTo: Reprocessing_Types.Types.imageT => bool;
/** Clears image such that `isImageDrawnTo` returns false.
*/
let clearImage:
(Reprocessing_Types.Types.imageT, Reprocessing_Types.Types.glEnvT) => unit;