viewof level = embed(
calcuvizspec({
models: [main],
input_cursors: [{player_x_in,player_y_in,ray_angle_in: clamped_ray_angle_in/*:(fov[0]+fov[1])/2*/
,fov_in:fov2}],
mark: {type:'rect',tooltip:false},
encodings: {
x: {grid: false, name: 'level_x_in', type:'nominal', domain: _.range(0,63.1,1)},
y: {grid: false, name: 'level_y_in', type: 'nominal', domain: _.range(0,63.1,1)},
color: {name: (observable_world ? 'level_player_ray_fov' : 'level_player'), type: 'quantitative', legend:false},
//row: {name: 'formula', type:'nominal', domain: ['level', 'level_plus_player', 'level_plus_player_plus_ray']},
},
width: 300, height:300,
spec_post_process: spec => {
spec.params = [{"name": "xy", "select": { "type": "point", "on": "mouseover", "nearest": true, "encodings": ["x", "y"], toggle:false}}];
let a = spec.encoding.x.axis; spec.encoding.x.axis = {...a, ticks:false, labels:false}
a = spec.encoding.y.axis; spec.encoding.y.axis = {...a, ticks:false, labels:false}
spec.encoding.color.scale = {scheme: 'turbo'}
return spec;
}
}), {actions:false})
viewof player_x_in = Inputs.range([3,61], {step:1, value:32, label:'player x'})
viewof player_y_in = Inputs.range([3,61], {step:1, value:32, label:'player y'})
clamped_ray_angle_in = {
if (ray_angle_in <= fov2[1] && ray_angle_in >= fov2[0])
return ray_angle_in
else return undefined
}//_.clamp(ray_angle_in,fov2[0],fov2[1])
viewof scene = embed(
calcuvizspec({
models: [main],
input_cursors: [{player_x_in,player_y_in}],
mark: {type:'bar', point:false, clip:true, tooltip:false},
encodings: {
x: {grid: false, name: 'ray_angle_in', /*sort:'descending',*/type: 'quantitative', domain: [clamped_ray_angle_in, ..._.range(fov2[0],fov2[1],ray_angle_in_step_size)], nice:false, ticks:2},
color: {name: 'ray_hit_color', type:'nominal', legend:false},
y: {grid: false, name: 'inverse_ray_length', type: 'quantitative'},
opacity: {name: 'inverse_ray_length', type: 'quantitative', legend:false},
},
width: 500, height:300,
spec_post_process: spec => {
spec.encoding.y.scale = {domain:[0,0.3],};
spec.encoding.x.axis = {tickCount:2, grid:false}
spec.params = [{"name": "ray_angle_in", "value": { "ray_angle_in": 0}, "select": { "type": "point", "on": "mouseover", "nearest": true, "encodings": ["x"], toggle:false}}];
spec.encoding.color.condition = {"test": `datum.ray_angle_in==${clamped_ray_angle_in || 999}`,"value": "red"}
spec.encoding.opacity.condition = {"test": `datum.ray_angle_in==${clamped_ray_angle_in || 999}`,"value": 1}
//spec.encoding.color.condition = {"param": "ray_angle_in", "empty":false, "value": "yellow"} // condition opacity also?
return spec
}
}), {config: {/*background:'#f9fef8'*/}})
viewof fov2 = interval([-5,5], {
step: 0.005,
value: [-1,1],
label: 'field of view',
width:400
})