Skip to content

Commit b020ec9

Browse files
committed
commit message
0 parents  commit b020ec9

File tree

17 files changed

+2252
-0
lines changed

17 files changed

+2252
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
distribution
2+
data
3+
lib
4+
web
5+
resources
6+
.DS_Store
7+
.project
8+
.classpath

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
XYScope is a library for Processing to render graphics on a vector display (oscilloscope, laser) by converting them to audio.
2+
3+
...

examples/P3D_toroid/P3D_toroid.pde

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
P3D_toroid
3+
Minimal version of Ira Greenbergs Toroid example
4+
for demonstrating P3D points and transformations can be used.
5+
- mouseX » adjust pts
6+
- mouseY » adjust segments
7+
- keyboard » look below for details
8+
https://processing.org/examples/toroid.html
9+
cc teddavis.org 2017
10+
*/
11+
12+
// import and create instance of XYscope
13+
import xyscope.*;
14+
XYscope xy;
15+
16+
// minim is required to generate audio
17+
import ddf.minim.*;
18+
19+
20+
int pts = 40;
21+
float angle = 0;
22+
float radius = 100.0;
23+
24+
// lathe segments
25+
int segments = 20;
26+
float latheAngle = 0;
27+
float latheRadius = 100.0;
28+
29+
//vertices
30+
PVector vertices[], vertices2[];
31+
32+
// for optional helix
33+
boolean isHelix = false;
34+
float helixOffset = 5.0;
35+
36+
void setup() {
37+
size(512, 512, P3D);
38+
39+
// initialize XYscope with default sound out
40+
xy = new XYscope(this);
41+
}
42+
43+
void draw() {
44+
background(0);
45+
46+
// clear waves like refreshing background
47+
xy.clearWaves();
48+
49+
// change shape with mouse
50+
pts = floor(map(mouseX, 0, width, 1, 50));
51+
segments = floor(map(mouseY, 0, height, 1, 50));
52+
53+
//center and spin toroid
54+
pushMatrix();
55+
56+
translate(width/2, height/2, -100);
57+
58+
rotateX(frameCount*PI/150);
59+
rotateY(frameCount*PI/170);
60+
rotateZ(frameCount*PI/90);
61+
62+
// initialize point arrays
63+
vertices = new PVector[pts+1];
64+
vertices2 = new PVector[pts+1];
65+
66+
// fill arrays
67+
for (int i=0; i<=pts; i++) {
68+
vertices[i] = new PVector();
69+
vertices2[i] = new PVector();
70+
vertices[i].x = latheRadius + sin(radians(angle))*radius;
71+
if (isHelix) {
72+
vertices[i].z = cos(radians(angle))*radius-(helixOffset*
73+
segments)/2;
74+
} else {
75+
vertices[i].z = cos(radians(angle))*radius;
76+
}
77+
angle+=360.0/pts;
78+
}
79+
80+
// draw toroid
81+
latheAngle = 0;
82+
for (int i=0; i<=segments; i++) {
83+
xy.beginShape();
84+
85+
for (int j=0; j<=pts; j++) {
86+
if (i>0) {
87+
xy.vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
88+
}
89+
vertices2[j].x = cos(radians(latheAngle))*vertices[j].x;
90+
vertices2[j].y = sin(radians(latheAngle))*vertices[j].x;
91+
vertices2[j].z = vertices[j].z;
92+
// optional helix offset
93+
if (isHelix) {
94+
vertices[j].z+=helixOffset;
95+
}
96+
xy.vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
97+
}
98+
// create extra rotation for helix
99+
if (isHelix) {
100+
latheAngle+=720.0/segments;
101+
} else {
102+
latheAngle+=360.0/segments;
103+
}
104+
xy.endShape();
105+
}
106+
popMatrix();
107+
108+
// build audio from shapes
109+
xy.buildWaves();
110+
111+
// draw all analytics
112+
xy.drawAll();
113+
}
114+
115+
/*
116+
left/right arrow keys control ellipse detail
117+
up/down arrow keys control segment detail.
118+
'a','s' keys control lathe radius
119+
'z','x' keys control ellipse radius
120+
'w' key toggles between wireframe and solid
121+
'h' key toggles between toroid and helix
122+
*/
123+
void keyPressed() {
124+
if (key == CODED) {
125+
// pts
126+
if (keyCode == UP) {
127+
if (pts<40) {
128+
pts++;
129+
}
130+
} else if (keyCode == DOWN) {
131+
if (pts>3) {
132+
pts--;
133+
}
134+
}
135+
// extrusion length
136+
if (keyCode == LEFT) {
137+
if (segments>3) {
138+
segments--;
139+
}
140+
} else if (keyCode == RIGHT) {
141+
if (segments<80) {
142+
segments++;
143+
}
144+
}
145+
}
146+
// lathe radius
147+
if (key =='a') {
148+
if (latheRadius>0) {
149+
latheRadius--;
150+
}
151+
} else if (key == 's') {
152+
latheRadius++;
153+
}
154+
// ellipse radius
155+
if (key =='z') {
156+
if (radius>10) {
157+
radius--;
158+
}
159+
} else if (key == 'x') {
160+
radius++;
161+
}
162+
// helix
163+
if (key =='h') {
164+
if (isHelix) {
165+
isHelix=false;
166+
} else {
167+
isHelix=true;
168+
}
169+
}
170+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
basic_drawing
3+
You can draw by simply adding points directly or converted
4+
cc teddavis.org 2017
5+
*/
6+
7+
// import and create instance of XYscope
8+
import xyscope.*;
9+
XYscope xy;
10+
11+
// minim is required to generate audio
12+
import ddf.minim.*;
13+
14+
void setup() {
15+
size(512, 512);
16+
17+
// initialize XYscope with default sound out
18+
xy = new XYscope(this);
19+
20+
// smooth waves to reduce visible points
21+
xy.smoothWaves(true);
22+
23+
// test best smoothAmount, default 12
24+
xy.smoothWavesAmount(12);
25+
}
26+
27+
28+
void draw() {
29+
background(0);
30+
31+
// build audio from shapes
32+
xy.buildWaves();
33+
34+
// draw all analytics
35+
xy.drawAll();
36+
}
37+
38+
void mouseDragged() {
39+
// add point based on width/height
40+
xy.point(mouseX, mouseY);
41+
42+
// add point normalized to 0 – 1
43+
//xy.addPoint(norm(mouseX, 0, width), norm(mouseY, 0, height));
44+
}
45+
46+
void keyPressed() {
47+
if (keyCode == 8) { // DELETE
48+
xy.clearWaves();
49+
}
50+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
basic_shapes
3+
Test this to make sure your setup is up and running.
4+
cc teddavis.org 2017
5+
*/
6+
7+
// import and create instance of XYscope
8+
import xyscope.*;
9+
XYscope xy;
10+
11+
// minim is required to generate audio
12+
import ddf.minim.*;
13+
14+
void setup() {
15+
size(512, 512);
16+
17+
// initialize XYscope with default sound out
18+
xy = new XYscope(this);
19+
}
20+
21+
void draw() {
22+
background(0);
23+
24+
// clear waves like refreshing background
25+
xy.clearWaves();
26+
27+
// set detail of vertex ellipse
28+
xy.ellipseDetail(30);
29+
30+
// use most primative shapes with class instance infront
31+
xy.ellipse(mouseX, mouseY, width/4, width/4);
32+
//xy.rect(mouseX, mouseY, width/4, width/4);
33+
//xy.line(mouseX, mouseY, width/4, width/4);
34+
//xy.point(mouseX, mouseY);
35+
36+
37+
// build audio from shapes
38+
xy.buildWaves();
39+
40+
// draw all analytics
41+
xy.drawAll();
42+
43+
// or specific ones
44+
// xy.drawPath();
45+
// xy.drawWaveform();
46+
// xy.drawWaves();
47+
// xy.drawXY();
48+
}

examples/clock/clock.pde

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
clock
3+
Extending Processing Clock example for XYscope
4+
https://processing.org/examples/clock.html
5+
cc teddavis.org 2017
6+
*/
7+
8+
// import and create instance of XYscope
9+
import xyscope.*;
10+
XYscope xy;
11+
12+
// minim is required to generate audio
13+
import ddf.minim.*;
14+
15+
int cx, cy;
16+
float secondsRadius;
17+
float minutesRadius;
18+
float hoursRadius;
19+
float clockDiameter;
20+
21+
void setup() {
22+
size(512, 512);
23+
stroke(255);
24+
25+
// initialize XYscope with default sound out
26+
xy = new XYscope(this);
27+
28+
// for clock
29+
int radius = min(width, height) / 2;
30+
secondsRadius = radius * 0.8;
31+
minutesRadius = radius * 0.60;
32+
hoursRadius = radius * 0.40;
33+
clockDiameter = radius * .8;
34+
35+
cx = width / 2;
36+
cy = height / 2;
37+
}
38+
39+
void draw() {
40+
background(0);
41+
42+
// clear waves like refreshing background
43+
xy.clearWaves();
44+
45+
// Angles for sin() and cos() start at 3 o'clock;
46+
// subtract HALF_PI to make them start at the top
47+
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
48+
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
49+
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
50+
51+
// Draw the hands of the clock
52+
int dots = 10;
53+
float step = map(second(), 0, 59, 1, .1);
54+
for (int i=0; i<int(dots); i++) {
55+
xy.line(cx, cy, cx + cos(s) * secondsRadius*i/dots, cy + sin(s) * secondsRadius*i/dots);
56+
}
57+
for (int i=1; i<dots; i++) {
58+
xy.line(cx, cy, cx + cos(m) * minutesRadius*i/dots, cy + sin(m) * minutesRadius*i/dots);
59+
}
60+
for (int i=1; i<dots; i++) {
61+
xy.line(cx, cy, cx + cos(h) * hoursRadius*i/dots, cy + sin(h) * hoursRadius*i/dots);
62+
}
63+
64+
// Draw the minute ticks
65+
for (int a = 0; a < 360; a+=6) {
66+
float angle = radians(a);
67+
float x = cx + cos(angle) * secondsRadius;
68+
float y = cy + sin(angle) * secondsRadius;
69+
xy.point(x, y);
70+
}
71+
72+
// build audio from shapes
73+
xy.buildWaves();
74+
75+
// draw all analytics
76+
xy.drawAll();
77+
}
78+
79+
// adjust freq() with arrow keys
80+
void keyPressed() {
81+
if (keyCode == 38) { // UP
82+
xy.freq(xy.freq().x+.5);
83+
} else if (keyCode == 40) { // DOWN
84+
xy.freq(xy.freq().x-.5);
85+
}
86+
}

0 commit comments

Comments
 (0)