I made a twisted torus!


#1

Hello everyone! I bought the software yesterday and have since been on a deep dive into livecoding, this is so amazing! Here’s what i’ve come up with so far. I dont really know much about coding, but I do know something about math:

//this makes a mobius loop
//or any kind of twisted torus

SLIDER(radius, 0.1..2);
SLIDER(width, 0.1..1);
SLIDER(twist, 1..32); //twist and twirl are the best
SLIDER(twirl, 1..32);  //names I could come up

vec3 gen(float t){
vec3 v;

float alpha = (int)twist * 2 * PI;
float beta = (int)twirl * 2 * PI;

v.x = (radius + width * cos(t * beta)) * cos(t * alpha);
v.y = (radius + width * cos(t * beta)) * sin(t * alpha);
v.z = width * sin(t * beta);

return v;
}


#2

very neat!

if you want you can use SLIDER_INT for twist and twirl.

//this makes a mobius loop
//or any kind of twisted torus

SLIDER(radius, 0.1..2);
SLIDER(width, 0.1..1);
SLIDER_INT(twist, 1..32); //twist and twirl are the best
SLIDER_INT(twirl, 1..32);  //names I could come up

vec3 gen(float t){
	vec3 v;

	float alpha = twist * 2 * PI;
	float beta = twirl * 2 * PI;

	v.x = (radius + width * cos(t * beta)) * cos(t * alpha);
	v.y = (radius + width * cos(t * beta)) * sin(t * alpha);
	v.z = width * sin(t * beta);

	return v;
}

in this way twist and twirl will always give you an integer value, and also it will only display integer values in the ui.


#3

Thanks a lot. As I said, I’m not good at coding but this is exactly what I need to get better at it. Using this to make actual music seems a bit daunting but for now I’m happy with creating shapes. the mobius just happend to sound nice, at least for some values of twist and twirl. BTW, I think I mislabled them! Twist should be Twirl and Twirl should be Twist.
Right now the Twirl value sets how twisted the torus is,


#4

love it. keep going! :slight_smile: