diff --git a/Torus.elm b/Torus.elm index 959c03e..758ef17 100644 --- a/Torus.elm +++ b/Torus.elm @@ -34,6 +34,11 @@ type alias Model = , time : Float , winSize : Window.Size } +totalLinePoints = 250 +ringRadius = 0.1 +ringVerts = 40 +knotScale = 0.2 + init: ( Model , Cmd Msg ) init = -- ( { p = 1 , q = 0 , time = 0.0 , winSize = (Window.Size 1 1) @@ -124,10 +129,10 @@ torusPoints p q = interpolatedCircle totalLinePoints |> List.map (\ t -> - let r = 0.5 * (2 + sin (q * t)) + let r = 2 + sin (q * t) in vec3 (cos (t * p) * r) - (cos (t * q) * r * 0.5) + (cos (t * q) * r * 0.25) (sin (t * p) * r) ) @@ -136,9 +141,11 @@ torusRings verts = verts |> List.map (\ (p1, p2)-> - (List.map circlePoint <| interpolatedCircle ringVerts) + ringVerts + |> interpolatedCircle + |> List.map circlePoint |> List.map (\ p -> - let (mid , dir) = (Vec3.add p1 p2 |> Vec3.scale 0.5 , Vec3.sub p2 p1 |> Vec3.normalize) + let (mid , dir) = (Vec3.add p1 p2 |> Vec3.scale knotScale , Vec3.sub p2 p1 |> Vec3.normalize) p_ = Vec3.toRecord p dir_ = Vec3.toRecord dir u = Vec3.cross dir Vec3.j |> Vec3.normalize @@ -168,7 +175,12 @@ circlePoint: Float -> Vec3 circlePoint x = vec3 (cos x) (sin x) 0 makePairs: List a -> List (a ,a) -makePairs ps = List.map2 (,) ps (List.drop 1 ps) +makePairs ps1 = + case ps1 of + [] -> [] + h::tail -> + let ps2 = tail ++ [h] + in List.map2 (,) ps1 ps2 closedPairs: List a -> List (a ,a) closedPairs xs = @@ -197,6 +209,10 @@ colorToVec3 color = c = Color.toRgb color in vec3 (to01 c.red) (to01 c.green) (to01 c.blue) +------------- +-- Shaders +------------- + type alias DiffuseColor = { projection : Mat4 , view : Mat4 @@ -248,6 +264,3 @@ diffuseFS = gl_FragColor = vec4(color * vlightWeight, 1.0); } |] - - -