Skip to content

Commit fe2727d

Browse files
feat: add block for drawing a circle with a color (#52)
1 parent 92bfe91 commit fe2727d

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/blocks/p5_blocks.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,27 @@ const draw_emoji = {
193193
'previousStatement': null,
194194
'nextStatement': null,
195195
'colour': 230,
196+
'inputsInline': true,
197+
};
198+
199+
const simpleCircle = {
200+
'type': 'simple_circle',
201+
'tooltip': '',
202+
'helpUrl': '',
203+
'message0': 'draw %1 circle %2',
204+
'args0': [
205+
{
206+
'type': 'input_value',
207+
'name': 'COLOR',
208+
},
209+
{
210+
'type': 'input_dummy',
211+
},
212+
],
213+
'previousStatement': null,
214+
'nextStatement': null,
215+
'colour': 230,
216+
'inputsInline': true,
196217
};
197218

198219
// Create the block definitions for all the JSON-only blocks.
@@ -203,6 +224,7 @@ const jsonBlocks = Blockly.common.createBlockDefinitionsFromJsonArray([
203224
fill,
204225
ellipse,
205226
draw_emoji,
227+
simpleCircle,
206228
]);
207229

208230
export const blocks = {

src/blocks/p5_generators.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ forBlock['draw_emoji'] = function (block) {
6868
sketch.text('${dropdown_emoji}', 150, 200);\n`;
6969
return code;
7070
};
71+
72+
forBlock['simple_circle'] = function (block, generator) {
73+
const color = generator.valueToCode(block, 'COLOR', Order.ATOMIC) || `'#fff'`;
74+
const code = `sketch.fill(${color});
75+
sketch.stroke(${color});
76+
sketch.ellipse(150, 150, 50, 50);`;
77+
return code;
78+
};

src/blocks/toolbox.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ export const toolbox = {
4848
kind: 'block',
4949
type: 'draw_emoji',
5050
},
51+
{
52+
kind: 'block',
53+
type: 'simple_circle',
54+
inputs: {
55+
COLOR: {
56+
shadow: {
57+
type: 'colour_picker',
58+
},
59+
},
60+
},
61+
},
5162
{
5263
kind: 'block',
5364
type: 'p5_ellipse',

0 commit comments

Comments
 (0)