Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to add new math angle block #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ardublockly/ardublockly_toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Ardublockly.TOOLBOX_XML =
' <block type="math_arithmetic"></block>' +
' <block type="math_single"></block>' +
' <block type="math_trig"></block>' +
' <block type="math_ang"></block>' +
' <block type="math_constant"></block>' +
' <block type="math_number_property"></block>' +
' <block type="math_change">' +
Expand Down
44 changes: 44 additions & 0 deletions blockly/blocks/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,50 @@ Blockly.Blocks['math_trig'] = {
}
};

Blockly.Blocks['math_ang'] = {
/**
* Block for angle operators.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2",
"args0": [
{
"type": "field_dropdown",
"name": "OP",
"options": [
[Blockly.Msg.MATH_ANG_DEG, 'DEG'],
[Blockly.Msg.MATH_ANG_RAD, 'RAD']
]
},
{
"type": "input_value",
"name": "NUM",
"check": Blockly.Types.DECIMAL.checkList
}
],
"output": Blockly.Types.DECIMAL.output,
"colour": Blockly.Blocks.math.HUE,
"helpUrl": Blockly.Msg.MATH_AND_HELPURL
});
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function() {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'DEG': Blockly.Msg.MATH_ANG_TOOLTIP_DEG,
'RAD': Blockly.Msg.MATH_ANG_TOOLTIP_RAD
};
return TOOLTIPS[mode];
});
},
/** @return {!string} Type of the block, all these operations are floats. */
getBlockType: function() {
return Blockly.Types.DECIMAL;
}
};

Blockly.Blocks['math_constant'] = {
/**
* Block for constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
Expand Down
6 changes: 6 additions & 0 deletions blockly/generators/arduino/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ Blockly.Arduino['math_single'] = function(block) {
case 'TAN':
code = 'tan(' + arg + ' / 180 * Math.PI)';
break;
case 'RAD':
code = 'rad(' + arg + ' / 180 * Math.PI)';
break;
}
if (code) {
return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX];
Expand All @@ -147,6 +150,9 @@ Blockly.Arduino['math_single'] = function(block) {
case 'ATAN':
code = 'atan(' + arg + ') / M_PI * 180';
break;
case 'DEG':
code = 'deg(' + arg + ') / M_PI * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
}
Expand Down