-
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.
Implement Polygon type + refactored Rectangle to make use of it (#69)
* first attempt - not working * polygon implmentation + refactored rectangle; both working w/ examples * removed rectangle type and refactored examples * fixing merge issues * Resolve conflicts after merging with master --------- Co-authored-by: Kaustubh Maske Patil <[email protected]>
- Loading branch information
1 parent
704c2b6
commit 91123cf
Showing
6 changed files
with
62 additions
and
70 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
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,11 @@ | ||
open Joy.Shape | ||
|
||
let size = 100 | ||
|
||
let () = | ||
init (); | ||
let poly = | ||
polygon [ { x = -size; y = 0 }; { x = 0; y = size }; { x = size; y = 0 } ] | ||
in | ||
render_shape poly; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,10 @@ | ||
open Graphics | ||
open Joy.Shape | ||
|
||
type point = { x : int; y : int } | ||
type rectangle = { c : point; length : int; width : int } | ||
type shape = Rectangle of rectangle | ||
|
||
let canvas_size = (500, 500) | ||
let canvas_mid = { x = fst canvas_size / 2; y = snd canvas_size / 2 } | ||
|
||
let render_shape s = | ||
match s with | ||
| Rectangle rect -> | ||
let x1 = rect.c.x - (rect.length / 2) in | ||
let x2 = rect.c.x + (rect.length / 2) in | ||
let y1 = rect.c.y - (rect.width / 2) in | ||
let y2 = rect.c.y + (rect.width / 2) in | ||
draw_rect x1 y1 (x2 - x1) (y2 - y1) | ||
|
||
let rectangle ?x ?y length width = | ||
let center = | ||
match (x, y) with Some x, Some y -> { x; y } | _ -> canvas_mid | ||
in | ||
Rectangle { c = center; length; width } | ||
|
||
let show shapes = List.iter render_shape shapes | ||
let size = 100 | ||
|
||
let () = | ||
open_graph | ||
(" " | ||
^ string_of_int (fst canvas_size) | ||
^ "x" | ||
^ string_of_int (snd canvas_size)); | ||
set_color black; | ||
|
||
let rect = rectangle 200 100 in | ||
show [ rect ]; | ||
|
||
ignore (read_line ()); | ||
close_graph () | ||
init (); | ||
(* creating a rectangle from points *) | ||
let rect = rectangle size size in | ||
render_shape rect; | ||
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