shapes
This commit is contained in:
parent
5efb0eb582
commit
1f1ccd81bb
@ -1,11 +1,34 @@
|
|||||||
|
|
||||||
|
export
|
||||||
|
P2,
|
||||||
|
P3,
|
||||||
|
BezierCurve,
|
||||||
|
curve_points,
|
||||||
|
directed_curve
|
||||||
|
|
||||||
|
typealias P2 FixedSizeArrays.Vec{2,Float64}
|
||||||
|
typealias P3 FixedSizeArrays.Vec{3,Float64}
|
||||||
|
|
||||||
|
|
||||||
immutable Shape
|
immutable Shape
|
||||||
vertices::AVec
|
vertices::AVec
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Shape(x, y) = Shape(collect(zip(x, y)))
|
||||||
|
|
||||||
get_xs(shape::Shape) = Float64[v[1] for v in shape.vertices]
|
get_xs(shape::Shape) = Float64[v[1] for v in shape.vertices]
|
||||||
get_ys(shape::Shape) = Float64[v[2] for v in shape.vertices]
|
get_ys(shape::Shape) = Float64[v[2] for v in shape.vertices]
|
||||||
|
|
||||||
|
function scale(shape::Shape, x, y=x)
|
||||||
|
sx, sy = shape_coords(shape)
|
||||||
|
Shape(sx .* x, sy .* y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function translate(shape::Shape, x, y=x)
|
||||||
|
sx, sy = shape_coords(shape)
|
||||||
|
Shape(sx .+ x, sy .+ y)
|
||||||
|
end
|
||||||
|
|
||||||
function shape_coords(shape::Shape)
|
function shape_coords(shape::Shape)
|
||||||
unzip(shape.vertices)
|
unzip(shape.vertices)
|
||||||
end
|
end
|
||||||
@ -288,16 +311,6 @@ end
|
|||||||
|
|
||||||
# @require FixedSizeArrays begin
|
# @require FixedSizeArrays begin
|
||||||
|
|
||||||
export
|
|
||||||
P2,
|
|
||||||
P3,
|
|
||||||
BezierCurve,
|
|
||||||
curve_points,
|
|
||||||
directed_curve
|
|
||||||
|
|
||||||
typealias P2 FixedSizeArrays.Vec{2,Float64}
|
|
||||||
typealias P3 FixedSizeArrays.Vec{3,Float64}
|
|
||||||
|
|
||||||
type BezierCurve{T <: FixedSizeArrays.Vec}
|
type BezierCurve{T <: FixedSizeArrays.Vec}
|
||||||
control_points::Vector{T}
|
control_points::Vector{T}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -28,50 +28,50 @@ function _apply_recipe(d::KW, args...; issubplot=false, kw...)
|
|||||||
args
|
args
|
||||||
end
|
end
|
||||||
|
|
||||||
# # -------------------------------------------------
|
# -------------------------------------------------
|
||||||
|
|
||||||
# function rotate(x::Real, y::Real, θ::Real; center = (0,0))
|
function rotate(x::Real, y::Real, θ::Real; center = (0,0))
|
||||||
# cx = x - center[1]
|
cx = x - center[1]
|
||||||
# cy = y - center[2]
|
cy = y - center[2]
|
||||||
# xrot = cx * cos(θ) - cy * sin(θ)
|
xrot = cx * cos(θ) - cy * sin(θ)
|
||||||
# yrot = cy * cos(θ) + cx * sin(θ)
|
yrot = cy * cos(θ) + cx * sin(θ)
|
||||||
# xrot + center[1], yrot + center[2]
|
xrot + center[1], yrot + center[2]
|
||||||
# end
|
end
|
||||||
|
|
||||||
# # -------------------------------------------------
|
# -------------------------------------------------
|
||||||
|
|
||||||
# type EllipseRecipe <: PlotRecipe
|
type EllipseRecipe <: PlotRecipe
|
||||||
# w::Float64
|
w::Float64
|
||||||
# h::Float64
|
h::Float64
|
||||||
# x::Float64
|
x::Float64
|
||||||
# y::Float64
|
y::Float64
|
||||||
# θ::Float64
|
θ::Float64
|
||||||
# end
|
end
|
||||||
# EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0)
|
EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0)
|
||||||
|
|
||||||
# # return x,y coords of a rotated ellipse, centered at the origin
|
# return x,y coords of a rotated ellipse, centered at the origin
|
||||||
# function rotatedEllipse(w, h, x, y, θ, rotθ)
|
function rotatedEllipse(w, h, x, y, θ, rotθ)
|
||||||
# # # coord before rotation
|
# # coord before rotation
|
||||||
# xpre = w * cos(θ)
|
xpre = w * cos(θ)
|
||||||
# ypre = h * sin(θ)
|
ypre = h * sin(θ)
|
||||||
|
|
||||||
# # rotate and translate
|
# rotate and translate
|
||||||
# r = rotate(xpre, ypre, rotθ)
|
r = rotate(xpre, ypre, rotθ)
|
||||||
# x + r[1], y + r[2]
|
x + r[1], y + r[2]
|
||||||
# end
|
end
|
||||||
|
|
||||||
# function getRecipeXY(ep::EllipseRecipe)
|
function getRecipeXY(ep::EllipseRecipe)
|
||||||
# x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)])
|
x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)])
|
||||||
# top = rotate(0, ep.h, ep.θ)
|
top = rotate(0, ep.h, ep.θ)
|
||||||
# right = rotate(ep.w, 0, ep.θ)
|
right = rotate(ep.w, 0, ep.θ)
|
||||||
# linex = Float64[top[1], 0, right[1]] + ep.x
|
linex = Float64[top[1], 0, right[1]] + ep.x
|
||||||
# liney = Float64[top[2], 0, right[2]] + ep.y
|
liney = Float64[top[2], 0, right[2]] + ep.y
|
||||||
# Any[x, linex], Any[y, liney]
|
Any[x, linex], Any[y, liney]
|
||||||
# end
|
end
|
||||||
|
|
||||||
# function getRecipeArgs(ep::EllipseRecipe)
|
function getRecipeArgs(ep::EllipseRecipe)
|
||||||
# [(:line, (3, [:dot :solid], [:red :blue], :path))]
|
[(:line, (3, [:dot :solid], [:red :blue], :path))]
|
||||||
# end
|
end
|
||||||
|
|
||||||
# # -------------------------------------------------
|
# # -------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -265,9 +265,16 @@ end
|
|||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function with(f::Function, args...; kw...)
|
function with(f::Function, args...; kw...)
|
||||||
|
newdefs = KW(kw)
|
||||||
|
|
||||||
|
if :canvas in args
|
||||||
|
newdefs[:xticks] = nothing
|
||||||
|
newdefs[:yticks] = nothing
|
||||||
|
newdefs[:grid] = false
|
||||||
|
newdefs[:legend] = false
|
||||||
|
end
|
||||||
|
|
||||||
# dict to store old and new keyword args for anything that changes
|
# dict to store old and new keyword args for anything that changes
|
||||||
newdefs = KW(kw)
|
|
||||||
olddefs = KW()
|
olddefs = KW()
|
||||||
for k in keys(newdefs)
|
for k in keys(newdefs)
|
||||||
olddefs[k] = default(k)
|
olddefs[k] = default(k)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user