Skip to content

Commit fee6970

Browse files
committed
Add cardioid fractal shader code
1 parent 35fd620 commit fee6970

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

cardioid.glsl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#version 430
2+
3+
out vec4 fragColor;
4+
5+
uniform vec2 resolution;
6+
uniform float time;
7+
8+
vec2 rotate2D(vec2 uv, float a) {
9+
float s = sin(a);
10+
float c = cos(a);
11+
return mat2(c, -s, s, c) * uv;
12+
}
13+
14+
vec2 hash12(float t) {
15+
float x = fract(sin(t * 3453.329));
16+
float y = fract(sin((t + x) * 8532.732));
17+
return vec2(x, y);
18+
}
19+
20+
void main() {
21+
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution.xy) / resolution.y;
22+
vec3 col = vec3(0.0);
23+
24+
uv = rotate2D(uv, 3.14 / 2.0);
25+
26+
float r = 0.17;
27+
for (float i=0.0; i < 60.0; i++) {
28+
float factor = (sin(time) * 0.5 + 0.5) + 0.3;
29+
i += factor;
30+
31+
float a = i / 3;
32+
float dx = 2 * r * cos(a) - r * cos(2 * a);
33+
float dy = 2 * r * sin(a) - r * sin(2 * a);
34+
35+
col += 0.013 * factor / length(uv - vec2(dx + 0.1, dy) - 0.02 * hash12(i));
36+
}
37+
col *= sin(vec3(0.2, 0.8, 0.9) * time) * 0.15 + 0.25;
38+
39+
fragColor = vec4(col, 1.0);
40+
}

main.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
shape("turtle")
44
speed(-5)
5-
5+
bgcolor("white")
6+
penup()
7+
goto(0, -180) # Move the turtle to a starting position
8+
pendown()
69

710
def tree(size, levels, angle):
811
if levels == 0:
@@ -23,7 +26,6 @@ def tree(size, levels, angle):
2326
right(angle)
2427
backward(size)
2528

26-
2729
def snowflake_side(length, levels):
2830
if levels == 0:
2931
forward(length)
@@ -38,18 +40,26 @@ def snowflake_side(length, levels):
3840
left(60)
3941
snowflake_side(length, levels - 1)
4042

41-
4243
def create_snowflake(sides, length):
4344
colors = ["green", "blue", "yellow", "orange"]
4445
for i in range(sides):
4546
color(colors[i])
4647
snowflake_side(length, sides)
4748
right(360 / sides)
4849

50+
create_snowflake(4, 200)
4951

50-
# left(90)
51-
# tree(70, 7, 30)
52+
# Hide the turtle after drawing the snowflake
53+
hideturtle()
5254

53-
create_snowflake(4, 200)
55+
# Move to the center and write "OmegaHack 2024"
56+
penup()
57+
goto(0, 0)
58+
color("black")
59+
write("OmegaHack 2024", align="center", font=("Arial", 24, "bold"))
60+
61+
# Move down a bit and write "DSI"
62+
goto(0, -30)
63+
write("DSI", align="center", font=("Arial", 18, "bold"))
5464

5565
mainloop()

0 commit comments

Comments
 (0)