-
Notifications
You must be signed in to change notification settings - Fork 29
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
[CSG]: include Sierpinsky example in samples #231
Comments
As part of recent changes to CSG, the pyramid primitive that the Sierpinski snippet makes use of has been changed. I have yet to submit a PR for these changes, but will do so soon. The changes also include adding your snippet to the CSG samples folder, although the snippet is the one sent on Telegram which appears to be different from this more updated version. I had tweaked the impacted part of the snippet due to the change to the pyramid primitive, in order to achieve a similar result as before. I could try to incorporate the changes of this newer snippet into the existing sample and have that as part of my PR. Once the PR gets merged, it should resolve this issue. One thing I noticed in the new snippet is that the n=2 sphere version of the fractal appears to load indefinitely for me. I do not think it is just due to computational expense. I suspect some kind of bug with the union function due to the unioned Shapes not actually touching each other. I suspect so because reducing the translation amount between the spheres allows the Shape to render almost instantly: This issue may be related to #227. So perhaps the issue lies somewhere in our code, our patch file, or the JSCAD library. Current snippet pasted below for reference: // Source §1
// Prof Martin's Sierpinski triangle fractal
import { union, translate, scale, render, pyramid }
from 'csg';
const r = 1; // vertical stretch factor
const shape = scale(pyramid('#edd4c8'), 1, 1, r);
function repeat(n, trans, s) {
return n === 0
? s
: repeat(n - 1, trans, trans(s));
}
function sierpinski(o) {
const t1 = translate(o, 0.5, 0.5, -r);
const t2 = translate(o, -0.5, 0.5, -r);
const t3 = translate(o, 0.5, -0.5, -r);
const t4 = translate(o, -0.5, -0.5, -r);
const s = union(o,
union(union(t1, t2),
union(t3, t4)));
const s_scaled = scale(s, 0.5, 0.5, 0.5);
return s_scaled;
}
render(repeat(5, sierpinski, shape)); |
Feature
Include the Sierpinsky sample in the sample snippets and documentation. Here is the program:
https://share.sourceacademy.org/adkx8
The text was updated successfully, but these errors were encountered: