Skip to content

Commit 4a25eab

Browse files
authored
Merge pull request #5709 from jesi-rgb/save-gif
Implement `saveGif` as a native p5 function
2 parents fe0f15b + ac29642 commit 4a25eab

File tree

10 files changed

+491
-15
lines changed

10 files changed

+491
-15
lines changed

Gruntfile.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module.exports = grunt => {
150150
source: {
151151
options: {
152152
parserOptions: {
153-
ecmaVersion: 5
153+
ecmaVersion: 8
154154
}
155155
},
156156
src: ['src/**/*.js']
@@ -163,7 +163,7 @@ module.exports = grunt => {
163163
'eslint-samples': {
164164
options: {
165165
parserOptions: {
166-
ecmaVersion: 6
166+
ecmaVersion: 8
167167
},
168168
format: 'unix'
169169
},
@@ -259,6 +259,16 @@ module.exports = grunt => {
259259
}
260260
}
261261
},
262+
babel: {
263+
options: {
264+
presets: ['@babel/preset-env']
265+
},
266+
dist: {
267+
files: {
268+
'lib/p5.pre-min.js': 'lib/p5.js'
269+
}
270+
}
271+
},
262272

263273
// This minifies the javascript into a single file and adds a banner to the
264274
// front of the file.
@@ -274,8 +284,8 @@ module.exports = grunt => {
274284
},
275285
dist: {
276286
files: {
277-
'lib/p5.min.js': 'lib/p5.pre-min.js',
278-
'lib/modules/p5Custom.min.js': 'lib/modules/p5Custom.pre-min.js'
287+
'lib/p5.min.js': ['lib/p5.pre-min.js'],
288+
'lib/modules/p5Custom.min.js': ['lib/modules/p5Custom.pre-min.js']
279289
}
280290
}
281291
},
@@ -523,10 +533,14 @@ module.exports = grunt => {
523533
grunt.loadNpmTasks('grunt-contrib-clean');
524534
grunt.loadNpmTasks('grunt-simple-nyc');
525535

536+
//this library converts the ES6 JS to ES5 so it can be properly minified
537+
grunt.loadNpmTasks('grunt-babel');
538+
526539
// Create the multitasks.
527540
grunt.registerTask('build', [
528541
'browserify',
529542
'browserify:min',
543+
'babel',
530544
'uglify',
531545
'browserify:test'
532546
]);

lib/empty-example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.html
2+
*.js

lib/empty-example/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
body {
1010
padding: 0;
1111
margin: 0;
12+
background-color: #1b1b1b;
1213
}
1314
</style>
14-
<script src="../p5.js"></script>
15+
<script src="../p5.min.js"></script>
1516
<!-- <script src="../addons/p5.sound.js"></script> -->
1617
<script src="sketch.js"></script>
1718
</head>

lib/empty-example/sketch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ function setup() {
44

55
function draw() {
66
// put drawing code here
7-
}
7+
}

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"grunt-mocha-test": "^0.13.3",
6868
"grunt-newer": "^1.1.0",
6969
"grunt-simple-nyc": "^3.0.1",
70+
"grunt-babel": "^8.0.0",
7071
"html-entities": "^1.3.1",
7172
"husky": "^4.2.3",
7273
"i18next": "^19.0.2",
@@ -85,7 +86,8 @@
8586
"regenerator-runtime": "^0.13.3",
8687
"request": "^2.88.0",
8788
"simple-git": "^3.3.0",
88-
"whatwg-fetch": "^2.0.4"
89+
"whatwg-fetch": "^2.0.4",
90+
"gifenc": "^1.0.3"
8991
},
9092
"license": "LGPL-2.1",
9193
"main": "./lib/p5.min.js",
@@ -154,7 +156,6 @@
154156
"not dead"
155157
],
156158
"author": "",
157-
"dependencies": {},
158159
"husky": {
159160
"hooks": {
160161
"pre-commit": "lint-staged"

src/image/image.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ p5.prototype.saveCanvas = function() {
184184
}, mimeType);
185185
};
186186

187-
p5.prototype.saveGif = function(pImg, filename) {
187+
// this is the old saveGif, left here for compatibility purposes
188+
// the only place I found it being used was on image/p5.Image.js, on the
189+
// save function. that has been changed to use this function.
190+
p5.prototype.encodeAndDownloadGif = function(pImg, filename) {
188191
const props = pImg.gifProperties;
189192

190193
//convert loopLimit back into Netscape Block formatting

0 commit comments

Comments
 (0)