# Problem in Pluto

**URL:** <https://discourse.julialang.org/t/problem-in-pluto/60683>\
**Category:** General Usage\
**Created:** [May 6, 2021, 9:22pm UTC](https://discourse.julialang.org/t/problem-in-pluto/60683 "2021-05-06T21:22:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vos](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@Vos](https://discourse.julialang.org/u/Vos)\
**Post date:** [May 6, 2021, 9:22pm UTC](https://discourse.julialang.org/t/problem-in-pluto/60683/1 "2021-05-06T21:22:34Z")

</div>

Good evening to all,

I have a problem with my code. What I wrote is supposed to draw “lines” connecting the edge of the large rectangle with the edge of the small rectangle, like this:

 ![APicture](https://global.discourse-cdn.com/julialang/original/3X/d/b/db4c2a4561f3aff3ba10f5ec0e7f4754b7873a5f.png)  
 ![BPicture](https://global.discourse-cdn.com/julialang/original/3X/1/4/14049369d6085772911ea92623cd87e6e9ee058d.png)

But sometimes it gives me this, which is not normal:

 ![CPicture](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6d0e0415dbb9a15e88c8c49cb382ca5a5782d18.png)  
 ![DPicture](https://global.discourse-cdn.com/julialang/original/3X/5/9/59005ad2d03eec4a54582ef4275a46859d6c58ff.png)

My code is the following :

```julia
begin
	using NativeSVG
    using PlutoUI
end

```

```julia
begin
	const track = zeros(Integer, 49, 49)
	track[1:2,1:49] .= -1
	track[48:49,1:49] .= -1
	track[1:49, 1:2] .= -1
	track[1:49, 48:49] .= -1
	track[12:38, 12:38].= -1
	nothing
end

```

```julia
function Map()
	for row in 1:49
		for col in 1:49
			x = 20 + col * 12
			y = 20 + row * 12
			if track[row, col] === -1
				rect(x = x, y = y, width = 12, height = 12, stroke = "transparent", fill = "black", stroke_width = "0")
			else 
				rect(x = x, y = y, width = 12, height = 12, stroke = "black", fill = "transparent", stroke_width = "0.4")
			end
		end
	end
end

```

```julia
function Line()
	Map()
	a = rand(1:49)
	b = rand(1:49)
	a1 = 20 + a * 12
	b1 = 20 + b * 12
	if track[a, b] ≠ -1
		if a == 3 || a == 39 && b ∈ (12 : 38) 
				while track[a, b] ≠ -1
				a1 = 20 + a * 12
				b1 = 20 + b * 12
				rect(x = a1 + 1, y = b1 + 1, width = 10, height = 10, fill = "red")
				a = a + 1
				end
		elseif a ∈ (12 : 38) && b == 3 || b == 39
			   while track[a, b] ≠ -1
				a1 = 20 + a * 12
				b1 = 20 + b * 12
				rect(x = a1 + 1, y = b1 + 1, width = 10, height = 10, fill = "red")
				b = b + 1
				end
		else 
			Line()
		end
	else 
		Line()
	end
end

```

```julia
Drawing(width = 700, height =700) do
	Line()
end

```

Do you know where the problem lies or even how to improve this code?  
Thanks

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [May 7, 2021, 7:17am UTC](https://discourse.julialang.org/t/problem-in-pluto/60683/2 "2021-05-07T07:17:12Z")

</div>

In your code, it is not possible for Pluto to detect cell dependencies because all functions work by implicitly modifying the global `track` variable.  
To make Pluto aware of the dependencies, use a more functional approach, i.e. `track2= Map(track)`, where `Map` takes their inputs as parameters and return the values they modified.  
The initialization of `track` and `Line` are probably fine because they define / only read the `track` variable.
