|
1 | | -/** |
2 | | - * CardCreator.pde |
3 | | - * |
4 | | - * This script aids in playing card design by using a customizable card |
5 | | - * template, building each card file with information provided in two |
6 | | - * spreadsheets. |
7 | | - * |
8 | | - * @author Andrew Albers |
9 | | - * @version 1.0 |
10 | | - * @since 2014-08-30 |
11 | | - */ |
12 | | - |
13 | | -PGraphics cardMain; |
14 | | -PGraphics fontPlacer; |
15 | | -PImage cardPic; |
16 | | -PFont font; |
17 | | -Table content; |
18 | | -Table template; |
19 | | -int maxWid = 0; |
20 | | -int maxHei = 0; |
21 | | -ArrayList<String> elements; |
22 | | - |
23 | | -/** |
24 | | - * Reads csv files, defines card dimensions to accomodate |
25 | | - * largest x + width and largest y + height of elements |
26 | | - * in template.csv |
27 | | - * |
28 | | - * TODO: Let user choose other card sizes to generate |
29 | | - * TODO: Add bleed area to card sizes for printing. |
30 | | - */ |
31 | | -void setup(){ |
32 | | - getCardValues(); |
33 | | - cardMain = createGraphics(maxWid,maxHei); |
34 | | - noLoop(); |
35 | | -} |
36 | | - |
37 | | -/** |
38 | | - * Kicks off card creation safter setup. |
39 | | - */ |
40 | | -void draw(){ |
41 | | - createAllCards(); |
42 | | -} |
43 | | - |
44 | | -/** |
45 | | - * Passes each row in the content.csv file to createCard() |
46 | | - */ |
47 | | -void createAllCards() { |
48 | | - println("Creating All Cards"); |
49 | | - for (TableRow conRow : content.rows()) { |
50 | | - createCard(conRow); |
51 | | - } |
52 | | - println("Done. Check the CardCreator directory for updated cards."); |
53 | | -} |
54 | | - |
55 | | -/** |
56 | | - * Builds a single card, placing each element in the order it appears in |
57 | | - * template.csv. Saves the finished image with the filename given under |
58 | | - * "Name" in the content.csv file. |
59 | | - * |
60 | | - * @param conRow a row in the user-created content.csv file |
61 | | - */ |
62 | | -void createCard(TableRow conRow) { |
63 | | - cardMain.clear(); |
64 | | - println("creating ", conRow.getString("saveFile")); |
65 | | - for(int i = 0; i < elements.size(); i++){ |
66 | | - //calls drawImg() if "Img" is in element name |
67 | | - if(elements.get(i).indexOf("Img") != -1){ |
68 | | - drawImg(conRow.getString(elements.get(i)), template.getRow(i)); |
69 | | - } |
70 | | - //calls drawText() if "Text" is in element name |
71 | | - else if(elements.get(i).indexOf("Text") != -1){ |
72 | | - drawText(conRow.getString(elements.get(i)), template.getRow(i)); |
73 | | - } |
74 | | - } |
75 | | - saveCard(conRow.getString("saveFile")); |
76 | | -} |
77 | | - |
78 | | -/** |
79 | | - * Saves a file to a given filename. |
80 | | - * |
81 | | - * @param filename |
82 | | - */ |
83 | | -void saveCard(String filename){ |
84 | | - cardMain.save(filename); |
85 | | -} |
86 | | - |
87 | | -/** |
88 | | - * Draws text given a text string, an x and y position, |
89 | | - * a width, height, and font. Optionally it will also squish |
90 | | - * the text given an hSquish (horizontal squish percentage). |
91 | | - * Also added an (optional) colorHex value. Default is white. |
92 | | - * |
93 | | - * @param t text to print |
94 | | - * @param row template.csv attributes for this text element |
95 | | - */ |
96 | | -void drawText(String t, TableRow row) { |
97 | | - int x = int(row.getString("x")); |
98 | | - int y = int(row.getString("y")); |
99 | | - int w = int(row.getString("w")); |
100 | | - int h = int(row.getString("h")); |
101 | | - |
102 | | - //get the text color or default to white |
103 | | - String hexStr = "FF" + row.getString("colorHex"); |
104 | | - if(hexStr.equals("")){ |
105 | | - hexStr = "FFFFFFFF"; |
106 | | - } |
107 | | - color col = unhex(hexStr); |
108 | | - |
109 | | - //get the horizontal squish value or defualt to 1 |
110 | | - float hSquish = float(row.getString("hSquish")); |
111 | | - if(Float.isNaN(hSquish) || hSquish <= 0) { |
112 | | - hSquish = 1; //set hSquish to 1 if undefined or <= 0 |
113 | | - } |
114 | | - |
115 | | - String text = t; |
116 | | - font = loadFont(row.getString("font")); |
117 | | - fontPlacer = createGraphics(int(w/hSquish),h); |
118 | | - fontPlacer.beginDraw(); |
119 | | - fontPlacer.textFont(font); |
120 | | - fontPlacer.textSize(int(row.getString("size"))); |
121 | | - fontPlacer.textAlign(LEFT,TOP); |
122 | | - fontPlacer.fill(col); |
123 | | - //provide extra horizontal space for text if 0 < hSquish < 1... |
124 | | - fontPlacer.text(text,0,0,int(w/hSquish),h); |
125 | | - fontPlacer.endDraw(); |
126 | | - //... and then compresses to the stated width |
127 | | - cardMain.image(fontPlacer.get(),x,y,w,h); |
128 | | -} |
129 | | - |
130 | | -/** |
131 | | - * Draws an image given a filename, an x and y position, |
132 | | - * a width, and height. |
133 | | - * |
134 | | - * @param filename the image file to draw |
135 | | - * @param row template.csv attributes for this image element |
136 | | - */ |
137 | | -void drawImg(String filename, TableRow row) { |
138 | | - if(filename.length() != 0){ |
139 | | - cardPic = loadImage(filename); |
140 | | - int x = int(row.getString("x")); |
141 | | - int y = int(row.getString("y")); |
142 | | - int w = int(row.getString("w")); |
143 | | - int h = int(row.getString("h")); |
144 | | - cardMain.image(cardPic,x,y,w,h); |
145 | | - } |
146 | | -} |
147 | | - |
148 | | -/** |
149 | | - * Reads template.csv and content.csv, stores their values in |
150 | | - * two tables: template and content. |
151 | | - * |
152 | | - * TODO: Allow multiple template.csv/content.csv files to be |
153 | | - * read. ie generate landscape and portrait-formatted |
154 | | - * cards at the same time |
155 | | - */ |
156 | | -void getCardValues(){ |
157 | | - elements = new ArrayList<String>(); |
158 | | - template = loadTable("template.csv", "header"); |
159 | | - for (TableRow row : template.rows()) { |
160 | | - //add to the list of elements |
161 | | - elements.add(row.getString("element")); |
162 | | - |
163 | | - // |
164 | | - if(int(row.getString("x"))+int(row.getString("w")) > maxWid){ |
165 | | - maxWid = int(row.getString("x"))+int(row.getString("w")); |
166 | | - } |
167 | | - if(int(row.getString("y"))+int(row.getString("h")) > maxHei) { |
168 | | - maxHei = int(row.getString("y"))+int(row.getString("h")); |
169 | | - } |
170 | | - } |
171 | | - content = loadTable("content.csv", "header"); |
172 | | -} |
| 1 | +///** |
| 2 | +// * CardCreator.pde |
| 3 | +// * |
| 4 | +// * This script aids in playing card design by using a customizable card |
| 5 | +// * template, building each card file with information provided in two |
| 6 | +// * spreadsheets. |
| 7 | +// * |
| 8 | +// * @author Andrew Albers |
| 9 | +// * @version 1.0 |
| 10 | +// * @since 2014-08-30 |
| 11 | +// */ |
| 12 | +// |
| 13 | +//PGraphics cardMain; |
| 14 | +//PGraphics fontPlacer; |
| 15 | +//PImage cardPic; |
| 16 | +//PFont font; |
| 17 | +//Table content; |
| 18 | +//Table template; |
| 19 | +//int maxWid = 0; |
| 20 | +//int maxHei = 0; |
| 21 | +//ArrayList<String> elements; |
| 22 | +// |
| 23 | +///** |
| 24 | +// * Reads csv files, defines card dimensions to accomodate |
| 25 | +// * largest x + width and largest y + height of elements |
| 26 | +// * in template.csv |
| 27 | +// * |
| 28 | +// * TODO: Let user choose other card sizes to generate |
| 29 | +// * TODO: Add bleed area to card sizes for printing. |
| 30 | +// */ |
| 31 | +//void setup(){ |
| 32 | +// getCardValues(); |
| 33 | +// cardMain = createGraphics(maxWid,maxHei); |
| 34 | +// noLoop(); |
| 35 | +//} |
| 36 | +// |
| 37 | +///** |
| 38 | +// * Kicks off card creation safter setup. |
| 39 | +// */ |
| 40 | +//void draw(){ |
| 41 | +// createAllCards(); |
| 42 | +//} |
| 43 | +// |
| 44 | +///** |
| 45 | +// * Passes each row in the content.csv file to createCard() |
| 46 | +// */ |
| 47 | +//void createAllCards() { |
| 48 | +// println("Creating All Cards"); |
| 49 | +// for (TableRow conRow : content.rows()) { |
| 50 | +// createCard(conRow); |
| 51 | +// } |
| 52 | +// println("Done. Check the CardCreator directory for updated cards."); |
| 53 | +//} |
| 54 | +// |
| 55 | +///** |
| 56 | +// * Builds a single card, placing each element in the order it appears in |
| 57 | +// * template.csv. Saves the finished image with the filename given under |
| 58 | +// * "Name" in the content.csv file. |
| 59 | +// * |
| 60 | +// * @param conRow a row in the user-created content.csv file |
| 61 | +// */ |
| 62 | +//void createCard(TableRow conRow) { |
| 63 | +// cardMain.clear(); |
| 64 | +// println("creating ", conRow.getString("saveFile")); |
| 65 | +// for(int i = 0; i < elements.size(); i++){ |
| 66 | +// //calls drawImg() if "Img" is in element name |
| 67 | +// if(elements.get(i).indexOf("Img") != -1){ |
| 68 | +// drawImg(conRow.getString(elements.get(i)), template.getRow(i)); |
| 69 | +// } |
| 70 | +// //calls drawText() if "Text" is in element name |
| 71 | +// else if(elements.get(i).indexOf("Text") != -1){ |
| 72 | +// drawText(conRow.getString(elements.get(i)), template.getRow(i)); |
| 73 | +// } |
| 74 | +// } |
| 75 | +// saveCard(conRow.getString("saveFile")); |
| 76 | +//} |
| 77 | +// |
| 78 | +///** |
| 79 | +// * Saves a file to a given filename. |
| 80 | +// * |
| 81 | +// * @param filename |
| 82 | +// */ |
| 83 | +//void saveCard(String filename){ |
| 84 | +// cardMain.save(filename); |
| 85 | +//} |
| 86 | +// |
| 87 | +///** |
| 88 | +// * Draws text given a text string, an x and y position, |
| 89 | +// * a width, height, and font. Optionally it will also squish |
| 90 | +// * the text given an hSquish (horizontal squish percentage). |
| 91 | +// * Also added an (optional) colorHex value. Default is white. |
| 92 | +// * |
| 93 | +// * @param t text to print |
| 94 | +// * @param row template.csv attributes for this text element |
| 95 | +// */ |
| 96 | +//void drawText(String t, TableRow row) { |
| 97 | +// int x = int(row.getString("x")); |
| 98 | +// int y = int(row.getString("y")); |
| 99 | +// int w = int(row.getString("w")); |
| 100 | +// int h = int(row.getString("h")); |
| 101 | +// |
| 102 | +// //get the text color or default to white |
| 103 | +// String hexStr = "FF" + row.getString("colorHex"); |
| 104 | +// if(hexStr.equals("")){ |
| 105 | +// hexStr = "FFFFFFFF"; |
| 106 | +// } |
| 107 | +// color col = unhex(hexStr); |
| 108 | +// |
| 109 | +// //get the horizontal squish value or defualt to 1 |
| 110 | +// float hSquish = float(row.getString("hSquish")); |
| 111 | +// if(Float.isNaN(hSquish) || hSquish <= 0) { |
| 112 | +// hSquish = 1; //set hSquish to 1 if undefined or <= 0 |
| 113 | +// } |
| 114 | +// |
| 115 | +// String text = t; |
| 116 | +// font = loadFont(row.getString("font")); |
| 117 | +// fontPlacer = createGraphics(int(w/hSquish),h); |
| 118 | +// fontPlacer.beginDraw(); |
| 119 | +// fontPlacer.textFont(font); |
| 120 | +// fontPlacer.textSize(int(row.getString("size"))); |
| 121 | +// fontPlacer.textAlign(LEFT,TOP); |
| 122 | +// fontPlacer.fill(col); |
| 123 | +// //provide extra horizontal space for text if 0 < hSquish < 1... |
| 124 | +// fontPlacer.text(text,0,0,int(w/hSquish),h); |
| 125 | +// fontPlacer.endDraw(); |
| 126 | +// //... and then compresses to the stated width |
| 127 | +// cardMain.image(fontPlacer.get(),x,y,w,h); |
| 128 | +//} |
| 129 | +// |
| 130 | +///** |
| 131 | +// * Draws an image given a filename, an x and y position, |
| 132 | +// * a width, and height. |
| 133 | +// * |
| 134 | +// * @param filename the image file to draw |
| 135 | +// * @param row template.csv attributes for this image element |
| 136 | +// */ |
| 137 | +//void drawImg(String filename, TableRow row) { |
| 138 | +// if(filename.length() != 0){ |
| 139 | +// cardPic = loadImage(filename); |
| 140 | +// int x = int(row.getString("x")); |
| 141 | +// int y = int(row.getString("y")); |
| 142 | +// int w = int(row.getString("w")); |
| 143 | +// int h = int(row.getString("h")); |
| 144 | +// cardMain.image(cardPic,x,y,w,h); |
| 145 | +// } |
| 146 | +//} |
| 147 | +// |
| 148 | +///** |
| 149 | +// * Reads template.csv and content.csv, stores their values in |
| 150 | +// * two tables: template and content. |
| 151 | +// * |
| 152 | +// * TODO: Allow multiple template.csv/content.csv files to be |
| 153 | +// * read. ie generate landscape and portrait-formatted |
| 154 | +// * cards at the same time |
| 155 | +// */ |
| 156 | +//void getCardValues(){ |
| 157 | +// elements = new ArrayList<String>(); |
| 158 | +// template = loadTable("template.csv", "header"); |
| 159 | +// for (TableRow row : template.rows()) { |
| 160 | +// //add to the list of elements |
| 161 | +// elements.add(row.getString("element")); |
| 162 | +// |
| 163 | +// // |
| 164 | +// if(int(row.getString("x"))+int(row.getString("w")) > maxWid){ |
| 165 | +// maxWid = int(row.getString("x"))+int(row.getString("w")); |
| 166 | +// } |
| 167 | +// if(int(row.getString("y"))+int(row.getString("h")) > maxHei) { |
| 168 | +// maxHei = int(row.getString("y"))+int(row.getString("h")); |
| 169 | +// } |
| 170 | +// } |
| 171 | +// content = loadTable("content.csv", "header"); |
| 172 | +//} |
173 | 173 |
|
0 commit comments