Skip to content

Commit 92bfe91

Browse files
feat: add draw_emoji block (#51)
1 parent 5e27797 commit 92bfe91

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/blocks/p5_blocks.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,39 @@ const ellipse = {
170170
'helpUrl': 'https://p5js.org/reference/#/p5/ellipse',
171171
};
172172

173+
const draw_emoji = {
174+
'type': 'draw_emoji',
175+
'tooltip': '',
176+
'helpUrl': '',
177+
'message0': 'draw %1 %2',
178+
'args0': [
179+
{
180+
'type': 'field_dropdown',
181+
'name': 'emoji',
182+
'options': [
183+
['❤️', '❤️'],
184+
['✨', '✨'],
185+
['🐻', '🐻'],
186+
],
187+
},
188+
{
189+
'type': 'input_dummy',
190+
'name': '',
191+
},
192+
],
193+
'previousStatement': null,
194+
'nextStatement': null,
195+
'colour': 230,
196+
};
197+
173198
// Create the block definitions for all the JSON-only blocks.
174199
// This does not register their definitions with Blockly.
175200
const jsonBlocks = Blockly.common.createBlockDefinitionsFromJsonArray([
176201
background,
177202
stroke,
178203
fill,
179204
ellipse,
205+
draw_emoji,
180206
]);
181207

182208
export const blocks = {

src/blocks/p5_generators.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ forBlock['p5_ellipse'] = function (block, generator) {
6161
const height = generator.valueToCode(block, 'HEIGHT', Order.NONE) || 0;
6262
return `sketch.ellipse(${x}, ${y}, ${width}, ${height});\n`;
6363
};
64+
65+
forBlock['draw_emoji'] = function (block) {
66+
const dropdown_emoji = block.getFieldValue('emoji');
67+
const code = `sketch.textSize(100);
68+
sketch.text('${dropdown_emoji}', 150, 200);\n`;
69+
return code;
70+
};

src/blocks/toolbox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export const toolbox = {
4444
kind: 'block',
4545
type: 'colour_random',
4646
},
47+
{
48+
kind: 'block',
49+
type: 'draw_emoji',
50+
},
4751
{
4852
kind: 'block',
4953
type: 'p5_ellipse',

0 commit comments

Comments
 (0)