soiz1 commited on
Commit
e2a1935
·
verified ·
1 Parent(s): 9aca793

Update src/containers/custom-procedures.jsx

Browse files
src/containers/custom-procedures.jsx CHANGED
@@ -5,31 +5,14 @@ import React from 'react';
5
  import CustomProceduresComponent from '../components/custom-procedures/custom-procedures.jsx';
6
  import LazyScratchBlocks from '../lib/tw-lazy-scratch-blocks';
7
  import {connect} from 'react-redux';
8
- import Color from './custom-procedures-util/color.js';
9
 
10
- function createHeavyColorFromHex(hex, percentage) {
11
- const rgb = Color.hexToRgb(hex);
12
- const hsv = Color.rgbToHsv(rgb);
13
 
14
- if (hsv.v > 0.6) {
15
- // so that pure white can still get color change
16
- hsv.v -= percentage / 2;
17
- }
18
- // only white-black have this property
19
- // so we can avoid adding red to them
20
- if (!(hsv.h === 0 && hsv.s === 0)) {
21
- hsv.s += percentage * hsv.v;
22
- }
23
-
24
- // make sure values arent invalid
25
- if (hsv.v > 1) hsv.v = 1;
26
- if (hsv.v < 0) hsv.v = 0;
27
-
28
- if (hsv.s > 1) hsv.s = 1;
29
- if (hsv.s < 0) hsv.s = 0;
30
-
31
- const newRgb = Color.hsvToRgb(hsv);
32
- return Color.rgbToHex(newRgb);
33
  }
34
 
35
  class CustomProcedures extends React.Component {
@@ -74,7 +57,7 @@ class CustomProcedures extends React.Component {
74
  );
75
 
76
  // @todo This is a hack to make there be no toolbox.
77
- const ScratchBlocks = LazyScratchBlocks.get();
78
  const oldDefaultToolbox = ScratchBlocks.Blocks.defaultToolbox;
79
  ScratchBlocks.Blocks.defaultToolbox = null;
80
  this.workspace = ScratchBlocks.inject(this.blocks, workspaceConfig);
@@ -216,8 +199,8 @@ class CustomProcedures extends React.Component {
216
  const newColor = element.target.value;
217
  this.mutationRoot.setColor(
218
  newColor,
219
- createHeavyColorFromHex(newColor, 0.15),
220
- createHeavyColorFromHex(newColor, 0.25)
221
  );
222
  this.setState({blockColor: newColor});
223
  }
 
5
  import CustomProceduresComponent from '../components/custom-procedures/custom-procedures.jsx';
6
  import LazyScratchBlocks from '../lib/tw-lazy-scratch-blocks';
7
  import {connect} from 'react-redux';
 
8
 
9
+ let ScratchBlocks; // defined later
 
 
10
 
11
+ function darkenColor(hex, amt) {
12
+ const Color = ScratchBlocks.goog.color;
13
+ return Color.rgbArrayToHex(Color.darken(
14
+ Color.hexToRgb(hex), amt
15
+ ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
18
  class CustomProcedures extends React.Component {
 
57
  );
58
 
59
  // @todo This is a hack to make there be no toolbox.
60
+ ScratchBlocks = LazyScratchBlocks.get();
61
  const oldDefaultToolbox = ScratchBlocks.Blocks.defaultToolbox;
62
  ScratchBlocks.Blocks.defaultToolbox = null;
63
  this.workspace = ScratchBlocks.inject(this.blocks, workspaceConfig);
 
199
  const newColor = element.target.value;
200
  this.mutationRoot.setColor(
201
  newColor,
202
+ darkenColor(newColor, 0.1),
203
+ darkenColor(newColor, 0.2)
204
  );
205
  this.setState({blockColor: newColor});
206
  }