2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2014-01-28 03:00:09 -08:00
|
|
|
* @license
|
2013-10-30 14:46:03 -07:00
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2012 Google Inc.
|
2014-10-07 13:09:55 -07:00
|
|
|
* https://developers.google.com/blockly/
|
2013-10-30 14:46:03 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileoverview Colour blocks for Blockly.
|
|
|
|
* @author fraser@google.com (Neil Fraser)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
goog.provide('Blockly.Blocks.colour');
|
|
|
|
|
|
|
|
goog.require('Blockly.Blocks');
|
|
|
|
|
2016-07-07 11:43:20 -04:00
|
|
|
goog.require('Blockly.constants');
|
|
|
|
|
|
|
|
/**
|
2017-10-19 10:31:45 -04:00
|
|
|
* Pick a random colour.
|
2016-10-21 17:38:57 -07:00
|
|
|
* @return {string} #RRGGBB for random colour.
|
2016-07-07 11:43:20 -04:00
|
|
|
*/
|
|
|
|
function randomColour() {
|
2017-10-19 10:31:45 -04:00
|
|
|
var num = Math.floor(Math.random() * Math.pow(2, 24));
|
|
|
|
return '#' + ('00000' + num.toString(16)).substr(-6);
|
2016-07-07 11:43:20 -04:00
|
|
|
}
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
Blockly.Blocks['colour_picker'] = {
|
2014-09-08 14:26:52 -07:00
|
|
|
/**
|
|
|
|
* Block for colour picker.
|
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
2013-10-30 14:46:03 -07:00
|
|
|
init: function() {
|
2015-08-24 01:28:43 -07:00
|
|
|
this.jsonInit({
|
|
|
|
"message0": "%1",
|
|
|
|
"args0": [
|
|
|
|
{
|
2017-09-19 10:13:41 -04:00
|
|
|
"type": "field_colour_slider",
|
2015-08-24 01:28:43 -07:00
|
|
|
"name": "COLOUR",
|
2016-07-07 11:43:20 -04:00
|
|
|
"colour": randomColour()
|
2015-08-24 01:28:43 -07:00
|
|
|
}
|
|
|
|
],
|
2016-07-07 11:43:20 -04:00
|
|
|
"outputShape": Blockly.OUTPUT_SHAPE_ROUND,
|
2016-07-06 21:04:11 -04:00
|
|
|
"output": "Colour"
|
2015-08-24 01:28:43 -07:00
|
|
|
});
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
};
|