@@ -13,15 +13,15 @@ define(function(require) {
1313 * Creates a canvas element in the document, and sets the dimensions of it
1414 * in pixels. This method should be called only once at the start of setup.
1515 * <br>
16- * The system variables width and height are set by the parameters passed
17- * to this function. If createCanvas() is not used, the window will be
18- * given a default size of 100x100 pixels.
16+ * The system variables width and height are set by the parameters passed
17+ * to this function. If createCanvas() is not used, the window will be
18+ * given a default size of 100x100 pixels.
1919 *
2020 * @method createCanvas
2121 * @param {Number } w width of the canvas
2222 * @param {Number } h height of the canvas
2323 * @return {Object } canvas generated
24- * @example
24+ * @example
2525 * <div>
2626 * <code>
2727 * function setup() {
@@ -40,7 +40,7 @@ define(function(require) {
4040 } else { // resize the default canvas if new one is created
4141 c = document . getElementById ( 'defaultCanvas' ) ;
4242 if ( c ) {
43- c . id = '' ; // remove default id
43+ c . id = 'userCanvas ' ; // remove default id
4444 } else { // probably user calling createCanvas more than once... uhoh
4545 // c = document.createElement('canvas');
4646
@@ -53,11 +53,11 @@ define(function(require) {
5353 }
5454 }
5555
56+
5657 c . setAttribute ( 'width' , w * this . _pixelDensity ) ;
5758 c . setAttribute ( 'height' , h * this . _pixelDensity ) ;
5859 c . setAttribute ( 'style' ,
5960 'width:' + w + 'px !important; height:' + h + 'px !important;' ) ;
60-
6161 // set to invisible if still in setup (to prevent flashing with manipulate)
6262 if ( ! this . _setupDone ) {
6363 c . className += ' p5_hidden' ; // tag to show later
@@ -70,21 +70,49 @@ define(function(require) {
7070 document . body . appendChild ( c ) ;
7171 }
7272
73- var pg = new p5 . Graphics ( c , this ) ;
74- if ( isDefault ) {
75- // store in elements array
73+ var pg ;
74+ pg = this . _defaultGraphics ;
75+ if ( ! pg ) {
76+ pg = new p5 . Graphics ( c , this ) ;
7677 this . _elements . push ( pg ) ;
78+ this . _defaultGraphics = pg ;
79+ }
80+ else
81+ {
82+ pg . resize ( w * this . _pixelDensity , h * this . _pixelDensity ) ;
7783 }
84+
7885 this . scale ( this . _pixelDensity , this . _pixelDensity ) ;
7986 return pg ;
8087 } ;
8188
89+ p5 . prototype . resizeCanvas = function ( w , h ) {
90+ // What do we do if we have two canvases due to userNode
91+
92+ var c = document . getElementById ( 'defaultCanvas' ) ;
93+ if ( ! c ) {
94+ c = document . getElementById ( 'userCanvas' ) ;
95+ }
96+
97+ c . setAttribute ( 'width' , w * this . _pixelDensity ) ;
98+ c . setAttribute ( 'height' , h * this . _pixelDensity ) ;
99+ c . setAttribute ( 'style' ,
100+ 'width:' + w + 'px !important; height:' + h + 'px !important;' ) ;
101+
102+ var pg = this . _defaultGraphics ;
103+ if ( pg ) {
104+ pg . resize ( w * this . _pixelDensity , h * this . _pixelDensity ) ;
105+ }
106+ this . scale ( this . _pixelDensity , this . _pixelDensity ) ;
107+
108+ } ;
109+
82110
83111 /**
84- * Removes the default canvas for a p5 sketch that doesn't
112+ * Removes the default canvas for a p5 sketch that doesn't
85113 * require a canvas
86114 * @method noCanvas
87- * @example
115+ * @example
88116 * <div>
89117 * <code>
90118 * function setup() {
@@ -101,10 +129,10 @@ define(function(require) {
101129 } ;
102130
103131 /**
104- * Creates and returns a new p5.Graphics object. Use this class if you need
132+ * Creates and returns a new p5.Graphics object. Use this class if you need
105133 * to draw into an off-screen graphics buffer. The two parameters define the
106134 * width and height in pixels.
107- *
135+ *
108136 * @method createGraphics
109137 * @param {Number } w width of the offscreen graphics buffer
110138 * @param {Number } h height of the offscreen graphics buffer
@@ -122,7 +150,7 @@ define(function(require) {
122150 * pg.background(100);
123151 * pg.noStroke();
124152 * pg.ellipse(pg.width/2, pg.height/2, 50, 50);
125- * image(pg, 50, 50);
153+ * image(pg, 50, 50);
126154 * image(pg, 0, 0, 50, 50);
127155 * }
128156 * </code>
@@ -137,7 +165,7 @@ define(function(require) {
137165 //c.style.visibility='hidden';
138166 var node = this . _userNode || document . body ;
139167 node . appendChild ( c ) ;
140-
168+
141169 var pg = new p5 . Graphics ( c ) ;
142170 // store in elements array
143171 this . _elements . push ( pg ) ;
@@ -156,39 +184,39 @@ define(function(require) {
156184 } ;
157185
158186 /**
159- * Blends the pixels in the display window according to the defined mode.
160- * There is a choice of the following modes to blend the source pixels (A)
187+ * Blends the pixels in the display window according to the defined mode.
188+ * There is a choice of the following modes to blend the source pixels (A)
161189 * with the ones of pixels already in the display window (B):
162190 * <ul>
163- * <li><code>BLEND</code> - linear interpolation of colours: C =
191+ * <li><code>BLEND</code> - linear interpolation of colours: C =
164192 * A*factor + B. This is the default blending mode.</li>
165193 * <li><code>ADD</code> - sum of A and B</li>
166- * <li><code>DARKEST</code> - only the darkest colour succeeds: C =
194+ * <li><code>DARKEST</code> - only the darkest colour succeeds: C =
167195 * min(A*factor, B).</li>
168- * <li><code>LIGHTEST</code> - only the lightest colour succeeds: C =
196+ * <li><code>LIGHTEST</code> - only the lightest colour succeeds: C =
169197 * max(A*factor, B).</li>
170198 * <li><code>DIFFERENCE</code> - subtract colors from underlying image.</li>
171199 * <li><code>EXCLUSION</code> - similar to <code>DIFFERENCE</code>, but less
172200 * extreme.</li>
173- * <li><code>MULTIPLY</code> - multiply the colors, result will always be
201+ * <li><code>MULTIPLY</code> - multiply the colors, result will always be
174202 * darker.</li>
175- * <li><code>SCREEN</code> - opposite multiply, uses inverse values of the
203+ * <li><code>SCREEN</code> - opposite multiply, uses inverse values of the
176204 * colors.</li>
177205 * <li><code>REPLACE</code> - the pixels entirely replace the others and
178206 * don't utilize alpha (transparency) values.</li>
179207 * <li><code>OVERLAY</code> - mix of <code>MULTIPLY</code> and <code>SCREEN
180208 * </code>. Multiplies dark values, and screens light values.</li>
181- * <li><code>HARD_LIGHT</code> - <code>SCREEN</code> when greater than 50%
209+ * <li><code>HARD_LIGHT</code> - <code>SCREEN</code> when greater than 50%
182210 * gray, <code>MULTIPLY</code> when lower.</li>
183- * <li><code>SOFT_LIGHT</code> - mix of <code>DARKEST</code> and
211+ * <li><code>SOFT_LIGHT</code> - mix of <code>DARKEST</code> and
184212 * <code>LIGHTEST</code>. Works like <code>OVERLAY</code>, but not as harsh.
185213 * </li>
186- * <li><code>DODGE</code> - lightens light tones and increases contrast,
214+ * <li><code>DODGE</code> - lightens light tones and increases contrast,
187215 * ignores darks.</li>
188216 * <li><code>BURN</code> - darker areas are applied, increasing contrast,
189217 * ignores lights.</li>
190218 * </ul>
191- *
219+ *
192220 * @method blendMode
193221 * @param {String/Constant } mode blend mode to set for canvas
194222 * @example
0 commit comments