-
Notifications
You must be signed in to change notification settings - Fork 16
Canvas creation #32
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
base: master
Are you sure you want to change the base?
Canvas creation #32
Changes from all commits
502d6a5
40bda80
de36083
d90b811
d84042d
108996c
f0b0b3b
1fb3dd0
32ca239
81bb3e7
fd23e93
4c72bd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """ | ||
| gen_img = generatecanvas(colortype, x, y) | ||
| gen_img = generatecanvas(colortype, x, y, background) | ||
| gen_img = generatecanvas(colortype, [x,y]) | ||
| gen_img = generatecanvas(colortype, [x,y], background) | ||
|
|
||
| Creates an image of with the given colortype and size. | ||
| Defaults to a black solid image | ||
| """ | ||
| generatecanvas(colortype::Type, x::Int, y::Int) = zeros(colortype, (x,y)) | ||
|
|
||
| generatecanvas(colortype::Type, size::NTuple{2, Int}) = zeros(colortype, size) | ||
|
|
||
| generatecanvas(colortype::Type, x::Int, y::Int, b::AbstractBackground) = | ||
| generatecanvas(colortype, (x,y), b) | ||
|
|
||
| function generatecanvas(colortype::Type, size::NTuple{2, Int}, b::AbstractBackground) | ||
| draw!(zeros(colortype, (size...)), b) | ||
| end | ||
|
|
||
|
|
||
| """ | ||
| new_img = draw!(img, solid_background) | ||
|
|
||
| Paints the entire given image a solid color | ||
| """ | ||
| function draw!(img::AbstractArray{T,2}, b::SolidBackground) where {T<:Colorant} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again seems redundant with standard names: julia> A = fill(colorant"red", 2, 2)
2×2 Array{RGB{N0f8},2} with eltype RGB{Normed{UInt8,8}}:
RGB{N0f8}(1.0,0.0,0.0) RGB{N0f8}(1.0,0.0,0.0)
RGB{N0f8}(1.0,0.0,0.0) RGB{N0f8}(1.0,0.0,0.0)
julia> fill!(A, colorant"blue")
2×2 Array{RGB{N0f8},2} with eltype RGB{Normed{UInt8,8}}:
RGB{N0f8}(0.0,0.0,1.0) RGB{N0f8}(0.0,0.0,1.0)
RGB{N0f8}(0.0,0.0,1.0) RGB{N0f8}(0.0,0.0,1.0) |
||
| b.color == zero(typeof(b.color)) ? (return img) : nothing | ||
| x, y = size(img) | ||
| for i = 1:y | ||
| for j = 1:x | ||
| draw!(img, Point(j, i), b.color) | ||
| end | ||
| end | ||
| img | ||
| end | ||
|
|
||
| """ | ||
| new_img = draw!(img, striped_background) | ||
|
|
||
| Layers colors onto a given image to set a "background" | ||
| """ | ||
| function draw!(img::AbstractArray{T,2}, b::StripedBackground) where {T<:Colorant} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is interesting and adds novel functionality. However, you seem to implicitly assume that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also worth asking: how often do you use angles different from 0 and π/2? If your stripes are all rectilinear then there are easier implementations.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was more trying to make it completely general. A stripes function might be preferable and not dealing with backgrounds. Its just fit better into the flow of the module I am making. |
||
| x,y = size(img) | ||
| for (e,(c,d)) in enumerate(zip(b.colors,b.distances)) | ||
| draw!(img, LineNormal(d,b.θ), c) | ||
| for i = 1:y | ||
| cnt = 0 | ||
| for j = 1:x | ||
| if img[i,j] == zero(typeof(c)) | ||
| draw!(img, Point(j,i), c) | ||
| cnt += 1 | ||
| elseif img[i,j] == c | ||
| break | ||
| elseif img[i,j] in b.colors[1:e-1] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slow. How about an auxiliary array that indicates whether a given pixel has already been handled? |
||
| cnt = 1 | ||
| continue | ||
| end | ||
| end | ||
| cnt == 0 ? break : continue | ||
| end | ||
| end | ||
| img | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the work is being done by
zeros, why do we effectively have to create an alias to it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I have done this a different way. We can scrap this merge request. We can stick a stripped function in when needed.