Skip to content
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

Gridlines and inverted mode #4

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,41 @@ end
function plot(data::PlotInputs, start::Real=-10, stop::Real=10;
border::Bool=true, labels::Bool=true, title::Bool=true,
cols::Int=60, rows::Int=16, margin::Int=9,
scalefunc::Function=identity)
grid = fill(char(0x2800), cols, rows)
invert::Bool=false, gridlines::Bool=false)

if gridlines
if invert
fill_char=char(0x283F)
else
fill_char=char(0x2812)
end
else
if invert
fill_char=char(0x28FF)
else
fill_char=char(0x2800)
end
end
grid = fill(fill_char, cols, rows)
if invert
base_char=10495
else
base_char=10240
end
left, right = sides = ((0, 1, 2, 6), (3, 4, 5, 7))
function showdot(x, y) # Assumes x & y are already scaled to the grid.
invy = (rows - y)*0.9999
col, col2 = int(floor(x)), int(floor(x*2))
row, row4 = int(floor(invy)), int(floor(invy*4))
grid[col + 1, row + 1] |= 1 << sides[1 + (col2 & 1)][1 + (row4 & 3)]
offset=1 << sides[1 + (col2 & 1)][1 + (row4 & 3)]
if invert
grid[col + 1, row + 1] = convert(Char, base_char-offset)
else
grid[col + 1, row + 1] = convert(Char, base_char+offset)
end
end


continuous = isa(data, Vector{Function})
if continuous
xframes, yframes = cols, rows
Expand Down Expand Up @@ -159,4 +184,4 @@ function plot(rng::Range, etc...; args...)
end
function logplot(etc...; args...)
plot(etc...; scalefunc=log10, args...)
end
end