Name
PenArrayToBrush -- convert pen array to palette brush (V9.0)
Synopsis
[id] = PenArrayToBrush(id, table, width, height[, t])
Function
This command creates a new palette brush from the array of pens specified in table. The table can be seen as a matrix containing height number of rows where each row has width number of elements, stored sequentially. The order of the pen data in this table must be as follows: Row after row in top-down format, i.e. the table starts with the first row of pens. Each row must contain exactly width number of pens, and there must be exactly height number of rows. The table must be one-dimensional, i.e. it mustn't use subtables for the individual rows but just store the pen values sequentially.

The palette that the pens should use can be set in the optional table argument t. The following table elements are currently recognized:

Palette:
Set this to the id of a palette that has been created by CreatePalette(), LoadPalette() or the @PALETTE preprocessor command. If you don't set this tag, Hollywood will use a default palette that has all colors initialized to black.

TransparentPen:
This tag can be used to specify a pen that should appear transparent. If no pen should be made transparent, set this tag to #NOPEN, which is also the default.

Please note that the table that you pass to this function will usually eat lots of memory. Thus, you should set this table to Nil as soon as you no longer need it. Otherwise you will waste huge amounts of memory and it could even happen that your script runs out of memory altogether. So please keep in mind that you should always set pixel array tables to Nil as soon as you are done with them.

To convert a palette brush to a pen array, you can use the BrushToPenArray() function. See BrushToPenArray for details.

Inputs
id
identifier for the new palette brush or Nil for auto id selection
table
table containing an array of pens that describe the contents of the new brush
width
number of elements in each row
height
number of rows in table
t
optional: table containing further options (see above)
Results
id
optional: identifier of the new palette brush; will only be returned when you pass Nil as argument 1 (see above)
Example
pixels = {}
For Local y = 0 To 479
   For Local x = 0 To 639 Do pixels[y * 640 + x] = y \ 2
Next

PenArrayToBrush(1, pixels, 640, 480, {Palette = #PALETTE_AGA})
pixels = Nil    ; IMPORTANT: free memory!
DisplayBrush(1, 0, 0)
The code above creates a palette brush that contains the first 240 pens from the default palette #PALETTE_AGA. Each palette pen uses two rows. Important: Do not forget to set the pixel array to Nil when you no longer need it because otherwise it will stay in memory and pixel arrays will eat huge amounts of memory!

Show TOC