From instruction: Draw a straight line and follow it
Code: straight_line_torus by mtchl
A straight line on a toroidal surface. If it doesn't seem very straight, imagine unwrapping the torus into a 2d rectangle. Click to set a new random angle for the line.
Creative Commons BY-NC-SA license.
// a straight line (on a toroidal surface) // mitchell whitelaw - http://teemingvoid.blogspot.com // for instructionset.org // 20 may 2008 int offset = 0; int line_length = 0; int line_length_max = 5000; int inner_radius = 120; int outer_radius = 40; float inner_rotation_min = 0.001; float inner_rotation_max = 0.02; float outer_rotation_min = 0.001; float outer_rotation_max = 0.05; float inner_rotation = random(inner_rotation_min,inner_rotation_max); float outer_rotation = random(outer_rotation_min,outer_rotation_max); void setup(){ size(600,400,P3D); } void draw(){ background(0); translate(width/2,height/2); rotateX(mouseY*-0.01); rotateZ(mouseX*0.01); stroke(255,150); for (int v=0; v<line_length; v++){ pushMatrix(); rotateY((v+offset)*inner_rotation); translate(inner_radius,0); rotateZ((v+offset)*outer_rotation); translate(0,outer_radius); point(0,0); popMatrix(); } if (line_length > line_length_max) { offset+=10; } else { line_length+=10; } } void mousePressed(){ inner_rotation = random(inner_rotation_min,inner_rotation_max); outer_rotation = random(outer_rotation_min,outer_rotation_max); offset = 0; line_length = 0; }
[download]
Written in Processing.