Skip to content

Instantly share code, notes, and snippets.

@matbesancon
Created December 24, 2020 14:45
Show Gist options
  • Save matbesancon/80aa961e5c01fa6c426426083c684d84 to your computer and use it in GitHub Desktop.
Save matbesancon/80aa961e5c01fa6c426426083c684d84 to your computer and use it in GitHub Desktop.
Javis projection
using Javis
nframes = 200
function ground(args...)
background("white") # canvas background
sethue("black") # pen color
end
function object(p=O, color="black", radius=12)
sethue(color)
circle(p, radius, :fill)
return p
end
myvideo = Video(300, 300)
Background(1:200, ground)
function draw_line(p1 = O, p2 = O, color = "black", action = :stroke, edge = "solid")
sethue(color)
setdash(edge)
line(p1, p2, action)
end
vert_line = Object(
(args...) ->
draw_line(Point(0, 170), Point(0, 0), "black", :stroke, "longdashed"),
)
horiz_line = Object(
(args...) ->
draw_line(Point(-170, 0), Point(0, 0), "black", :stroke, "longdashed"),
)
vert_line_solid = Object(
(args...) ->
draw_line(Point(0, 0), Point(0, -170), "black", :stroke, "solid"),
)
horiz_line_solid = Object(
(args...) ->
draw_line(Point(0, 0), Point(170, 0), "black", :stroke, "solid"),
)
function draw_proj(pos)
pos_proj = Point(
max(pos.x, 0),
min(pos.y, 0),
)
sethue("blue")
squircle(pos_proj, 10, 10, :fill)
return pos_proj
end
red_ball = Object(1:nframes, (args...)->object(O, "red"), Point(100,0))
act!(red_ball, Action(anim_rotate_around(2π, O)))
Object(1:nframes, (args...)->draw_proj(pos(red_ball)))
render(myvideo; pathname="how_to.gif", framerate=70)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment