diff --git a/a.sml b/a.sml new file mode 100644 index 0000000..94e5178 --- /dev/null +++ b/a.sml @@ -0,0 +1,22 @@ +structure LowerCaseA = +struct + fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight) = + let + val endX = startX + drawWidth + val endY = startY + drawHeight + in + [ ((startX * (1.0 - 0.47499999404)) + (endX * 0.47499999404)) / windowWidth, + ((startY * (1.0 - 0.700000047684)) + (endY * 0.700000047684)) / windowHeight, + ((startX * (1.0 - 0.299999982119)) + (endX * 0.299999982119)) / windowWidth, + ((startY * (1.0 - 0.675000011921)) + (endY * 0.675000011921)) / windowHeight, + ((startX * (1.0 - 0.449999988079)) + (endX * 0.449999988079)) / windowWidth, + ((startY * (1.0 - 0.550000011921)) + (endY * 0.550000011921)) / windowHeight, + ((startX * (1.0 - 0.625)) + (endX * 0.625)) / windowWidth, + ((startY * (1.0 - 0.275000035763)) + (endY * 0.275000035763)) / windowHeight, + ((startX * (1.0 - 0.799999952316)) + (endX * 0.799999952316)) / windowWidth, + ((startY * (1.0 - 0.400000035763)) + (endY * 0.400000035763)) / windowHeight, + ((startX * (1.0 - 0.524999976158)) + (endX * 0.524999976158)) / windowWidth, + ((startY * (1.0 - 0.524999976158)) + (endY * 0.524999976158)) / windowHeight + ] + end +end diff --git a/dotscape b/dotscape index 051dad5..f0e8124 100755 Binary files a/dotscape and b/dotscape differ diff --git a/imperative-shell/file-thread.sml b/imperative-shell/file-thread.sml index 8ee3cea..2d5c480 100644 --- a/imperative-shell/file-thread.sml +++ b/imperative-shell/file-thread.sml @@ -10,7 +10,75 @@ struct datatype parse_result = OK of AppType.triangle list | PARSE_ERROR + val structureName = "LowerCaseA" val filename = "a.dsc" + val exportFilename = "a.sml" + + datatype dir = X | Y + + fun ndcToLerp (num, dir) = + let + val num = (num + 1.0) / 2.0 + val num = Real32.toString num + in + case dir of + X => + " ((startX * (1.0 - " ^ num ^ ")) + (endX * " ^ num ^ ")) / windowWidth" + | Y => + " ((startY * (1.0 - " ^ num ^ ")) + (endY * " ^ num ^ ")) / windowHeight" + end + + fun helpExportTriangles (io, triangles) = + case triangles of + {x1, y1, x2, y2, x3, y3} :: tl => + let + val x1 = ndcToLerp (x1, X) + val x2 = ndcToLerp (x2, X) + val x3 = ndcToLerp (x3, X) + + val y1 = ndcToLerp (y1, Y) + val y2 = ndcToLerp (y2, Y) + val y3 = ndcToLerp (y3, Y) + + val line = String.concat + [ x1, ",\n", y1, ",\n" + , x2, ",\n", y2, ",\n" + , x3, ",\n", y3 + , case tl of [] => "\n" | _ => ",\n" + ] + + val _ = TextIO.output (io, line) + in + helpExportTriangles (io, tl) + end + | [] => () + + fun exportTriangles triangles = + let + val io = TextIO.openOut exportFilename + + val fileStartString = + String.concat ["structure ", structureName, " =\nstruct\n"] + val _ = TextIO.output (io, fileStartString) + + val functionStartString = + " fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight) : Real32.real vector =\n\ + \ let\n\ + \ val startX = Real32.fromInt startX\n\ + \ val startY = Real32.fromInt startY\n\ + \ val endX = startX + drawWidth\n\ + \ val endY = startY + drawHeight\n\ + \ in\n\ + \ #[" + val _ = TextIO.output (io, functionStartString) + + val _ = helpExportTriangles (io, triangles) + + val _ = TextIO.output (io, " ]\n end\nend") + val _ = TextIO.closeOut io + in + () + end fun parse (io, acc) = case TextIO.inputLine io of