kerjos-Scope

Look at this little man on his bicycle!

Here’s the PDF: zoetrope-output

Look at all this math devoted to figuring out where his knees need to be! That’s the Law of Cosines right there!

 

 

 

 

 

 

 

 

 

 

 

I really wanted to imitate the figural drawings that come with Zoetropes. The bicycle is such a Victorian-era development I figured it would fit nicely. And it turns out that it works well with 11 frames.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
// Processing Template for Zoetrope toy by Eye Think
// https://www.amazon.com/Zoetrope-Animation-Toy-Victorian-Illusion/dp/B007VM9HZO/
// Developed for Processing 3.3.6 * http://processing.org
// 24 January 2018 * Golan Levin 
 
// See information about Processing PDF export at: 
// https://processing.org/reference/libraries/pdf/index.html
// PDF generated by Processing can be opened in Adobe Illustrator.
import processing.pdf.*;
boolean bRecordingPDF = false;
 
float inch = 72; 
float paperStripWidth = inch * 12.625;
float paperStripHeight = inch * 1.3125;
float overlapMargin = inch * 0.4375;
float artAreaWidth = paperStripWidth - overlapMargin;
float artAreaHeight = paperStripHeight;
 
final int nFrames = 11; 
int myFrameCount = 0;
int exportFrameCount = 0; 
boolean bAnimate = true; 
boolean bExportFrameImages = false;
 
//-------------------------------------------------------
void setup() {
  size(1224, 792); // 17x11" at 72DPI
  frameRate(15);
  smooth();
} 
 
//-------------------------------------------------------
void draw() {
  background(240); 
  if (bRecordingPDF) {
    beginRecord(PDF, "zoetrope-output.pdf");
  }
 
  // Do all the drawing. 
  pushMatrix(); 
  translate(width/2, height/2);
  translate(0-paperStripWidth/2, 0-paperStripHeight/2); 
 
  drawCutLines(); 
  drawGuides(); 
  drawAllFrames();
  popMatrix();
 
  if (bExportFrameImages) {
    // If activated, export .PNG frames 
    if (exportFrameCount < nFrames) { String filename = "frame_" + nf((exportFrameCount%nFrames), 3) + ".png"; saveFrame("frames/" + filename); println("Saved: " + filename); exportFrameCount++; if (exportFrameCount >= nFrames) {
        bExportFrameImages = false;
        exportFrameCount = 0;
      }
    }
  }
 
  if (bRecordingPDF) {
    endRecord();
    bRecordingPDF = false;
  }
}
 
 
//-------------------------------------------------------
void keyPressed() {
  switch (key) {
  case ' ': 
    // Press spacebar to pause/unpause the animation. 
    bAnimate = !bAnimate;
    break;
 
  case 'p': 
  case 'P':
    // Press 'p' to export a PDF for the Zoetrope. 17x11" paper!
    bRecordingPDF = true; 
    break;
 
  case 'f': 
  case 'F': 
    // Press 'f' to export .png Frames (to make an animated .GIF)
    myFrameCount = 0; 
    exportFrameCount = 0; 
    bExportFrameImages = true;
    bAnimate = true; 
    break;
  }
}
 
//-------------------------------------------------------
void drawCutLines() {
  fill(0); 
  textAlign(CENTER, BOTTOM); 
  text("Zoetrope Template", paperStripWidth/2, -20); 
 
  stroke(0); 
  strokeWeight(1.0);
  noFill(); 
  if (!bRecordingPDF) {
    fill(255);
  }
  rect(0, 0, paperStripWidth, paperStripHeight);
}
 
//-------------------------------------------------------
void drawGuides() {
  // This function draws the guidelines. 
  // Don't draw these when we're exporting the PDF. 
  if (!bRecordingPDF) {
    float frameSpacing = artAreaWidth / nFrames;
 
    stroke(128); 
    strokeWeight(0.2);
    for (int i=0; i<nFrames; i++) {
      pushMatrix();
      translate(i * frameSpacing, 0);
      rect(0, 0, frameSpacing, artAreaHeight); 
      popMatrix();
    }
  }
}
 
//-------------------------------------------------------
void drawAllFrames() {
  for (int i=0; i<nFrames; i++) {
 
    float frameSpacing = artAreaWidth / nFrames;
 
    pushMatrix();
    translate((i + 0.5) * frameSpacing, 0);
 
    int whichFrame = i; 
    if (bAnimate) {
      whichFrame = (i+myFrameCount)%nFrames;
    }
    drawArtFrame (whichFrame); 
    // drawArtFrameAlternate (whichFrame); 
 
    popMatrix();
  }
  myFrameCount++;
}
 
 
//-------------------------------------------------------
void drawArtFrame (int whichFrame) { 
  // Draw the artwork for a generic frame of the Zoetrope, 
  // given the framenumber (whichFrame) out of nFrames.
 
  //Draw a man on a bicycle, pedalling:
  pushMatrix();
  translate(0,50);
 
  //Bicycle
  stroke(0);
  fill(255);
 
  //Frame
  float gearsX = 0;
  float gearsY = 20;
  float[] frameFront = {12.5,0};
  triangle(-12.5,0, frameFront[0],frameFront[1], gearsX,gearsY);
 
  //Handlebars
  float[] handleBars = {15,-10};
  float handleBarLength = 5;
  float[] handleBarEnds = {handleBars[0]-handleBarLength,handleBars[1]};
  line(frameFront[0], frameFront[1], handleBars[0],handleBars[1]);
  line(handleBars[0], handleBars[1], handleBarEnds[0], handleBarEnds[1]);
 
  //Wheels:
  float diameter = 25;
  float wheelCenterX = 23;
  float wheelCenterY = 15;
  ellipse(wheelCenterX,wheelCenterY,diameter,diameter);
  ellipse((0-wheelCenterX),wheelCenterY,diameter,diameter);
 
  //Spokes:
  strokeWeight(1);
  float numSpokes = 9;
  float theta = map(whichFrame, 0, nFrames, 0, -360);
  for (float spoke=0; spoke<numSpokes; spoke++) {
      float lineX = wheelCenterX + (cos(radians(theta)) * diameter/2);
      float lineY = wheelCenterY + (sin(radians(theta)) * diameter/2);
      line(wheelCenterX, wheelCenterY, lineX, lineY);
      theta += (360/numSpokes);
  }
  theta = map(whichFrame, 0, nFrames, 0, -360);
  for (float spoke=0; spoke<numSpokes; spoke++) {
      float lineX = (0 - wheelCenterX) + (cos(radians(theta)) * diameter/2);
      float lineY = wheelCenterY + (sin(radians(theta)) * diameter/2);
      line((0 - wheelCenterX), wheelCenterY, lineX, lineY);
      theta += (360/numSpokes);
  }
 
  //Pedals
  ellipse(gearsX,gearsY,4,4);
  float pedalLength = 8;
  theta = map(whichFrame, 0, nFrames, 0, 360/2);
  float lineX1 = gearsX + (cos(radians(theta)) * pedalLength);
  float lineY1 = gearsY + (sin(radians(theta)) * pedalLength);
  float lineX2 = gearsX - (cos(radians(theta)) * pedalLength);
  float lineY2 = gearsY - (sin(radians(theta)) * pedalLength);
  line(lineX1,lineY1,lineX2,lineY2);
 
  //Pedals: Feet
  float pedalWidth = 4;
  float lineX3 = lineX1 + pedalWidth;
  float lineX4 = lineX2 + pedalWidth;
  line(lineX1,lineY1,lineX3,lineY1);
  line(lineX2,lineY2,lineX4,lineY2);
 
  //Man
  fill(0);
 
  //Feet
  float footOffset = 1;
  float footHeight = 2;
  float footWidth = 4;
  float[] ankle1 = {lineX1+footOffset,lineY1};
  //stroke(255,0,0);
  //ellipse(ankle1[0],ankle1[1],4,4);
  float[] ankle2 = {lineX2+footOffset,lineY2};
  //ellipse(ankle2[0],ankle2[1],4,4);
  triangle(ankle1[0],ankle1[1],
           ankle1[0]+footWidth,ankle1[1],
           ankle1[0],ankle1[1]-footHeight);
  triangle(ankle2[0],ankle2[1],
           ankle2[0]+footWidth,ankle2[1],
           ankle2[0],ankle2[1]-footHeight);
 
  //Torso
  float[] hips = {-12.5,0};
  //float shoulderHeight = map(whichFrame, 0,nFrames, 15,20);
  float shoulderPeriod = map(whichFrame, 0,nFrames, 0,1);
  shoulderPeriod = sin(PI*shoulderPeriod);
  float shoulderHeight = map(shoulderPeriod, 0,1, 15,20);
 
  float[] leftShoulder = {-8, 0-shoulderHeight};
  float[] rightShoulder = {0, 0-shoulderHeight};
  quad(hips[0],hips[1], 0,0,
       rightShoulder[0],rightShoulder[1], leftShoulder[0],leftShoulder[1]);
  float hipHeight = 7;
  float[] topOfHips;
  topOfHips = calcTopOfHips(hips,leftShoulder,hipHeight);
 
  //Head
  float headWidth = 6;
  float headHeight = 8;
  quad(rightShoulder[0] + headWidth/2, rightShoulder[1],
       rightShoulder[0] - headWidth/2, rightShoulder[1],
       rightShoulder[0] - headWidth/2, rightShoulder[1] - headHeight,
       rightShoulder[0] + headWidth/2, rightShoulder[1] - headHeight);
 
  //Knees
  float upperLeg = 20;
  float lowerLeg = 20;
  float kneeWidth = 3;
  float[] knee1;
  knee1 = calculateKnee(ankle1,hips,upperLeg,lowerLeg);
  float[] backOfKnee1;
  backOfKnee1 = calcBackOfKnee(knee1,topOfHips,kneeWidth);
  float[] knee2;
  knee2 = calculateKnee(ankle2,hips,upperLeg,lowerLeg);
  float[] backOfKnee2;
  backOfKnee2 = calcBackOfKnee(knee2,topOfHips,kneeWidth);
 
  //Legs
  stroke(0);
  triangle(hips[0],hips[1],topOfHips[0],topOfHips[1],knee1[0],knee1[1]);
  triangle(knee1[0],knee1[1],backOfKnee1[0],backOfKnee1[1],ankle1[0],ankle1[1]);
  triangle(hips[0],hips[1],topOfHips[0],topOfHips[1],knee2[0],knee2[1]);
  triangle(knee2[0],knee2[1],backOfKnee2[0],backOfKnee2[1],ankle2[0],ankle2[1]);
 
  //Arms
  triangle(leftShoulder[0],leftShoulder[1],
           rightShoulder[0],rightShoulder[1],
           handleBarEnds[0],handleBarEnds[1]);
  triangle(leftShoulder[0],leftShoulder[1]+6,
           0,handleBarEnds[1],
           handleBarEnds[0],handleBarEnds[1]);
 
  popMatrix();
 
}
 
float[] calcBackOfKnee(float[] knee, float[] topOfHips,
                       float kneeWidth){
   float x1 = topOfHips[0];
   float y1 = topOfHips[1];
   float x2 = knee[0];
   float y2 = knee[1];
   float x3 = x2 - kneeWidth;
   float m = ( (y2-y1) / (x2-x1) );
   float y3 = y1 + (m*(x3-x1));
   float[] backOfKnee = {x3,y3};
   return backOfKnee;
}
 
float[] calcTopOfHips(float[] hips, float[] leftShoulder,
                      float hipHeight) {
   float x1 = hips[0];
   float y1 = hips[1];
   float x2 = leftShoulder[0];
   float y2 = leftShoulder[1];
   float y3 = y1 - hipHeight;
   float m = ( (y2-y1) / (x2-x1) );
   float x3 = x1 + ((y3 - y1) / m);
   float[] topOfHips = {x3,y3};
   return topOfHips;
}
 
float[] calculateKnee(float[] ankle, float[] hips,
                      float upperLeg, float lowerLeg) {
   float x1 = hips[0];
   float y1 = hips[1];
   float x2 = ankle[0];
   float y2 = ankle[1];
   float d = x2 - x1;
   float e = y2 - y1;
   float c = sqrt(sq(d) + sq(e));
   /* //Test------------
   float ox = x1;
   float oy = y2;
   stroke(255,0,0);
   line(x1,y1,ox,oy); //e
   line(x2,y2,ox,oy); //d
   */
   float a = lowerLeg;
   float b = upperLeg;
   float B = acos( (sq(b)-sq(a)-sq(c)) / (-2*a*c) );
   float E = atan( (y2-y1) / (x2-x1) );
   float F = PI - B - E;
   float w = b * cos(F);
   float h = b * sin(F);
   float x3 = x2 + w;
   float y3 = y2 - h;
   /* Test
   line(x1,y1,x3,y3);
   line(x2,y2,x3,y3);
   */
   float[] knee = {x3,y3};
   return knee;
}
 
float function_PennerEaseOutBounce (float t) {
  if ((t) < (1/2.75f)) {
    return (7.5625f* t*t);
  } 
  else if (t < (2/2.75f)) {
    float postFix = t-=(1.5f/2.75f);
    return (7.5625f*(postFix)*t + 0.75f);
  } 
  else if (t < (2.5/2.75)) {
    float postFix = t-=(2.25f/2.75f);
    return (7.5625f*(postFix)*t + 0.9375f);
  } 
  else {
    float postFix = t-=(2.625f/2.75f);
    return (7.5625f*(postFix)*t + 0.984375f);
  }
  }
 
 
//-------------------------------------------------------
void drawArtFrameAlternate(int whichFrame) { 
  // An alternate drawing test. 
  // Draw a falling object. 
 
  float chuteHeight = artAreaHeight * 0.85;
  pushMatrix();
  translate(0, (artAreaHeight - chuteHeight)/2.0);
 
  // Draw a little splat on the frame when it hits the ground. 
  if (whichFrame == (nFrames-1)) {
    stroke(0, 0, 0); 
    strokeWeight(0.5); 
    int nL = 10;
    for (int i=0; i<nL; i++) {
      float a = HALF_PI + map(i, 0, nL-1, 0, TWO_PI);
      float cx = 12 * cos(a);
      float cy = 10 * sin(a); 
      float dx = 16 * cos(a);
      float dy = 13 * sin(a); 
      line (cx, (chuteHeight-5)+cy, dx, (chuteHeight-5)+dy);
    }
  }
 
  // Draw a little box frame
  fill(255); 
  stroke(0, 0, 0);
  strokeWeight(1); 
  rect(-5, 0, 10, chuteHeight); 
 
  // Make the puck accelerate downward
  float t = map(whichFrame, 0, nFrames-1, 0, 1); 
  float t2 = pow(t, 2.0); 
  float rh = 8 + whichFrame * 0.5; // wee stretch
  float ry = map(t2, 0, 1, 0, chuteHeight-rh); 
 
  noStroke(); 
  fill(0, 0, 0);
  rect(-5, ry, 10, rh);
 
  popMatrix(); 
}