1 '''
2 A wireframe box with colored edges which expands and contracts according
3 to time-of-day.
4 An original implementation of *hms* from http://www.gysin-vanetti.com/hms
5 (C) Ben Alkov, 2014, licensed as APL 2.0 as part of processing.py
6 (https://github.com/jdf/processing.py).
7 '''
8
9 def settings():
10 size(500, 500, P3D)
11 smooth(4)
12
13 def setup():
14 global fillCube, edgeCube
15 frame.setTitle("Box Clock")
16 camera(0, 0, 100,
17 0, 0, 0,
18 0, 1, 0)
19
20 # Creating a **filled** wireframe cube is non-obvious.
21 # We need an opaque black cube inside a transparent wireframe cube.
22 fillCube = createShape(BOX, 2)
23 edgeCube = makeEdgeCube()
24
25 # The fill color here has to match the `background` from `draw` in order
26 # for the fill cube to be invisible.
27 fillCube.setFill(color(10))
28
29
30 def draw():
31 rotateX(sin(frameCount * 0.008))
32 rotateY(cos(frameCount * 0.008))
33
34 # The fill color here has to match the `fillCube`'s `setFill` color in
35 # order for the fill cube to be invisible.
36 background(10)
37 drawShape()
38
39
40 def drawShape():
41 # `map`; "Re-maps a number from one range to another."
42 # Scale time units to 3D coordinates.
43 x = map(second(), 0, 59, 1, 12)
44 y = map(minute(), 0, 59, 1, 12)
45 z = map(hour(), 0, 23, 1, 12)
46
47 scale(x, y, z)
48 shape(fillCube, 0, 0)
49 shape(edgeCube, 0, 0)
50
51
52 def makeEdgeCube():
53 # Draw a 2x2x2 transparent cube with edges colored according to the
54 # current time.
55 Red = color(255, 137, 95) # Seconds.
56 Green = color(176, 255, 121) # Minutes.
57 Blue = color(56, 76, 204) # Hours.
58 edgeCube = createShape()
59 edgeCube.beginShape(LINES)
60
61 # Seconds - lines along `x`.
62 edgeCube.stroke(Red)
63 edgeCube.vertex(-1, 1, 1)
64 edgeCube.vertex(1, 1, 1)
65 edgeCube.vertex(-1, -1, 1)
66 edgeCube.vertex(1, -1, 1)
67 edgeCube.vertex(-1, -1, -1)
68 edgeCube.vertex(1, -1, -1)
69 edgeCube.vertex(-1, 1, -1)
70 edgeCube.vertex(1, 1, -1)
71
72 # Minutes - lines along `y`.
73 edgeCube.stroke(Green)
74 edgeCube.vertex(-1, 1, 1)
75 edgeCube.vertex(-1, -1, 1)
76 edgeCube.vertex(1, 1, 1)
77 edgeCube.vertex(1, -1, 1)
78 edgeCube.vertex(1, 1, -1)
79 edgeCube.vertex(1, -1, -1)
80 edgeCube.vertex(-1, 1, -1)
81 edgeCube.vertex(-1, -1, -1)
82
83 # Hours - lines along `z`.
84 edgeCube.stroke(Blue)
85 edgeCube.vertex(-1, 1, -1)
86 edgeCube.vertex(-1, 1, 1)
87 edgeCube.vertex(1, 1, -1)
88 edgeCube.vertex(1, 1, 1)
89 edgeCube.vertex(1, -1, -1)
90 edgeCube.vertex(1, -1, 1)
91 edgeCube.vertex(-1, -1, -1)
92 edgeCube.vertex(-1, -1, 1)
93 edgeCube.endShape()
94 return edgeCube
Static sketches including "size" as might be expected do not play too well.
Wednesday, 4 November 2015
A Third Coming for processing.py (a little unexpected)
Well it seem much kudos must go to Luca Damasco (Google Summer of Code student), the python mode has returned for processing-3.0 . I've just playing with it and it seems to be it might be as well to adopt an approach similar to that I settled on for JRubyArt, and explicitly create a settings method as below, and to set the sketch title in setup:-
Subscribe to:
Posts (Atom)