@@ -1111,27 +1111,118 @@ p5.PrintWriter = function(filename, extension) {
1111
1111
this . content = '' ;
1112
1112
//Changed to write because it was being overloaded by function below.
1113
1113
/**
1114
+ * Writes data to the PrintWriter stream
1114
1115
* @method write
1115
- * @param {Array } data
1116
+ * @param {Array } data all data to be written by the PrintWriter
1117
+ * @example
1118
+ * <div class="norender">
1119
+ * <code>
1120
+ * // creates a file called 'newFile.txt'
1121
+ * var writer = createWriter('newFile.txt');
1122
+ * // write 'Hello world!'' to the file
1123
+ * writer.write(['Hello world!']);
1124
+ * // close the PrintWriter and save the file
1125
+ * writer.close();
1126
+ * </code>
1127
+ * </div>
1128
+ * <div class='norender'>
1129
+ * <code>
1130
+ * // creates a file called 'newFile2.txt'
1131
+ * var writer = createWriter('newFile2.txt');
1132
+ * // write 'apples,bananas,123' to the file
1133
+ * writer.write(['apples', 'bananas', 123]);
1134
+ * // close the PrintWriter and save the file
1135
+ * writer.close();
1136
+ * </code>
1137
+ * </div>
1138
+ * <div class='norender'>
1139
+ * <code>
1140
+ * // creates a file called 'newFile3.txt'
1141
+ * var writer = createWriter('newFile3.txt');
1142
+ * // write 'My name is: Teddy' to the file
1143
+ * writer.write('My name is:');
1144
+ * writer.write(' Teddy');
1145
+ * // close the PrintWriter and save the file
1146
+ * writer.close();
1147
+ * </code>
1148
+ * </div>
1116
1149
*/
1117
1150
this . write = function ( data ) {
1118
1151
this . content += data ;
1119
1152
} ;
1120
1153
/**
1154
+ * Writes data to the PrintWriter stream, and adds a new line at the end
1121
1155
* @method print
1122
- * @param {Array } data
1156
+ * @param {Array } data all data to be printed by the PrintWriter
1157
+ * @example
1158
+ * <div class='norender'>
1159
+ * <code>
1160
+ * // creates a file called 'newFile.txt'
1161
+ * var writer = createWriter('newFile.txt');
1162
+ * // creates a file containing
1163
+ * // My name is:
1164
+ * // Teddy
1165
+ * writer.print('My name is:');
1166
+ * writer.print('Teddy');
1167
+ * // close the PrintWriter and save the file
1168
+ * writer.close();
1169
+ * </code>
1170
+ * </div>
1171
+ * <div class='norender'>
1172
+ * <code>
1173
+ * var writer;
1174
+ *
1175
+ * function setup() {
1176
+ * createCanvas(400, 400);
1177
+ * // create a PrintWriter
1178
+ * writer = createWriter('newFile.txt');
1179
+ * }
1180
+ *
1181
+ * function draw() {
1182
+ * // print all mouseX and mouseY coordinates to the stream
1183
+ * writer.print([mouseX, mouseY]);
1184
+ * }
1185
+ *
1186
+ * function mouseClicked() {
1187
+ * // close the PrintWriter and save the file
1188
+ * writer.close();
1189
+ * }
1190
+ * </code>
1191
+ * </div>
1123
1192
*/
1124
1193
this . print = function ( data ) {
1125
1194
this . content += data + '\n' ;
1126
1195
} ;
1127
1196
/**
1197
+ * Flushes the PrintWriter object
1128
1198
* @method flush
1199
+ * @example
1129
1200
*/
1130
1201
this . flush = function ( ) {
1131
1202
this . content = '' ;
1132
1203
} ;
1133
1204
/**
1205
+ * Closes the PrintWriter
1134
1206
* @method close
1207
+ * @example
1208
+ * <div class="norender">
1209
+ * <code>
1210
+ * // create a file called 'newFile.txt'
1211
+ * var writer = createWriter('newFile.txt');
1212
+ * // close the PrintWriter and save the file
1213
+ * writer.close();
1214
+ * </code>
1215
+ * </div>
1216
+ * <div class='norender'>
1217
+ * <code>
1218
+ * // create a file called 'newFile2.txt'
1219
+ * var writer = createWriter('newFile2.txt');
1220
+ * // write some data to the file
1221
+ * writer.write([100, 101, 102]);
1222
+ * // close the PrintWriter and save the file
1223
+ * writer.close();
1224
+ * </code>
1225
+ * </div>
1135
1226
*/
1136
1227
this . close = function ( ) {
1137
1228
// convert String to Array for the writeFile Blob
0 commit comments