My first major contribution - Shapes for Blockly

768 views
Skip to first unread message

Jim Brown

unread,
Aug 25, 2013, 4:41:32 PM8/25/13
to blo...@googlegroups.com
Hi Blockly team,

I have created a new blockly contribution called Shapes. Its a more or less a rework of the Turtle code.
This is my first attempt at creating a new set of blocks so any feedback will be appreciated. See attached source code.



I have tried to keep the number of blocks to a minimum yet still allowing enough drawing power. What is here so far:

  • Move To - Move the drawing point to x/y
  • Draw Line To - Draw a line from the current point to x/y
  • Draw Rectangle - Draw a rectangle (filled/unfilled)
  • Draw Circle - Draw a circle (filled/unfilled)
  • Begin / End polygon drawing blocks. Draws polygons as constructed by Draw Line To blocks placed between these blocks
  • Draw Text - Draws text at the current drawing point
  • Set Stroke Width - Sets the width of lines (applies to unfilled polygons too), unfilled rects, and unfilled circles
  • Fill Mode - Sets whether or not rectangles, circles, or polygons are filled.
  • Set Stroke Colour - Sets the color for lines (plus unfilled polygons), unfilled rects, and unfilled circles
  • Set Fill ColourSets the color for filled rects, filled circles, and filled polygons. Also sets the text colour (currently filled text only available)
  • Hide / Show Crosshairs - Hide or show the drawing cursor
STILL TO DO:
 Gradient fills.
 Rotated text
 Outline text

  Other ideas team?
  
Regards, Jim


blockly_shapes.zip

Ellen Spertus

unread,
Aug 26, 2013, 12:25:12 PM8/26/13
to blo...@googlegroups.com
Wow!

How about a command to set the background color?  How about ones to get the current X and Y coordinates?

Ellen


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jim Brown

unread,
Aug 26, 2013, 3:36:42 PM8/26/13
to blo...@googlegroups.com
Hi Ellen

The background colour changing is now in. This is performed by an eraseBackground block which clears the background using the current fill colour.

However, for the 'get x/y coords' I am a bit stumped on how to RETURN the Shapes x or y value
I have coded in the block and trying to 'return' Shape.x or Shape.y (which hold the cursor coords) but I am getting a recurring error.

My block.js code section for the cursor x/y position block  is:

Blockly.Language.draw_getcursorpos = {
  // Block for getting the cursors x or y position
  helpUrl: '',
  init: function() {
    this.setColour(160);
    this.appendDummyInput()    
        .appendTitle(new Blockly.FieldDropdown(this.STATE), 'POS');
    this.setOutput(true, "Number");
    this.setTooltip(BlocklyApps.getMsg('Shape_cursorPosTooltip'));
  }
};

Blockly.Language.draw_getcursorpos.STATE =
    [[BlocklyApps.getMsg('Shape_getCursorXPos'), 'getCursorXPos'],
     [BlocklyApps.getMsg('Shape_getCursorYPos'), 'getCursorYPos']];

Blockly.JavaScript.draw_getcursorpos = function() {
  // Generate JavaScript for returning the cursor x or y pos
  return 'Shape.' + this.getTitleValue('POS') +
      '(\'block_id_' + this.id + '\')';
};


It appears to generate the code accordingly. I want it to call one of the following JavaScript calls within the shape.js:

Shape.getCursorXPos = function(id) {
   return Shape.x;
};

Shape.getCursorYPos = function(id) {
   return Shape.y;
};

However, the error message I am seeing in the browser console window is:
Uncaught Expecting tuple from value block "draw_getcursorpos"


Any pointers or help will be appreciated.

regards, Jim

======================================

Neil Fraser

unread,
Aug 28, 2013, 12:22:49 AM8/28/13
to blo...@googlegroups.com
Would it be better if begin/end polygon drawing were an enclosing block with the drawing commands nested inside it?

Jim Brown

unread,
Aug 28, 2013, 4:10:15 AM8/28/13
to blo...@googlegroups.com, ro...@neil.fraser.name
Hi Neil

Definitely agree. I am not sure how to code that in though.Can you point me in the right direction?
I want allow onlythe 'draw line to ..' as a connecting block too.

Regards, Jim
Reply all
Reply to author
Forward
0 new messages