Skip to content

Instantly share code, notes, and snippets.

@TheCedarPrince
Created March 27, 2022 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheCedarPrince/efe363e231d9bbcb8eff06500d4b5de3 to your computer and use it in GitHub Desktop.
Save TheCedarPrince/efe363e231d9bbcb8eff06500d4b5de3 to your computer and use it in GitHub Desktop.
Prototype draft of creating Set Theory interface in JavisMath
using Colors
using Javis
using LaTeXStrings
using Luxor
using MathTeXEngine
########################
# FUNCTION DEFINITIONS #
########################
"""
make_drawing(width, height, img_path, bkg_color, origin_p)
Creates a Luxor `Drawing` object with given width and height dimensions.
Saves the image to whatever path of choosing.
Allows one to set the background color of an image.
Finally, one can set Luxor's reference origin point
"""
function make_drawing(width, height, img_path, bkg_color, origin_p)
d = Drawing(width, height, img_path)
background(bkg_color)
origin(origin_p)
return d
end
function JArrow(initial_point, terminal_point; padding = 0.15)
padded_initial_point =
between(initial_point, terminal_point, padding)
padded_terminal_point =
between(initial_point, terminal_point, 1 - padding)
arrow(padded_initial_point, padded_terminal_point, arrowheadlength = 15, linewidth = 3)
end
function JElement(;
p = O,
fill_color = "white",
outline_color = "blue",
text_color = "black",
action = :fill,
radius = 25,
text_size = 14,
circ_text = "",
)
sethue(fill_color)
circle(p, radius, :fill)
sethue(outline_color)
circle(p, radius, :stroke)
sethue(text_color)
fontsize(text_size)
text(circ_text, p, valign = :middle, halign = :center)
end
"""
Converts a coordinate pair in the traditional Cartesian coordinate system to a `Point` in Luxor's coordinate system.
"""
JPoint(p) = Point(p.x, -p.y)
JPoint(p::Array) = Point(p[1], -p[2])
JPoint(x, y) = Point(x, -y)
"""
Converts a Luxor `Point` to a coordinate pair in the traditional Cartesian coordinate system.
"""
LPoint(p::Point) = [p.x, -p.y]
"""
"""
distance(p1::Array, p2::Array) =
sqrt((p2[1] - p1[1])^2 + (p2[2] - p1[2])^2)
#############
# CONSTANTS #
#############
width = 400
height = 400
path = "/home/src/Projects/JavisMath/JavisMath/test.png"
color = RGBA(0.0, 0.0, 0.0)
op = Point(width / 2, height / 2)
tsize = 18
########
# MAIN #
########
my_draw = make_drawing(width, height, path, color, op);
x₁ = JPoint(-100, 100)
x₂ = JPoint(-100, 50)
x₃ = JPoint(-100, 0)
x₄ = JPoint(-100, -50)
x₅ = JPoint(-100, -100)
y₁ = JPoint(100, 100)
y₂ = JPoint(100, 50)
y₃ = JPoint(100, 0)
y₄ = JPoint(100, -50)
y₅ = JPoint(100, -100)
sethue("white")
setline(4)
ellipse(JPoint(-100, 0), 100, 300; action = :stroke)
setline(2)
JElement(p = x₁, radius = 15, text_size = tsize, circ_text = L"x_{1}", outline_color = "red")
JElement(p = x₂, radius = 15, text_size = tsize, circ_text = L"x_{2}", outline_color = "green")
JElement(p = x₃, radius = 15, text_size = tsize, circ_text = L"x_{3}", outline_color = "red")
JElement(p = x₄, radius = 15, text_size = tsize, circ_text = L"x_{4}")
JElement(p = x₅, radius = 15, text_size = tsize, circ_text = L"x_{5}", outline_color = "purple")
sethue("white")
setline(4)
ellipse(JPoint(100, 0), 100, 300; action = :stroke)
setline(2)
JElement(p = y₁, radius = 15, text_size = tsize, circ_text = L"y_{1}", outline_color = "red")
JElement(p = y₂, radius = 15, text_size = tsize, circ_text = L"y_{2}")
JElement(p = y₃, radius = 15, text_size = tsize, circ_text = L"y_{3}")
JElement(p = y₄, radius = 15, text_size = tsize, circ_text = L"y_{4}", outline_color = "purple")
JElement(p = y₅, radius = 15, text_size = tsize, circ_text = L"y_{5}", outline_color = "green")
sethue("red")
JArrow(x₁, y₁, padding = 0.075)
JArrow(x₃, y₁, padding = 0.075)
sethue("green")
JArrow(x₂, y₅, padding = 0.075)
sethue("purple")
JArrow(x₅, y₄, padding = 0.075)
finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment