Skip to content

Commit adbdc7f

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents f611164 + 238d462 commit adbdc7f

File tree

5 files changed

+216
-1
lines changed

5 files changed

+216
-1
lines changed
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
1-
This folder contains wrapup reports for projects from Google Summer of Code, Processing Fellowships, and others.
1+
This folder contains wrapup reports for projects from p5.js related [Google Summer of Code](https://summerofcode.withgoogle.com/organizations/4915113891463168/) projects, [Processing Fellowships](https://processingfoundation.org/fellowships), and others.
2+
3+
4+
*Note for contributors: Embedded images and media are welcome. Please host these files externally rather than placing in this repo to avoid adding growing the repository filesize too much.*
5+
6+
7+
8+
### Processing Foundation Fellowships 2018
9+
* [A p5.js Dissection Manual](https://medium.com/processing-foundation/a-p5-js-dissection-manual-38959ff8522e) by Vijith Assar, 2018
10+
* [Chinese Translation for p5.js and preparing a future of more translations](https://medium.com/processing-foundation/chinese-translation-for-p5-js-and-preparing-a-future-of-more-translations-b56843ea096e), [p5.js 的中文翻译 — 为支持更多种语言翻译做准备](https://medium.com/processing-foundation/p5-js-%E7%9A%84%E4%B8%AD%E6%96%87%E7%BF%BB%E8%AF%91-%E4%B8%BA%E6%94%AF%E6%8C%81%E6%9B%B4%E5%A4%9A%E7%A7%8D%E8%AF%AD%E8%A8%80%E7%BF%BB%E8%AF%91%E5%81%9A%E5%87%86%E5%A4%87-a0fa94da770f) by Kenneth Lim, 2018
11+
* [Making p5.js Accessible](https://medium.com/processing-foundation/making-p5-js-accessible-e2ce366e05a0) by Luis Morales-Navarro and Mathura Govindarajan, 2018
12+
* [Introducing the 2018 Processing Foundation Fellows](https://medium.com/processing-foundation/introducing-the-2018-processing-foundation-fellows-a16ae4e87f80)
13+
14+
### Google Summer of Code 2018
215

316
* [A Platform for Algorithmic Composition on p5.js-sound](https://github.com/processing/p5.js/blob/master/developer_docs/project_wrapups/junshern_gsoc_2018.md) by Chan Jun Shern, 2018
417
* [New JavaScript console in p5.js web editor](https://github.com/processing/p5.js/blob/master/developer_docs/project_wrapups/liang_gsoc_2018.md) by Liang Tang, 2018
518
* [Updates to WebGL Mode](https://github.com/processing/p5.js/blob/master/developer_docs/project_wrapups/aidannelson_gsoc_2018.md) by Aidan Nelson, 2018
19+
* [Implementing missing primitives in p5.js WebGL mode](https://github.com/processing/p5.js/blob/master/developer_docs/project_wrapups/adilrabbani_gsoc_2018.md) by Adil Rabbani, 2018
20+
21+
### Processing Foundation Fellowships 2017
22+
* [p5 Accessibility](https://medium.com/processing-foundation/p5-accessibility-115d84535fa8) by Claire Kearney-Volpe, 2017
23+
* [A p5.js Web Editor for All](https://medium.com/processing-foundation/a-p5-js-web-editor-for-all-64aaa3f9d767) by Cassie Tarakajian, 2017
24+
* [Community and Code](https://medium.com/processing-foundation/community-and-code-882b00e6ee32) by Saskia Freeke, 2017
25+
* [¡Manos a la obra! Empecemos. (Creative Coding in p5.js)](https://medium.com/processing-foundation/manos-a-la-obra-empecemos-creative-coding-in-p5-js-a2bfe3e059ce) by DIY Girls, Sylvia Aguiñaga (Director of Curriculum) and Vanessa Landes (Program Leader), 2017
26+
* [Features and Fixes in the p5.js Editor](https://medium.com/processing-foundation/features-and-fixes-in-the-p5-js-editor-722e4b56495e) by Andrew Nicolaou, 2017
27+
* [Everyone Can Code: A creative coding curriculum for students with low computer literacy](https://medium.com/processing-foundation/anyone-can-code-a-creative-coding-curriculum-for-students-with-low-computer-literacy-69e121149abc) by Niklas Peters, 2017
28+
* [Creative Coding with p5.js for Prisons in Washington State](https://medium.com/processing-foundation/creative-coding-with-p5-js-for-prisons-in-washington-state-3bd1d342d769) by Susan Evans, 2017
29+
* [Announcing our 2017 Processing Foundation Fellows](https://medium.com/processing-foundation/announcing-our-2017-processing-foundation-fellows-8b9e7c8bd2f)
30+
31+
### Google Summer of Code 2017 ([archive](https://summerofcode.withgoogle.com/archive/2017/organizations/5256745899261952/))
32+
33+
* [Processing Foundation: GSOC Grand Wrap-Up Post](https://medium.com/processing-foundation/2017-google-summer-of-code-grand-wrap-up-post-16680b1438db)
634
* [Improving Developer Operations](https://github.com/processing/p5.js/blob/master/developer_docs/project_wrapups/sakshamsaxena_gsoc_2017.md) by Saksham Saxena, 2017
35+
* [Maps, Maps, Maps!](https://medium.com/processing-foundation/maps-maps-maps-f0914218c87b) by Cristobal Valenzuela, 2017
36+
* [Friendly Error System for p5.js](https://medium.com/processing-foundation/2017-marks-the-processing-foundations-sixth-year-participating-in-google-summer-of-code-d365f62fc463) by A. Mira Chung, 2017
37+
* [Processing Foundation: Our Summer of Code Has Begun!](https://medium.com/processing-foundation/our-summer-of-code-has-begun-dffc1bbddb7c)
38+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Implementing missing WebGL primitives
2+
#### by Adil Rabbani ([@adilrabbani](https://github.com/AdilRabbani))
3+
4+
This summer I worked on improving p5.js WebGL mode, along side [Aidan Nelson](https://github.com/AidanNelson) with the help of our mentors [Stalgia Grigg](https://github.com/mlarghydracept)
5+
and [Kate Hollenbach](https://github.com/kjhollen). My tasks for the summer included implementing missing primitives in p5.js WebGL mode i.e arc, point, bezierVertex,
6+
curveVertex, quadraticVertex and text.
7+
8+
## Contribution
9+
10+
My first contribution to p5.js was when I was writing my GSOC proposal. This was just a minor change in [reference examples](https://github.com/processing/p5.js/pull/2737) for curves
11+
and some examples for [vertex()](https://github.com/processing/p5.js/pull/2798). These small changes helped me in understanding the use of grunt, lint, and other node modules being
12+
used in the build process. I was really happy (and surprised) when my proposal got accepted 😄. I was about to contribute to one of my favourite libraries. We had a shared branch on
13+
[git](https://github.com/processing/p5.js/tree/webgl-gsoc-2018) where we would compare our pull requests to be merged.
14+
15+
### arc
16+
17+
I started by going through [manual examples](https://github.com/processing/p5.js/tree/master/test/manual-test-examples/webgl), debugging them in browser and watching the code jump from
18+
function to function. I have to admit though, it was a little daunting at first. My first task was to implement arc for WebGL mode and so I decided to go through already implemented ellipse
19+
and debugging it in the chrome editor.
20+
21+
The code started to make sense after a while and I started to make small changes so as to move forward in implementing arc. Before my first evaluation I was able to implement arc [#2942](https://github.com/processing/p5.js/pull/2942) with all three modes
22+
(OPEN, PIE, CHORD) and add documentation and [test examples](https://github.com/processing/p5.js/tree/webgl-gsoc-2018/test/manual-test-examples/webgl/arc). Ellipse was now refactored by using
23+
the same arc implementation. This closed issue [#2181](https://github.com/processing/p5.js/issues/2181).
24+
25+
### point
26+
27+
WebGL by default renders square points. Looking through some resources on web gave me an idea of discarding pixels from a square point further to render a circular point. Adding the shader in p5.js was
28+
relatively simple. But I was stuck on a bug for a while that didn't go off no matter what. Thankfully with the help of my mentor I was able to debug it and come up with a solution.
29+
30+
One small problem was still there though. A good approach on rendering points would be to use the default square point when the size of the point was really small and when it became big enough, it should
31+
render good looking circular points. I posted this issue on Github and [Adam Ferris](https://github.com/aferriss) who have been working on this before, suggested to use his shader which worked the same way
32+
as mentioned. Read the discussion [here](https://github.com/processing/p5.js/issues/3017). Finally, I opened a [pull request](https://github.com/processing/p5.js/pull/3031) for point and added two test examples
33+
for the primitive. This closed issue [#2662](https://github.com/processing/p5.js/issues/2662) and [#2184](https://github.com/processing/p5.js/issues/2184)
34+
35+
### bezierVertex, curveVertex and quadraticVertex
36+
37+
I decided to go for curves next. I went through a great [article](https://pomax.github.io/bezierinfo/) on bezier curves for this task. Reading the article I came to know that a bezier curve can be easily converted
38+
to Catmull Rom Splines so this meant that if I was able to implement bezierVertex, implementing curveVertex was relatively simple (just converting the points). While quadraticVertex can be implemented by changing the formula used to compute
39+
coefficients for curves.
40+
41+
I finally added the required functions and started testing curves. Everything worked quite well, except just one. Filling curves gave weird results. At first, I thought maybe there was something wrong going on in
42+
my code but a further researching revealed that we can't just fill curves with all the intersections and loops without a proper triangulation algorithm. After approval from Kate and Stalgia, I started testing different
43+
triangulation libraries ([Earcut](https://github.com/mapbox/earcut), [Libtess](https://github.com/brendankenny/libtess.js/), [Tess2](https://github.com/diatomic/tess2)). Earcut was the most precise but wasn't giving correct results.
44+
After a quick discussion with Earcut's creator, it was decided that Earcut wasn't a good option for us.
45+
46+
Tess2 wasn't really a good option either. It wasn't giving correct results and was too big in size. Libtess seemed to work really well and this was also because it was based on the same [GLU Tesselator implementation](https://github.com/processing/processing-android/tree/master/core/src/processing/opengl/tess) that was being used in Processing. The only problem with Libtess was that it was quite bigger than Earcut. We contacted [Lauren](https://github.com/lmccart)
47+
if it was okay with integrating this library for the triangulation part. She encouraged us by saying that we can add the library as a node module just as opentype was being used for 2D text in p5.js. After integrating libtess,
48+
I decided to improve the code further for some performance gains. I was able to implement a look up table with the help of which, we wouldn't need to compute coefficients after rendering curve, the first time. This was a huge performance boost from the
49+
previous trivial implementation. All that was left was to submit a [pull request](https://github.com/processing/p5.js/pull/3085) with an [example](https://github.com/processing/p5.js/tree/webgl-gsoc-2018/test/manual-test-examples/webgl/curves) showcasing what you can do with WebGL curves in p5.js. This closed issues [#2185](https://github.com/processing/p5.js/issues/2185), [#2186](https://github.com/processing/p5.js/issues/2186) and [#2187](https://github.com/processing/p5.js/issues/2187).
50+
51+
### text
52+
53+
Now I had one big task left : Implementing text for p5.js WebGL mode. Let me just mention one thing though, "One does not simply implement text in WebGL 😥"
54+
55+
I went through different methods for rendering text in WebGL. At the end I was able to pick 2 methods that looked perfect for rendering text. The first one was [Signed Distance Field Rendering](http://hack.chrons.me/opengl-text-rendering/). The other being a [GPU based rendering](http://wdobbie.com/post/gpu-text-rendering-with-vector-textures/) approach. After a [discussion](https://github.com/processing/p5.js/issues/2183) on github we decided to go for the GPU based approach. I was not able to implement this approach as [Spongman](https://github.com/Spongman) had already done most of the work for text using the same technique. We decided to pull that implementation and polish it further (looking for bugs, improvements) instead of writing everything from scratch. The pull request is being reviewed [here](https://github.com/processing/p5.js/pull/3110).
56+
57+
### Other minor contributions
58+
59+
Fixed a minor issue with triangle stroke in 2D mode [#3075](https://github.com/processing/p5.js/pull/3075) closing [#3065](https://github.com/processing/p5.js/issues/3065).
60+
Ported some examples from Processing to p5.js [#242](https://github.com/processing/p5.js-website/pull/242).
61+
62+
## Support
63+
Any questions pertaining to this project may be addressed via Issues on the [p5.js repository](https://github.com/processing/p5.js). Simply create a new Issue and either assign or tag me in the conversation with @adilrabbani. For anything else, don't hesitate to get in touch at 14bscsarabbani@seecs.edu.pk!
64+
65+
## Conclusion
66+
67+
I learned a lot this summer. I would like to thank my mentor, [Stalgia Grigg](https://github.com/mlarghydracept) for all the guidance and help throughout the project as well as all the members of Processing Foundation for giving me a chance to contribute
68+
to this library.
69+
70+
Thanks everyone! 😃

lib/addons/p5.dom.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,80 @@
784784
return self;
785785
};
786786

787+
/**
788+
* Creates a colorPicker element in the DOM for color input.
789+
* The .value() method will return a hex string (#rrggbb) of the color.
790+
* The .color() method will return a p5.Color object with the current chosen color.
791+
*
792+
* @method createColorPicker
793+
* @param {String|p5.Color} [value] default color of element
794+
* @return {p5.Element} pointer to <a href="#/p5.Element">p5.Element</a> holding created node
795+
* @example
796+
* <div>
797+
* <code>
798+
* var inp1, inp2;
799+
* function setup() {
800+
* createCanvas(100, 100);
801+
* background('grey');
802+
* inp1 = createColorPicker('#ff0000');
803+
* inp2 = createColorPicker(color('yellow'));
804+
* inp1.input(setShade1);
805+
* inp2.input(setShade2);
806+
* setMidShade();
807+
* }
808+
*
809+
* function setMidShade() {
810+
* // Finding a shade between the two
811+
* var commonShade = lerpColor(inp1.color(), inp2.color(), 0.5);
812+
* fill(commonShade);
813+
* rect(20, 20, 60, 60);
814+
* }
815+
*
816+
* function setShade1() {
817+
* setMidShade();
818+
* console.log('You are choosing shade 1 to be : ', this.value());
819+
* }
820+
* function setShade2() {
821+
* setMidShade();
822+
* console.log('You are choosing shade 2 to be : ', this.value());
823+
* }
824+
* </code>
825+
* </div>
826+
*/
827+
p5.prototype.createColorPicker = function(value) {
828+
p5._validateParameters('createColorPicker', arguments);
829+
var elt = document.createElement('input');
830+
var self;
831+
elt.type = 'color';
832+
if (value) {
833+
if (value instanceof p5.Color) {
834+
elt.value = value.toString('#rrggbb');
835+
} else {
836+
p5.prototype._colorMode = 'rgb';
837+
p5.prototype._colorMaxes = {
838+
rgb: [255, 255, 255, 255],
839+
hsb: [360, 100, 100, 1],
840+
hsl: [360, 100, 100, 1]
841+
};
842+
elt.value = p5.prototype.color(value).toString('#rrggbb');
843+
}
844+
} else {
845+
elt.value = '#000000';
846+
}
847+
self = addElement(elt, this);
848+
// Method to return a p5.Color object for the given color.
849+
self.color = function() {
850+
if (value.mode) {
851+
p5.prototype._colorMode = value.mode;
852+
}
853+
if (value.maxes) {
854+
p5.prototype._colorMaxes = value.maxes;
855+
}
856+
return p5.prototype.color(this.elt.value);
857+
};
858+
return self;
859+
};
860+
787861
/**
788862
* Creates an &lt;input&gt;&lt;/input&gt; element in the DOM for text input.
789863
* Use .<a href="#/p5.Element/size">size()</a> to set the display length of the box.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<script language="javascript" type="text/javascript" src="../../../../../lib/p5.js"></script>
4+
<script language="javascript" type="text/javascript" src="../../../../../lib/addons/p5.dom.js"></script>
5+
<script language="javascript" src="sketch.js"></script>
6+
</head>
7+
8+
<body>
9+
<div id="test"></div>
10+
</body>
11+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var inp1, inp2;
2+
function setup() {
3+
createCanvas(100, 100);
4+
background('grey');
5+
var c1 = '#ff0000';
6+
inp1 = createColorPicker(c1);
7+
var c2 = color('yellow');
8+
inp2 = createColorPicker(c2);
9+
inp1.input(setShade1);
10+
inp2.input(setShade2);
11+
setMidShade();
12+
}
13+
14+
function setMidShade() {
15+
// Finding a shade between the two
16+
var commonShade = lerpColor(inp1.color(), inp2.color(), 0.5);
17+
fill(commonShade);
18+
rect(20, 20, 60, 60);
19+
}
20+
21+
function setShade1() {
22+
setMidShade();
23+
console.log('You are choosing shade 1 to be : ', this.value());
24+
}
25+
function setShade2() {
26+
setMidShade();
27+
console.log('You are choosing shade 2 to be : ', this.value());
28+
}

0 commit comments

Comments
 (0)