Skip to content
Permalink
Browse files

fix visualisation

  • Loading branch information...
Roboneet committed Mar 1, 2019
1 parent f641456 commit d7bf53d82c852d3d9422ec768997d627366af7f1
Showing with 13 additions and 7 deletions.
  1. +1 −1 assets/pendulum/pendulum.js
  2. +2 −2 src/vis/cartpole.jl
  3. +10 −4 src/vis/utils.jl
@@ -9,7 +9,7 @@ function Pendulum(canvas){

Pendulum.prototype.set_theta = function(t){
console.log(t)
this.theta = t;
this.theta = t + Math.PI;
}

Pendulum.prototype.draw = function(){
@@ -12,7 +12,7 @@ function Ctx(env::CartPoleEnv)
"pole_diameter"=> env.polemass_length/5,
"x_threshold"=> env.x_threshold)

o = Observable(s, "obs", obs(env, env.state))
o = Observable(s, "obs", obs(env, Flux.data(env.state)))
onimport(s, @js () -> begin
window.pick = (e) -> document.querySelector(e)
window.container = window.pick(".wio-scope") || window.pick(".webio-scope")
@@ -28,5 +28,5 @@ function Ctx(env::CartPoleEnv)
end

function render(env::CartPoleEnv, ctx::Ctx)
ctx.o[] = obs(env, env.state)
ctx.o[] = obs(env, Flux.data(env.state))
end
@@ -7,14 +7,20 @@ struct Ctx <: AbstractCtx
o::Observable
end


function play(env, actions=rand(1:2, 1000), w=nothing)
# `play(env, actions)`
# or
# `
# using Blink
# w = Blink()
# play(env, actions, (ctx)=> body!(w, ctx.s))
# `
function play(env, actions=rand(1:2, 1000), cb=nothing)
reset!(env)
ctx = Ctx(env)
if w == nothing
if cb == nothing
display(ctx.s)
else
body!(w, ctx.s)
cb(ctx)
end

i = 1

0 comments on commit d7bf53d

Please sign in to comment.
You can’t perform that action at this time.