Repository navigation
Expand file tree
/
Copy pathGraphics.yaml
More file actions
2375 lines (2064 loc) · 76.3 KB
/
Copy pathGraphics.yaml
File metadata and controls
2375 lines (2064 loc) · 76.3 KB
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
id: graphics
name: Graphics
subtitle: Drawing Shapes, Styles and Positioning
ordering:
- Overview
- Drawing
- Transform
- Advanced Transform
- Style
- Text Metrics
- Transform Management
- Style Management
- Images
- Drawing Into Images
- Assets
- Generators
- Setting Clipping Bounds
- Constants
- Variables
- Camera Input
functions:
#---------------------------------
# Codea Overview
#---------------------------------
- id: codeaOverview
category: overview
description: |
When you begin a new project in Codea you'll notice that it consists of a tab called `Main` and some template code. Your project can consist of several tabs, the initial one is always called `Main`. If you add more files they will be listed across the top.
function setup()
print(\"Hello World!\")
end
function draw()
background(0,0,0)
-- Do your drawing here
end
This is the framework that your project will use to run. There are two functions defined for you initially: `setup()` and `draw()`.
`setup()` and `draw()` are executed by Codea when you press the play button to run your project. The `setup()` function is called once, at the start, and then the `draw()` function is called repeatedly (60 times per second, to be exact). In `setup()` Codea expects you to set up your initial program state, and in `draw()` you can tell Codea to render graphics onto the screen, update your program state over time, and so on.
In the next two sections we will cover these functions in detail.
group: Overview
name: How Codea Draws
related: [draw, setup]
#---------------------------------
#---------------------------------
# Assets Overview
#---------------------------------
- id: assetsOverview
category: overview
description: |
While Codea lets you draw lines and shapes, it's far more interesting to use resources like images, sounds, and 3D models. That's where assets come in. When you call a function like `sprite` you need to give it an image to draw. There are a few ways to do this, the easiest is to type the code `sprite()` and then tap on the highlighted parentheses `()`. This will present the asset picker so you can visually select an image
When you do this, you'll notice that the image you select is referred to with an *asset key*, it might look something like `asset.builtin.Planet_Cute.Icon`. An *asset key* describes the location of a file on your device, and Codea actually checks that the file exists while you are writing your code. If you type an asset key that does not exist, you will notice that Codea puts a red marker next to your code informing you that the specified asset can't be found
**Specifying Assets**
Start by typing the word `assets` in your code followed by a dot (`.`), you will see the list of autocomplete suggestions appear, and these will refer to real files and folders on your device
**Asset Locations**
*Project*: to specify assets in your current project, just type `asset.AssetName` where "AssetName" is a file or folder in your project
*Documents*: to specify assets in Codea's documents folder, type `asset.documents.AssetName`
*Built-in*: to specify assets from Codea's built-in collection of sprites, sounds and shaders, use `asset.builtin.AssetName`
**Creating New Assets**
When you need to tell Codea where to save a file, you can use the Lua concatenation operator (`..`) to create an asset key to a non-existent path. For example:
saveText(asset.documents .. "readme.txt", "Hello World")
The code `asset.documents .. "readme.txt"` tells Codea to create a path in your documents folder pointing to file called "readme.txt"
**Enumerating Assets**
To get the number of files in a folder you can use the Lua length operator (`#`), some examples:
-- Number of files in your project
print(#assets)
-- Number of files in documents
print(#asset.documents)
-- Number of files in a folder in documents
print(#asset.documents.SomeFolder)
To list all assets in a folder you can append `.all` onto the folder path to return an array of the folder contents as asset keys, e.g.,
-- Get all files in the current project
-- and iterate over them, printing their
-- path
for i,v in pairs(asset.all) do
print(i, v.path)
end
**Special Cases**
Codea tries to surface as many of the assets from your files into your code as it can, but sometimes you'll have files named with special characters and these won't translate into valid variable names in Lua. To access the raw contents of an asset library you can use square bracket notation, for example: `asset.documents["My File (2).png"]`. Codea won't be able to check whether the asset exists or offer autocomplete for this syntax
One other special case occurs if you have multiple files with identical names, but different file extensions. In this case Codea will offer them as static assets using `_ext` for the extension to differentiate. For example, `asset.MyObject_png` and `asset.MyObject_obj` refer to "MyObject.png" and "MyObject.obj" in your Codea project respectively
**Asset Library Tracking**
Finally, you can tell Codea to monitor a folder for changes by assigning a function to the `updated` property of the specified folder. Note that this only works on asset paths to folders, not to individual files. For example:
-- Track files in a folder in
-- documents for changes
asset.documents.MyFolder.updated = function (lib)
print("Number of files " .. #lib)
end
-- Track files in your project
asset.updated = function (lib)
print("Project files modified", lib)
end
group: Overview
name: Using Assets
related: [assets, assets.key, sprite, saveText]
#---------------------------------
#---------------------------------
# Drawing Overview
#---------------------------------
- id: draw
category: event
description: |
When you press the play button, the `draw()` function is repeatedly executed by Codea. Codea tries to execute the `draw()` function 60 times per second - if it can. Codea can't guarantee that your `draw()` function will be called 60 times per second (it may slow down if your project performs a lot of computation, or creates highly complex drawing).
function draw()
-- Set the background color to blueish
background(100,120,180)
-- Set the fill color to red
fill(255,0,0)
-- Set a wide outline
strokeWidth(5)
-- Set the outline color to white
stroke(255)
-- Draw a red circle with a white outline
-- In the center of the screen
ellipse( WIDTH/2, HEIGHT/2, 200 )
end
Note that the above code will run 60 times every second. That is, you are telling Codea to paint the background blue and draw a red circle with a white outline 60 times per second, from scratch. It does this so that you can create smooth motion by changing your program state over time, and updating your drawing code to reflect the new state. For example, you might make the circle bounce on the ground by changing its Y-position (the second parameter to `ellipse()`) every frame.
group: Overview
name: function draw()
related: [setup]
#---------------------------------
#---------------------------------
# Setup Overview
#---------------------------------
- id: setup
category: event
description: |
When you press the play button Codea will call the `setup()` function once, before it begins calling the `draw()` function. In here you can perform any once-off computations, set up program state, set the display mode, and do things that you don't need to do every frame. For example, the `setup()` function below creates a global variable controlled by a slider. This variable is then used in the `draw()` function to control the Y-position of a circle.
function setup()
displayMode(STANDARD)
parameter("YPosition", 0,
HEIGHT, HEIGHT/2)
end
function draw()
background(0)
fill(255,0,0)
ellipse( WIDTH/2,
YPosition,
200 )
end
group: Overview
name: function setup()
related: [draw]
#---------------------------------
#---------------------------------
# clip()
#---------------------------------
- id: clip
category: function
description: >
Constrains all drawing performed after this function call to the
rectangle specified by `x`, `y`, `width`, `height`. Any
drawing that occurs outside the bounds will not be visible.
This can be used to make split-screen multiplayer games, for example.
When called with zero arguments `clip()` disables the clipping rectangle,
allowing drawing to occur anywhere on the screen.
group: Setting Clipping Bounds
name: clip( x, y, width, height )
parameters:
- description: integer, x coordinate of the lower-left corner of the clipping
rectangle
name: x
- description: integer, y coordinate of the lower-left corner of the clipping
rectangle
name: y
- description: integer, width of the clipping rectangle
name: width
- description: integer, height of the clipping rectangle
name: height
syntax: |
clip( x, y, width, height )
clip() --Disables clipping
#---------------------------------
#---------------------------------
# setContext()
#---------------------------------
- id: setContext
category: function
description: >
This call causes all drawing operations to take place on the specified
image instead of on-screen. Drawing commands such as `ellipse`, `sprite`
and `rect` will render into the image given as an argument to `setContext()`.
Calling `setContext()` with no arguments causes all drawing operations to return
to their regular on-screen drawing functionality. Because Codea uses pre-multiplied
drawing, any image passed to `setContext()` will have its premultiplied
flag set to true.
An optional final argument `useDepth` can be specified to tell `setContext` to
also allocate a depth buffer for the image. By default `setContext` will not.
Allocating a depth buffer impacts performance, but allows rendering of 3D content
into an image.
examples:
- example: |
-- Creates an image of an ellipse and rect
function createImage()
myImage = image(400,400)
setContext( myImage )
ellipse(200, 200, 200)
rect(0, 0, 100, 100)
setContext()
return myImage
end
group: Drawing Into Images
name: setContext( image )
parameters:
- description: image, all drawing operations will occur on this image instead
of on screen
name: image
- description: boolean, whether a depth buffer should be created for this image, defaults
to false if not specified
name: useDepth
related: [image]
syntax: |
setContext()
setContext( image )
setContext( image, useDepth )
#---------------------------------
# noise()
#---------------------------------
- id: noise
category: function
description: >
Returns a Perlin noise value in the range -1.0 to 1.0 sampled at
location `x`, `y`, `z`. Any parameters not provided to this function
are treated as zero.
group: Generators
name: noise( x, y, z )
parameters:
- description: float, x location of the sample
name: x
- description: float, y location of the sample
name: y
- description: float, z location of the sample
name: z
returns: Perlin noise value from -1.0 to 1.0 at the given location.
syntax: |
noise( x )
noise( x, y )
noise( x, y, z )
#---------------------------------
# background()
#---------------------------------
- id: background
category: function
description: >
Clears the background to the specified color. You should generally
call this at the start of your `draw()` function in order to clear the
contents of the previous frame.
examples:
- example: |
function draw()
-- Dark blueish background
background(0, 50, 70)
-- Do some drawing
end
group: Drawing
name: background( red, green, blue )
parameters:
- description: int from `0` to `255`, specifies value between white and black
name: gray
- description: int from `0` to `255`, specifies opacity of the background
name: alpha
- description: int from `0` to `255`, specifies red amount of the background
name: red
- description: int from `0` to `255`, specifies green amount of the background
name: green
- description: int from `0` to `255`, specifies blue amount of the background
name: blue
- description: a value of the color datatype
name: color
related: [color, backingMode]
syntax: |
background( gray )
background( gray, alpha )
background( red, green, blue )
background( red, green, blue, alpha )
background( color )
#---------------------------------
#---------------------------------
# ellipse()
#---------------------------------
- id: ellipse
category: function
description: >
Draws an ellipse centered at `x`, `y` with horizontal and vertical
dimensions specified by `width` and `height`. The `ellipseMode()`
function sets how these parameters are interpreted. Use `fill()` to set
the color of an ellipse and `stroke()` to set its outline color.
If only the `width` is specified, this is treated as the ellipse
`diameter` (or `radius`, if `ellipseMode( RADIUS )` is used).
The interpretation
of an ellipse's `x`, `y`, `width` and `height` parameters can be specified
using the `ellipseMode()` function. `ellipseMode()` is set to `CENTER`
by default.
group: Drawing
name: ellipse( x, y, width, height )
parameters:
- description: x-coordinate of the ellipse
name: x
- description: y-coordinate of the ellipse
name: y
- description: width of the ellipse
name: width
- description: height of the ellipse
name: height
related: [ellipseMode, fill, stroke]
syntax: |
ellipse( x, y, diameter )
ellipse( x, y, width, height )
#---------------------------------
#---------------------------------
# rect()
#---------------------------------
- id: rect
category: function
description: >
Draws a rectangle with its lower-left corner positioned at `x`,
`y` and sized at `width`, `height`. Use `fill()` to set the color
of a rectangle and `stroke()` to set the outline color.
The interpretation
of a rectangle's `x`, `y`, `width` and `height` parameters can be specified
using the `rectMode()` function. `rectMode()` is set to `CORNER`
by default.
group: Drawing
name: rect( x, y, width, height )
parameters:
- description: x-coordinate of the lower-left corner
name: x
- description: y-coordinate of the lower-left corner
name: y
- description: width of the rectangle
name: width
- description: height of the rectangle
name: height
related: [rectMode, fill, stroke]
syntax: rect( x, y, width, height )
#---------------------------------
#---------------------------------
# sprite()
#---------------------------------
- id: sprite
category: function
description: >
Draws the sprite specified by `asset`. A sprite is a a bitmap graphic (such as a character,
or a space ship). The asset specifies the location of the file to use for drawing
Alternatively, an `image` can be provided in instead of an asset to draw that
image. `CAMERA` may also by provided in order to draw the current capture
source video input.
By default the x and y parameters set the location
of the center of the sprite, the origin mode can be set using the `spriteMode()`
function. The last two parameters are optional and set the width and height
in pixels, if these are not specified the sprite will be rendered at the pixel
dimensions of its graphic. Sprites can be tinted with the `tint()` function.
examples:
- example: |
background(127, 127, 127, 255)
sprite(asset.builtin.Planet_Cute.Character_Boy,
WIDTH / 2, HEIGHT / 2)
image: media/sprite_ex1.png
- example: |
background(127, 127, 127, 255)
tint(255, 0, 0)
sprite(asset.builtin.Planet_Cute.Character_Boy,
WIDTH / 2, HEIGHT / 2)
image: media/sprite_ex2.png
- example: |
sprite(CAMERA, 0, 0)
group: Drawing
name: sprite( asset, x, y )
parameters:
- description: |
asset key of the sprite to use, in the following format:
`asset.MyFileName`
or
`CAMERA`
name: asset
- description: image to draw onto the screen
name: image
- description: x-coordinate of the center of the sprite (this can be changed with `spriteMode`)
name: x
- description: y-coordinate of the center of the sprite (this can be changed with `spriteMode`)
name: y
- description: optional width of the sprite in pixels
name: width
- description: optional height of the sprite in pixels. If `width` is specified
and `height` is not, then `height` is automatically computed to
preserve the aspect ratio of the image.
name: height
related: [assetsOverview, spriteMode, tint, noTint, image, CAMERA]
syntax: |
sprite( asset, x, y )
sprite( asset, x, y, width )
sprite( asset, x, y, width, height )
sprite( image, x, y )
sprite( image, x, y, width )
sprite( image, x, y, width, height )
#---------------------------------
#---------------------------------
# text()
#---------------------------------
- id: text
category: function
description: >
Draws text at the given `x`, `y` location. You can set
the font used by `text()` with the `font()` function. Text appearance
can be further configured by using the `fontSize()` and `fill()` functions.
You can change the alignment and wrapping of text by using `textAlign()` and
`textWrapWidth()`. If `textWrapWidth()` is set to 0 (the default)
text will be drawn on one line. If `textWrapWidth()` is set to a value
greater than 0 the text will word-wrap if it exceeds the width specified by
`textWrapWidth()`
By default the x and y parameters set the
location of the center of the text, the origin mode can be set using the `textMode()`
function. Text color can be changed with the `fill()` function.
If you need to get the dimensions of a string in the current style, see the
`textSize` function documentation.
examples:
- example: |
background(100, 120, 160)
font("Georgia")
fill(255)
fontSize(20)
textWrapWidth(70)
text("Hello World!", WIDTH/2, HEIGHT/2)
image: media/text_ex1.png
group: Drawing
name: text( string, x, y )
parameters:
- description: the text string that you would like to draw onto the screen
name: string
- description: x-coordinate of the center of the text (this can be changed with
`textMode`)
name: x
- description: y-coordinate of the center of the text (this can be changed with
`textMode`)
name: y
related: [font, fill, fontSize, textMode, textAlign, textWrapWidth, textSize]
syntax: text( string, x, y )
#---------------------------------
#---------------------------------
# line()
#---------------------------------
- id: line
category: function
description: >
Draws a line between the two points specified by `x1,y1` and
`x2,y2`. A line's color can be set with the `stroke()` function and
its width can be set with the `strokeWidth()` function. A line's cap style
can be changed with the `lineCapMode()` function. Note that line cap modes
only take effect when drawing with the rendering mode set to `smooth()`.
When using `noSmooth()`, lines will be rendered using square end caps.
examples:
- example: |
function draw()
background(128)
stroke(255)
line(10, 10, 80, 80)
end
image: media/line_ex1.png
group: Drawing
name: line( x1, y1, x2, y2 )
parameters:
- description: x-coordinate of the first point
name: x1
- description: y-coordinate of the first point
name: y1
- description: x-coordinate of the second point
name: x2
- description: y-coordinate of the second point
name: y2
related: [lineCapMode, stroke, strokeWidth, smooth, noSmooth]
syntax: line( x1, y1, x2, y2 )
#---------------------------------
#---------------------------------
# image()
#---------------------------------
- id: image
category: type
description: >
This type represents a 2D raster image, pixels can be set with image:set(x,
y, color) and read with image:get(x, y). Images and sub-rectangles can be copied
with image:copy(). Draw images onto the screen using sprite(image,x,y). See
the relevant documentation pages for more details.You can access the width
or the height of an image through its width and height properties.
The `image.premultiplied` flag allows you to specify whether the image was
created with premultiplied alpha. Generally, for images you create yourself
using `image:set()`, you'll want this set to `false` (the default).
For images used with `setContext()` you will want this set to `true`.
Note that using an image with `setContext()` will automatically set its
premultiplied flag to `true`.The constructor can alternatively take
png or jpeg encoded binary data which it will decode and use to construct the
image. Using this will enable premultiplied alpha, and the encoded data is assumed
to be premultiplied.
`image(CAMERA)` can be used to capture the current frame from the camera into a
static image. This is a fairly slow operation and should not be done every frame.
If there is no camera frame available (due to the capture source not being available,
or still being initialized), an image with width and height of 0 is created.
examples:
- example: |
-- Create a 400x400 pixel image
myImage = image(400, 400)
-- Set a pixel
myImage:set(10,10,128,128,128,255)
-- Get a pixel
r,g,b,a = myImage:get(10,10)
- example: |
img = image(CAMERA)
group: Images
name: image
parameters:
- description: CAMERA constant, to copy the frame from the current capture source
name: source
- description: integer, the width of the image in pixels
name: width
- description: integer, the height of the image in pixels
name: height
- description: boolean, tells Codea to render this image as a premultiplied image.
The default is false.
name: premultiplied
- description: string, a sequence of bytes representing the encoded jpeg or png
image data.
name: data
related: [image.get, image.set, image.copy, sprite, setContext, CAMERA]
returns: The newly created image of given width and height
syntax: |
image( width, height )
image.width
image.height
image(data)
image(source)
#---------------------------------
#---------------------------------
# image.get()
#---------------------------------
- id: image.get
category: method
description: This method returns the red, green, blue and alpha components of
the pixel located at x, y in the image.
examples:
- example: |
r,g,b,a = myImage:get( 15, 15 )
r,g,b = myImage:get( 25, 25 )
group: Images
name: image.get( x, y )
parameters:
- description: integer, x location of the pixel to query
name: x
- description: integer, y location of the pixel to query
name: y
related: [image, image.set]
returns: >
Four values: red, green, blue and alpha representing the color of the
pixel at `x`, `y`. The values are in the range 0 to 255.
syntax: image.get( x, y )
#---------------------------------
#---------------------------------
# image.set()
#---------------------------------
- id: image.set
category: method
description: This method sets the red, green, blue and alpha components of the
pixel located at x, y. If no alpha parameter is given, it is assumed to be 255.
examples:
- example: myImage:set( 15, 15, color(20,30,40,255) )
- example: myImage:set( 15, 15, 20, 30, 40, 255)
group: Images
name: image.set( x, y, color )
parameters:
- description: integer, x location of the pixel to query. 1 is the left most column.
Must be less than or equal to the image.width value.
name: x
- description: integer, y location of the pixel to query. 1 is the bottom row.
Must be less than or equal to the image.height value.
name: y
- description: color object, the color to set the pixel to
name: color
- description: integer, the red, green, blue and alpha value to set the pixel
to. Between `0` and `255`.
name: r, g, b, a
related: [image, image.set, color]
syntax: |
image.set( x, y, color )
image.set( x, y, r, g, b, a)
image.set( x, y, r, g, b)
#---------------------------------
#---------------------------------
# image.copy()
#---------------------------------
- id: image.copy
category: method
description: This method will copy the pixels in one image into a new image. If
no parameters are given, it will copy the whole image, otherwise it will copy
the defined subregion. If the region is outside of the image, it will be adjusted
to select a valid region from the image. If the rectangle is completely outside
of the image, an error will occur.
examples:
- example: newImage = myImage:copy()
- example: newImage = myImage:copy(20,40,100,100)
group: Images
name: image.copy( x, y, w, h )
parameters:
- description: integer, x location of the leftmost pixels of the copy region.
name: x
- description: integer, y location of the topmost pixels of the copy region
name: y
- description: positive integer, width in pixels of the copy region
name: width
- description: positive integer, height in pixels of the copy region
name: height
related:
- image
- image.set
returns: The newly created image with a copy of the given image or a subregion
of it.
syntax: |
image:copy()
image:copy(x, y, width, height)
#---------------------------------
#---------------------------------
# translate()
#---------------------------------
- id: translate
category: function
description: Translates all subsequent drawing operations by the specified
`x` and `y` values. Translations are cumulative, so a call to `translate(
50, 0 )` followed by a call to `translate( 10, 10 )` will translate
all subsequent drawing operations by `60, 10`. Translate can take an optional
`z` parameter to specify depth.
group: Transform
name: translate( x, y )
parameters:
- description: amount of horizontal translation, in pixels
name: x
- description: amount of vertical translation, in pixels
name: y
- description: amount of depth translation, in pixels
name: z
related: [rotate, scale, pushMatrix, popMatrix, resetMatrix]
syntax: |
translate( x, y )
translate( x, y, z )
#---------------------------------
#---------------------------------
# assets.key
#---------------------------------
- id: assets.key
category: type
description: This type represents a file (not folder) on your device. Codea creates an object of this type when you specify an asset using the `asset.FileName` syntax in your code
examples:
- example: |
-- Get the Main.lua file as an asset
local mainFile = asset.Main
print(mainFile.name)
print(mainFile.path)
-- Print a description of the asset key
print(mainFile)
group: Assets
name: assets.key
parameters:
- description: string, the name of this file, including its extension
name: name
- description: string, the full path to this file
name: path
- description: string, the file extension for this file
name: ext
- description: the type of this file, can be `SPRITES`, `MODELS`, `SOUNDS`, `MUSIC`, `TEXT`, `SHADERS`
name: type
related: [assets, assetsOverview]
syntax: asset.FileName
#---------------------------------
#---------------------------------
# assets
#---------------------------------
- id: assets
category: type
description: >
This type represents a folder (not file) on your device. Codea creates an object of this type when you specify an asset using the `asset.FolderName` syntax in your code, folders can have nested subfolders and you can specify them by using `.SubFolder` to refer to them (where "SubFolder" is the name of your sub folder)
examples:
- example: |
-- Get the Documents folder as an asset library
local docs = asset.documents
-- Number of files in documents
print(#docs)
-- Path to documents folder
print(docs.path)
-- Get a table with all the contents
local allDocs = docs.all
-- Get notified of updates to documents
asset.documents.updated = function (lib)
print("Docs updated!")
end
-- Create an asset key pointing to a new file
local myFile = docs .. "newFile.txt"
group: Assets
name: assets
parameters:
- description: string, the full path to this folder
name: path
- description: string, the type of this folder (if it represents a bundle type). Can be `PROJECT` or `SHADERS`
name: type
- description: string, the file extension of this folder, will be an empty string unless the folder has a specific extension
name: ext
- description: table, a table with every file and folder in this folder, the table is keyed by file name and the values are either `assets.key` (files) or `assets` (folders)
name: all
- description: >
function, assign a function to this property to be notified when this folder's contents have been modified, your function will be passed one argument which is an `assets` object of the folder being monitored
name: updated
related: [assets.key, assetsOverview]
syntax: asset.FolderName
#---------------------------------
#---------------------------------
# rotate()
#---------------------------------
- category: function
description: >
Specifies an amount of rotation (in degrees) to apply to all subsequent
drawing. All subsequent drawing functions will be rotated by angle value specified
in this function. Rotations are cumulative, so calling `rotate(30)` followed
by `rotate(20)` has the same effect as `rotate(50)`.
`rotate()` can also be called with a specific axis, defined by the `x`, `y`, `z` parameters.
This allows rotation to occur on an arbitrary axis for 3D effects. By default
the axis is (0, 0, 1), this means that objects rotate about the axis pointing
toward the viewer.
group: Transform
id: rotate
name: rotate( angle )
parameters:
- description: amount of rotation in degrees
name: angle
- description: float, x value for the axis of rotation
name: x
- description: float, y value for the axis of rotation
name: y
- description: float, z value for the axis of rotation
name: z
related:
- translate
- scale
- pushMatrix
- popMatrix
syntax: |
rotate( angle )
rotate( angle, x, y, z )
#---------------------------------
#---------------------------------
# scale()
#---------------------------------
- category: function
description: Specifies an amount of scale to apply to all drawing. All subsequent
drawing functions will be scaled by the x and y values specified in this function.
Scale values are specified as a scalar multipliers, for example, scale(2.0,
2.0) will double the `x` and `y` dimensions of subsequent drawing
commands. `scale()` is cumulative, so calling `scale(0.5)` followed
by `scale(0.5)` will scale all subsequent drawing operations by 0.25 (i.e.,
one quarter of their original size).
group: Transform
id: scale
name: scale( x, y )
parameters:
- description: uniform amount of scale to apply horizontally and vertically. Applies
on all axis, x, y and z.
name: amount
- description: amount of scale to apply on the x axis (horizontal)
name: x
- description: amount of scale to apply on the y axis (vertical)
name: y
- description: amount of scale to apply on the z axis (depth)
name: z
related:
- rotate
- translate
- pushMatrix
- popMatrix
syntax: |
scale( amount )
scale( x, y )
scale( x, y, z )
#---------------------------------
#---------------------------------
# zLevel()
#---------------------------------
- category: function
description: >
Sets the z level of future drawing operations. Negative values
mean the drawing will occur behind (further into the screen), positive values
will cause drawing to happen in front. By default all drawing will occur above
previous drawing operations.
This property is pushed onto the matrix stack with `pushMatrix()`.
group: Transform
id: zLevel
name: zLevel( z )
parameters:
- description: float, the amount of depth for future drawing operations, use positive
values to draw in front, and negative values to draw behind.
name: z
related:
- translate
- pushMatrix
- popMatrix
syntax: zLevel( z )
#---------------------------------
#---------------------------------
# perspective()
#---------------------------------
- category: function
description: >
Sets the projection matrix to the perspective projection defined
by the parameters `fov` (field of view, in degrees), `aspect` (aspect
ratio of the screen, defaults to WIDTH/HEIGHT), `near` and `far`.
The near and far values specify the closest and farthest distance an object
can be without being clipped by the view frustum.
When called without
arguments, sets up a perspective projection with a field of view of 45 degrees
and an aspect ratio of WIDTH/HEIGHT.
group: Advanced Transform
id: perspective
name: perspective( fov, aspect, near, far )
parameters:
- description: float, field of view in degrees
name: fov
- description: float, aspect ratio of the screen. Defaults to WIDTH/HEIGHT
name: aspect
- description: float, near clipping plane, defaults to 0.1
name: near
- description: float, far clipping plane, default value is computed based on the
height of the screen
name: far
related:
- projectionMatrix
- ortho
- camera
- matrix
- WIDTH
- HEIGHT
syntax: |
perspective()
perspective( fov )
perspective( fov, aspect )
perspective( fov, aspect, near, far )
#---------------------------------
#---------------------------------
# ortho()
#---------------------------------
- category: function
description: >
Sets the projection matrix to the orthographic projection defined
by the parameters `left`, `right`, `bottom`, `top`, `near`
and `far`. The near and far values specify the closest and farthest distance
an object can be without being clipped by the view frustum.
When called with no arguments, sets up the default orthographic projection, equivalent
to ortho( 0, WIDTH, 0, HEIGHT, -10, 10 ).
group: Advanced Transform
id: ortho
name: ortho( left, right, bottom, top )
parameters:
- description: float, left edge of the frustum
name: left
- description: float, right edge of the frustum
name: right
- description: float, bottom edge of the frustum