-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from FayCarsons/repeat
Added `repeat` function from original Python library
- Loading branch information
Showing
6 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
import numpy as np | ||
from joy import * | ||
|
||
|
||
class Ellipse: | ||
def __init__(self, center, radius_x, radius_y): | ||
self.center = np.array(center) | ||
self.radius_x = radius_x | ||
self.radius_y = radius_y | ||
|
||
def rotate(self, angle): | ||
# Translate to origin | ||
translated_center = np.array([0, 0]) | ||
translated_center[0] = self.center[0] - self.radius_x | ||
translated_center[1] = self.center[1] - self.radius_y | ||
|
||
# Rotate around the origin | ||
rotated_center = self.rotate_point(translated_center, angle) | ||
|
||
# Translate back to the original center | ||
self.center[0] = rotated_center[0] + self.radius_x | ||
self.center[1] = rotated_center[1] + self.radius_y | ||
|
||
@staticmethod | ||
def rotate_point(point, angle): | ||
x_rot = point[0] * np.cos(angle) - point[1] * np.sin(angle) | ||
y_rot = point[0] * np.sin(angle) + point[1] * np.cos(angle) | ||
return np.array([x_rot, y_rot]) |
This file contains 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 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 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,21 @@ | ||
open Joy.Shape | ||
|
||
(* | ||
demonstration of the repeat function | ||
takes n, an operation, and an initial shape, and applies the operation | ||
iteratively to the initial shape n times | ||
adapted from the original Joy python library's examples | ||
*) | ||
|
||
let () = | ||
init (); | ||
<<<<<<< HEAD | ||
let circle = circle ~point:{x = (-100); y = 0} 50 in | ||
let shapes = repeat 10 (translate 10 0) circle in | ||
======= | ||
let circle = circle ~x:(-100) ~y:0 50 in | ||
let shapes = repeat 10 (translate 10 0) circle in | ||
>>>>>>> 66df79e (formatting) | ||
render_shape shapes; | ||
close () |
This file contains 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 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