My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
/**
* PolarUnravel demo combines the following 3 features of toxiclibs:
* <ul>
* <li>Polar-Cartesian coordinate transformation</li>
* <li>Vector interpolation to smoothly switch layouts</li>
* <li>Use of InterpolateStrategy for easing effects</li>
* <li>Use TColor for working with HSV color space</li>
* </ul>
*
* The demo depends on the separately distributed colorutils package, also
* part of toxiclibs. You can download the latest version from here:
* http://code.google.com/p/toxiclibs/downloads/list
*
* Usage:
* Click mouse to toggle between radial/horizontal layout
*/

/*
* Copyright (c) 2006-2009 Karsten Schmidt
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* http://creativecommons.org/licenses/LGPL/2.1/
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

import toxi.color.*;

import toxi.geom.*;
import toxi.math.*;

// keepers of transition state & target
float transition, transTarget;

// use a S-Curve to achieve an ease in/out effect
InterpolateStrategy is=new SigmoidInterpolation(3);

void setup() {
size(600,600,P3D);
}

void draw() {
background(255);
float w2=width * 0.5;
float h2=height * 0.5;
translate(w2, h2);
// update transition
transition += (transTarget - transition) * 0.01;
Vec2D normUp = new Vec2D(0, -1);
// define a color container using HSV
TColor col = TColor.newHSV(0, 1, 1);
for(int i = 270; i < 360 + 270; i += 2) {
float theta = radians(i);
// create a polar coordinate
Vec2D polar = new Vec2D(100,theta);
// use theta as color hue (ensure theta is properly wrapped)
col.setHue((polar.y / TWO_PI) % 1);
// also use theta to manipulate line length
float len = noise(polar.y * 4) * 100;
// convert polar coord into cartesian space (to obtain position on a circle)
Vec2D circ = polar.copy().toCartesian();
// create another coord splicing the circle at the top and using theta difference as position on a line
Vec2D linear = new Vec2D((MathUtils.THREE_HALVES_PI - polar.y) * w2 / PI + w2, 0);
// interprete circular position as normal/direction vector
Vec2D dir = circ.getNormalized();
// interpolate both position & normal based on current transition state
circ.interpolateToSelf(linear, transition,is);
dir.interpolateToSelf(normUp, transition,is).normalizeTo(len);
// apply color & draw line
stroke(col.toARGB());
line(circ.x, circ.y, circ.x + dir.x, circ.y + dir.y);
}
}

void mousePressed() {
// toggle transition target state
transTarget=(++transTarget % 2);
}

Change log

r325 by toxmeister on Nov 22, 2009   Diff
updating all Processing examples to
reflect changes to the library classes
Go to: 
Project members, sign in to write a code review

Older revisions

r306 by toxmeister on Oct 30, 2009   Diff
adding PolarUnravel Processing demo
All revisions of this file

File info

Size: 3187 bytes, 90 lines
Powered by Google Project Hosting