Skip to content

Commit 2884538

Browse files
Merge pull request #229 from mugulmd/mug/showcaseClaude
[docs] add showcase: Claude
2 parents 3cc0a0a + 2ecf05f commit 2884538

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

docs/sardine_doc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
- [Solstice](showcase/solstice.md)
114114
- [Zorba in Belleville](showcase/zorba.md)
115115
- [Artificial Life](showcase/artificial_life.md)
116+
- [Claude](showcase/claude.md)
116117
- [About](about.md)
117118
- [Why Sardine?](about/why.md)
118119
- [Contributions](about/contributions.md)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Claude
2+
3+
<iframe width="700" height="500" src="https://www.youtube.com/embed/F4HdBTVKRWg" title="Claude v0.0.0 Live-Coding Demo" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
4+
5+
[Claude](https://github.com/mugulmd/Claude/) is a tool for synchronizing visuals with audio in a live-coding context.
6+
7+
It comes as a Sardine extension, and allows you to control an OpenGL shader from Sardine.
8+
9+
```python
10+
@swim
11+
def arpy(p=.25, i=0):
12+
build_up = '[1:100,.2]'
13+
D('(neu arpy:rand*20 2|5 8)', i=i,
14+
lpf=f'100+{build_up}*50',
15+
room=1, size=f'.5+{build_up}*(.4/100)'
16+
)
17+
again(arpy, p=.25, i=i+1)
18+
19+
@swim
20+
def stomp(p=.5, i=0):
21+
D('(eu stomp:(6|4|1) 5 8)', i=i)
22+
Claude('cellsize', '.3 .2 .1 .', i=i, d=4)
23+
D('. stomp:3', i=i, d=4, speed='[1 .5]!!2')
24+
Claude('noiseamp', '0 0 .02 0', i=i, d=2)
25+
again(stomp, p=.5, i=i+1)
26+
27+
@swim
28+
def slowmvt(p=2, i=0):
29+
Claude('mvt', ['.1 (-.1) 0', '0 rand*.2'], i=i)
30+
Claude('gap', '2 3|4', dt='i', i=i, d=3)
31+
again(slowmvt, p=2, i=i+1)
32+
```
33+
34+
```
35+
#version 330
36+
37+
uniform vec2 resolution;
38+
uniform float time;
39+
40+
uniform float cellsize = .5;
41+
uniform float pixsize = .01;
42+
uniform float noiseamp = .0;
43+
uniform int gap = 2;
44+
uniform vec2 mvt = vec2(0.1, 0.0);
45+
46+
out vec3 frag_color;
47+
48+
float noise(float x) {
49+
return fract(sin(x) * 43758.5453123);
50+
}
51+
52+
ivec2 pixelate(vec2 uv, float size) {
53+
return ivec2(floor(uv / size));
54+
}
55+
56+
vec2 cell_point(ivec2 cell) {
57+
float rand = noise(dot(cell, ivec2(12, 45)));
58+
float phase = rand * 100;
59+
float speed = 1 + rand;
60+
float angle = speed * time + phase;
61+
return (vec2(cos(angle), sin(angle)) + 1.0) * .5;
62+
}
63+
64+
void main() {
65+
// Retrieve, normalize and unsqueeze fragment coordinates
66+
vec2 uv = gl_FragCoord.xy / resolution;
67+
uv = 2.0 * uv - 1.0;
68+
uv.x *= resolution.x / resolution.y;
69+
70+
uv += mvt * time;
71+
72+
ivec2 pix = pixelate(uv, pixsize);
73+
uv = pix * pixsize;
74+
float disp = 2*noise(pix.y) - 1;
75+
uv += disp * noiseamp;
76+
77+
ivec2 coords = pixelate(uv, cellsize);
78+
79+
// Compute Voronoi cell
80+
float dist_min = 1000.;
81+
ivec2 cell_min = coords;
82+
for (int dx = -1; dx <= 1; dx++) {
83+
for (int dy = -1; dy <= 1; dy++) {
84+
ivec2 cell = coords + ivec2(dx, dy);
85+
vec2 pos = (cell_point(cell) + vec2(cell)) * cellsize;
86+
float dist = distance(uv, pos);
87+
if (dist < dist_min) {
88+
dist_min = dist;
89+
cell_min = cell;
90+
}
91+
}
92+
}
93+
94+
// Output color based on cell coordinates
95+
if (cell_min.x % gap == 0) {
96+
frag_color = vec3(1.0, 0.7, 0.9);
97+
} else {
98+
frag_color = vec3(0.0, 0.4, 0.6);
99+
}
100+
}
101+
```

0 commit comments

Comments
 (0)