4.1.0 • Published 5 days ago

@blockly/field-bitmap v4.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 days ago

@blockly/field-bitmap Built on Blockly

A Blockly field that allows for user-inputted pixel grids. The image value is stored as a 2D array of 1s and 0s, and supports any size. The user can paint over pixels with their mouse, or randomize the grid.

Note: this field does not support serialization to XML.

Installation

Yarn

yarn add @blockly/field-bitmap

npm

npm install @blockly/field-bitmap --save

Usage

This field accepts up to 6 parameters:

  • "value" to specify an initial value. Must be a 2D rectangular array of 1s and 0s. If not provided, the default is an empty grid of the specified size.
  • "width" to specify an initial width, if there is no initial value. If not provided, the default is a width of 5.
  • "height" to specify an initial height, if there is no initial value. If not provided, the default is a height of 5.
  • fieldHeight" to specify a static field height. If provided, the individual pixels will be resized to fit inside the field. This only affects the field as it is seen on a block and not the pop-up editor. Good for larger images. (Note: If this results in fractional pixel sizes, the overall field height may not exactly match the specified value on all browsers.)
  • "colours" to override the default colours, Default values:
    {filled: '#363d80', empty: '#fff'}
  • "buttons" to show or hide the "Randomize" and/or "Clear" buttons. If either is omitted, the button will be shown. Default values:
    {randomize: true, clear: true}

JavaScript

import * as Blockly from 'blockly';
import {FieldBitmap} from 'blockly-field-bitmap';
Blockly.Blocks["test_field_bitmap"] = {
  init: function () {
    this.appendDummyInput()
      .appendField("bitmap: ")
      .appendField(new FieldBitmap(...), "FIELDNAME");
  }
};

JSON

Example with default value:

import * as Blockly from 'blockly';
import '@blockly/field-bitmap';
Blockly.defineBlocksWithJsonArray([
  {
    type: 'test_field_bitmap',
    message0: 'bitmap: %1',
    args0: [
      {
        type: 'field_bitmap',
        name: 'FIELDNAME',
        value: [
          [0, 0, 0, 0, 0, 0, 0],
          [0, 1, 1, 0, 1, 1, 0],
          [0, 0, 0, 0, 0, 0, 0],
          [0, 1, 1, 1, 1, 1, 0],
          [0, 1, 0, 0, 0, 1, 0],
          [0, 0, 1, 1, 1, 0, 0],
          [0, 0, 0, 0, 0, 0, 0],
        ],
      },
    ],
  },
]);

Example with width and height:

import * as Blockly from 'blockly';
import '@blockly/field-bitmap';
Blockly.defineBlocksWithJsonArray([
  {
    type: 'test_field_bitmap',
    message0: 'bitmap: %1',
    args0: [
      {
        type: 'field_bitmap',
        name: 'FIELDNAME',
        width: 8,
        height: 8,
      },
    ],
  },
]);

License

Apache 2.0

4.1.0

5 days ago

4.0.18

12 days ago

4.0.17

26 days ago

4.0.16

1 month ago

4.0.15

2 months ago

4.0.14

2 months ago

4.0.13

3 months ago

4.0.12

3 months ago

4.0.11

5 months ago

4.0.10

6 months ago

4.0.9

6 months ago

4.0.8

6 months ago

3.0.1

11 months ago

4.0.5

8 months ago

4.0.4

9 months ago

4.0.7

7 months ago

4.0.6

7 months ago

4.0.1

10 months ago

4.0.0

10 months ago

4.0.3

10 months ago

4.0.2

10 months ago

3.0.0

11 months ago

2.0.19

11 months ago

2.0.16

1 year ago

2.0.17

1 year ago

2.0.18

1 year ago

2.0.15

1 year ago

2.0.13

1 year ago

2.0.14

1 year ago

2.0.11

1 year ago

2.0.12

1 year ago

2.0.9

1 year ago

2.0.10

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.8

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago