You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dist/es/learn/coordinate-system-and-shapes.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -191,7 +191,7 @@ <h2>Formas Primitivas</h2>
191
191
}
192
192
</script>
193
193
194
-
<p>Una vez que nos hemos familiarizado con el concepto de dibujar un rectángulo, una <ahref="/reference/#/p5/ellipse">ellipse()</a> es muy sencilla de dibujar. De hecho es idéntica al <ahref="/reference/#/p5/rect">rect()</a>> con la diferencia de que la elipse se dibuja donde la caja que contiene al rectángulo debiera estar. El modo por defecto para la <ahref="/reference/#/p5/ellipse">ellipse()</a> es <ahref="/reference/#/p5/CENTER">CENTER</a>, en vez de <ahref="/reference/#/p5/CORNER">CORNER</a>.</p>
194
+
<p>Una vez que nos hemos familiarizado con el concepto de dibujar un rectángulo, una <ahref="/reference/#/p5/ellipse">ellipse()</a> es muy sencilla de dibujar. De hecho es idéntica al <ahref="/reference/#/p5/rect">rect()</a> con la diferencia de que la elipse se dibuja donde la caja que contiene al rectángulo debiera estar. El modo por defecto para la <ahref="/reference/#/p5/ellipse">ellipse()</a> es <ahref="/reference/#/p5/CENTER">CENTER</a>, en vez de <ahref="/reference/#/p5/CORNER">CORNER</a>.</p>
Copy file name to clipboardExpand all lines: dist/es/learn/tdd.html
+44-35Lines changed: 44 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -212,9 +212,9 @@ <h2>A sketch without tests</h2>
212
212
// fillColor will be the color of the rectangle.
213
213
// colorIncreaser will become an instance of our ColorIncreaser class.
214
214
215
-
var colorValueIncrease = 1;
216
-
var fillColor
217
-
var colorIncreaser
215
+
let colorValueIncrease = 1;
216
+
let fillColor;
217
+
let colorIncreaser;
218
218
219
219
function setup() {
220
220
createCanvas(500, 500);
@@ -249,7 +249,7 @@ <h2>A sketch without tests</h2>
249
249
</xmp></code></pre>
250
250
</li>
251
251
<li>
252
-
Open the index.html file in your browser (you don’t need to run a local server in this case). You should see a black box become red and then black again. This is the basis of looping over all the RGB colors. The problem you face is that there are 256 values for red, green, and blue, which means there are over 16 million combinations of colors! You can make this faster. However, making this faster will cause flashing lights which might give some people headaches or seizures. Please only increase this value if you do not have issues with flashing lights. The rest of the tutorial should be fine. In the sketch.js file change the<pre><codeclass="language-javascript"><xmp>var colorValueIncrease = 33;</xmp></code></pre> and reload the page. However this still doesn’t guarantee this is working properly. You don’t have time to watch all the colors change nor can you tell yourself if it is iterating through the millions of colors. Change the colorValueIncrease variable back to 1 before you move on.
252
+
Open the index.html file in your browser (you don’t need to run a local server in this case). You should see a black box become red and then black again. This is the basis of looping over all the RGB colors. The problem you face is that there are 256 values for red, green, and blue, which means there are over 16 million combinations of colors! You can make this faster. However, making this faster will cause flashing lights which might give some people headaches or seizures. Please only increase this value if you do not have issues with flashing lights. The rest of the tutorial should be fine. In the sketch.js file change the<pre><codeclass="language-javascript"><xmp>let colorValueIncrease = 33;</xmp></code></pre> and reload the page. However this still doesn’t guarantee this is working properly. You don’t have time to watch all the colors change nor can you tell yourself if it is iterating through the millions of colors. Change the colorValueIncrease variable back to 1 before you move on.
253
253
</li>
254
254
<li>
255
255
At 30 draw loops per second it would take over six days to loop through all of the colors. You certainly don’t have time to do that once, and would never be able to check and see if it worked every time you updated our code. What if you accidentally change something in our draw loop that breaks the code right before install? You wouldn’t know until it was live and everyone saw your sketch break.
@@ -264,13 +264,14 @@ <h2>Your first unit tests</h2>
264
264
<p>
265
265
In the folder called color_unit_test that you already created, make a new folder called test. Open the test folder and make a file called test.js. Type this code into test.js
266
266
<pre><codeclass="language-javascript"><xmp>
267
+
'use strict';
267
268
// Import the expect library. This is what allows us to check our code.
268
269
// You can check out the full documentation at http://chaijs.com/api/bdd/
269
-
var expect = require('chai').expect;
270
+
const expect = require('chai').expect;
270
271
271
272
272
273
// Create the variable you are going to test
273
-
var p5js = 'awesome';
274
+
let p5js = 'awesome';
274
275
275
276
276
277
// describe lets you comment on what this block of code is for.
@@ -309,11 +310,11 @@ <h2>Your first unit tests</h2>
309
310
</p>
310
311
<p>
311
312
Let's look at what happens when tests fail. Change line 6 in test.js from:
Go to the bottom of your sketch.js file, below the closing bracket } for the draw function, and add this:
388
391
<pre><codeclass="language-javascript">
389
-
function ColorIncreaser() {
390
-
// Stores a value and a color and allows you to increase the color
391
-
// by that value.
392
+
class ColorIncreaser {
393
+
constructor() {
394
+
// Stores a value and a color and allows you to increase the color
395
+
// by that value.
396
+
}
392
397
}
393
398
394
-
module.exports.ColorIncreaser = ColorIncreaser;
399
+
module.exports = ColorIncreaser;
395
400
</code></pre>
396
401
</p>
397
402
<p>
398
-
Save sketch.js. The function line will be our color increasing object. The module.export line is what allows our test.js file to import our ColorIncreaser with the line you already added that looks like this:
403
+
Save sketch.js. The function line will be our color increasing object. The module.exports line is what allows our test.js file to import our ColorIncreaser with the line you already added that looks like this:
399
404
<pre><codeclass="language-javascript">
400
-
var ColorIncreaser = require('../sketch').ColorIncreaser;
Now get your ColorIncreaser function to actually do something. Start by storing the colorValueIncrease as a variable in your class. Before you change the code in sketch.js you have to write your tests. Change the beforeEach function in test.js to look like this
407
412
<pre><codeclass="language-javascript">
408
413
beforeEach(function() {
409
-
var colorValueIncrease = 1;
414
+
let colorValueIncrease = 1;
410
415
colorIncreaser = new ColorIncreaser(colorValueIncrease);
and change the ColorIncreaser function to look like this
431
436
<pre><codeclass="language-javascript">
432
-
function ColorIncreaser(colorValueIncrease) {
433
-
// Stores a value and a color and allows you to increase the color
434
-
// by that value.
435
-
this.colorValueIncrease = colorValueIncrease
437
+
class ColorIncreaser() {
438
+
constructor(colorValueIncrease) {
439
+
// Stores a value and a color and allows you to increase the color
440
+
// by that value.
441
+
this.colorValueIncrease = colorValueIncrease
442
+
}
436
443
}
437
444
</code></pre>
438
445
Let’s run the mocha test again. It should pass!
@@ -443,7 +450,7 @@ <h2>Testing when your object is composed of other objects</h2>
443
450
Now you need to add an instance of the p5 color class to our ColorIncreaser. However, for your tests, you don’t want to use an actual instance of the color() class because you don’t want to test external dependencies given by another library.You just want to make sure that your increment function works. So you are going to create what is called a mock of the p5 color class so you can test without worrying about the implementation of code you didn’t write.
444
451
</p>
445
452
<p>
446
-
The original way of incrementing colors just used the color.levels and changed the red, green and blue values at index [0], [1], and [2]. You can see this in the draw function in sketch.js. The implementation of color just stores those values in a javascript array so you can mock it out very easily. Put this code in test.js below the var ColorIncreaser = require… line and above the describe line
453
+
The original way of incrementing colors just used the color.levels and changed the red, green and blue values at index [0], [1], and [2]. You can see this in the draw function in sketch.js. The implementation of color just stores those values in a javascript array so you can mock it out very easily. Put this code in test.js below the const ColorIncreaser = require… line and above the describe line
447
454
<pre><codeclass="language-javascript">
448
455
function mockColor(red, green, blue, alpha) {
449
456
// Mock of the color class from p5
@@ -459,8 +466,8 @@ <h2>Testing when your object is composed of other objects</h2>
459
466
Update your beforeEach() function
460
467
<pre><codeclass="language-javascript">
461
468
beforeEach(function() {
462
-
var colorValueIncrease = 1;
463
-
var fillColor = new mockColor(0, 0, 0, 255);
469
+
let colorValueIncrease = 1;
470
+
let fillColor = new mockColor(0, 0, 0, 255);
464
471
colorIncreaser = new ColorIncreaser(colorValueIncrease, fillColor);
465
472
});
466
473
</code></pre>
@@ -488,11 +495,13 @@ <h2>Testing when your object is composed of other objects</h2>
488
495
<p>
489
496
and update the ColorValueIncreaser function
490
497
<pre><codeclass="language-javascript">
491
-
function ColorIncreaser(colorValueIncrease, fillColor) {
492
-
// Stores a value and a color and allows you to increase the color
493
-
// by that value.
494
-
this.colorValueIncrease = colorValueIncrease
495
-
this.fillColor = fillColor;
498
+
class ColorIncreaser {
499
+
constructor(colorValueIncrease, fillColor) {
500
+
// Stores a value and a color and allows you to increase the color
501
+
// by that value.
502
+
this.colorValueIncrease = colorValueIncrease
503
+
this.fillColor = fillColor;
504
+
}
496
505
}
497
506
</code></pre>
498
507
</p>
@@ -512,7 +521,7 @@ <h2>Testing class methods</h2>
512
521
<pre><codeclass="language-javascript">
513
522
it('should have rgb values 255, 0, 0 after calling increaseFillColor 255 times', function(done) {
514
523
//it is 256^1 - 1 because it starts with the color black
@@ -547,9 +556,9 @@ <h2>Testing class methods</h2>
547
556
</code></pre>
548
557
</p>
549
558
<p>
550
-
And when you run mocha the tests will fail because that function does not exist! Let’s add a skeleton function in sketch.js between your ColorIncreaserFunction and your module export
559
+
And when you run mocha the tests will fail because that function does not exist! Let’s add a skeleton function in sketch.js inside the ColorIncreaser class below the constructor function.
// increase the first color channel by one. If that channel
554
563
// is now > 255 then increment the next color channel. Repeat for second
555
564
// and third channel
@@ -559,7 +568,7 @@ <h2>Testing class methods</h2>
559
568
<p>
560
569
Save sketch.js. Now when you run mocha the tests fail for a different reason. It finds the function, but it doesn’t do what you expect it to. Let’s change the function in sketch.js to look like what is inside the draw function.
Copy file name to clipboardExpand all lines: dist/learn/coordinate-system-and-shapes.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -191,7 +191,7 @@ <h2>Simple Shapes</h2>
191
191
}
192
192
</script>
193
193
194
-
<p>Once we have become comfortable with the concept of drawing a rectangle, an <ahref="/reference/#/p5/ellipse">ellipse()</a> is a snap. In fact, it is identical to <ahref="/reference/#/p5/rect">rect()</a>> with the difference being that an ellipse is drawn where the bounding box of the rectangle would be. The default mode for <ahref="/reference/#/p5/ellipse">ellipse()</a> is <ahref="/reference/#/p5/CENTER">CENTER</a>, rather than <ahref="/reference/#/p5/CORNER">CORNER</a>.</p>
194
+
<p>Once we have become comfortable with the concept of drawing a rectangle, an <ahref="/reference/#/p5/ellipse">ellipse()</a> is a snap. In fact, it is identical to <ahref="/reference/#/p5/rect">rect()</a> with the difference being that an ellipse is drawn where the bounding box of the rectangle would be. The default mode for <ahref="/reference/#/p5/ellipse">ellipse()</a> is <ahref="/reference/#/p5/CENTER">CENTER</a>, rather than <ahref="/reference/#/p5/CORNER">CORNER</a>.</p>
0 commit comments