Skip to content

IFS: Standardize output files #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions contents/IFS/code/c/IFS.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ void chaos_game(struct point *in, size_t in_n, struct point *out,
}

int main() {
const int point_count = 10000;

struct point shape_points [3] = {{0.0,0.0}, {0.5,sqrt(0.75)}, {1.0,0.0}};
struct point out_points[1000];
struct point out_points[point_count];

srand(time(NULL));

chaos_game(shape_points, 3, out_points, 1000);
chaos_game(shape_points, 3, out_points, point_count);

FILE *fp = fopen("sierpinksi.dat", "w+");

for (int i = 0; i < 1000; ++i) {
for (int i = 0; i < point_count; ++i) {
fprintf(fp, "%f\t%f\n", out_points[i].x, out_points[i].y);
}

fclose(fp);

return 0;
}

2 changes: 1 addition & 1 deletion contents/IFS/code/clisp/ifs.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
`((0 0) (0.5 ,(sqrt 0.75)) (1 0))))

;; output the data to the "out.dat" file
(with-open-file (out "out.dat" :direction :output :if-exists :supersede)
(with-open-file (out "sierpinski.dat" :direction :output :if-exists :supersede)
(flet ((format-point (p)
;; this is not very clean, but it's the simplest way to insert a tab into a string.
(format nil "~f~c~f" (point-x p) #\tab (point-y p))))
Expand Down
2 changes: 1 addition & 1 deletion contents/IFS/code/haskell/IFS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ main = do
points = chaosGame g 10000 sierpinski
showPoint (Point x y) = show x ++ "\t" ++ show y

writeFile "out.dat" $ intercalate "\n" $ map showPoint points
writeFile "sierpinski.dat" $ intercalate "\n" $ map showPoint points