-
-
Notifications
You must be signed in to change notification settings - Fork 360
IFS in coconut #727
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
IFS in coconut #727
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d88ad50
first draft on IFS Coconut version
Amaras 2bdcf78
No idea why it doesn't work. Stopping for now.
Amaras b07cf62
added .gitignore clause for Coconut compilation + try for IFS code
Amaras bdac498
Overly minor revision because GH didn't like the lack of newline
Amaras 3f1bca2
Corrected the bug. Should be good to go.
Amaras 98c55be
Added coconut in the md file
Amaras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -511,3 +511,6 @@ vscode/ | |
|
||
# Data file extension for Algorithm Archive | ||
*.dat | ||
|
||
# Coconut compilation files | ||
**/coconut/*.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from math import sqrt | ||
from random import random, choice | ||
|
||
data point(x=0, y=0): | ||
def __add__(self, other): | ||
return point(self.x + other.x, self.y + other.y) | ||
|
||
def __rmul__(self, other): | ||
return point(self.x * other, self.y * other) | ||
|
||
def chaos_game(n, shape_points): | ||
p = point(random(), random()) | ||
|
||
for _ in range(n): | ||
p = (1/2) * (p + choice(shape_points)) | ||
yield p | ||
|
||
|
||
# This will generate a Sierpinski triangle with a chaos game of n points for an | ||
# initial triangle with three points on the vertices of an equilateral triangle: | ||
# A = (0.0, 0.0) | ||
# B = (0.5, sqrt(0.75)) | ||
# C = (1.0, 0.0) | ||
# It will output the file sierpinski.dat, which can be plotted after | ||
shape_points = [point(0.0, 0.0), | ||
point(0.5, sqrt(0.75)), | ||
point(1.0, 0.0)] | ||
with open("sierpinski.dat", "w") as f: | ||
for p in chaos_game(10000, shape_points): | ||
f.write("{0}\t{1}\n".format(p.x, p.y)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hint: it has to do with
point
here...