# The dot is chasing me! [closed]

Write a program that displays a dot that moves toward the position of your mouse at 4 pixels per second. The dot must be 100 pixels big and the window must fill the computer screen.

None

## Output

A window showing an animated dot moving towards the mouse at a fixed, non-changing speed.

## Scoring

This is , so the shortest code in bytes wins.

## closed as unclear what you're asking by Mego♦, J42161217, Toto, Erik the Outgolfer, user42649 Jun 12 '17 at 12:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Edits that invalidate existing answers are not advised. Just sayin – Gryphon - Reinstate Monica Jun 12 '17 at 0:11
• What is the formula for speed? Is Manhattan distance allowed? – ASCII-only Jun 12 '17 at 0:11
• Please leave it at "the window must fill the computer screen"; it's more objective anyway. – MD XF Jun 12 '17 at 0:11
• I assume ruffle means roughly; however, this is also subjective, and we like 100% objective challenges here. – MD XF Jun 12 '17 at 0:15
• thanks MD XF did not relies that things need to be 100% – Foxy Jun 12 '17 at 0:19

# Mathematica, 89 bytes

Graphics[Disk[Dynamic[MousePosition["Graphics",{0,0}]],.1],PlotRange->10,ImageSize->1000]


# HTML + JavaScript, 140 bytes

Infinite speed

t=c.getContext2d
c.onmousemove=e=>(x=e.clientX,y=e.clientY)
setInterval(_=>t.clearRect(0,0,1e5,1e5)||t.fillRect(x,y,10,10),9)
<canvas id=c>

Non-cheaty, 188 bytes

x=y=0,t=c.getContext2d
c.onmousemove=e=>(z=e.pageX,w=e.pageY)
f=_=>t.clearRect(0,0,1e5,1e5)||(m=((a=z-x)**2+(b=w-y)**2)**.5)|t.fillRect(x+=a/m,y+=b/m,10,10)
setInterval(f,9)
<canvas id=c>

Larger and faster:

x=y=0,s=3,t=c.getContext2d
c.onmousemove=e=>(z=e.pageX,w=e.pageY)
f=_=>t.clearRect(0,0,1e5,1e5)||(m=((a=z-x)**2+(b=w-y)**2)**.5)|t.fillRect(x+=s*a/m,y+=s*b/m,10,10)
setInterval(f,9)
<canvas id=c height=999 width=999>

• did you see my edit – Foxy Jun 12 '17 at 0:07
• I think there is a problem with you second code ASCII-only it dos'nt follow my mose it just flouts above it – Foxy Jun 12 '17 at 0:16
• never mind it works now – Foxy Jun 12 '17 at 0:22

## Python 3 + Tkinter, 264262259 254 bytes

import tkinter as t,numpy as n
f=t.Tk()
p=n.array([1,1])
q=n.array([0.]*2)
c=t.Canvas(f)
c.pack()
def s(e):p[:]=e.x,e.y
c.bind("<Motion>",s)
z=c.create_oval(0,0,2,2)
def r():d=p-q;u=(d*d.T+.1)**-0.5;c.move(z,*u*d);q[:]+=u*d;c.after(9,r)
r()
f.mainloop()


Thanks to @Gryphon for saving 2 bytes, to @Jonathan Allan for another one, and to @Challenger5 for five. Changed 1e-9 to .1 for another two.

• You can remove the space before the * to remove 2 bytes. – Gryphon - Reinstate Monica Jun 12 '17 at 0:13
• Welcome to PPCG! If I am reading it correctly (and the only references used are tkinter.Tk and two numpy.arrays) then import tkinter,numpy as n...f=tkinter.Tk()...p=n.array([1,1])...q=n.array([0.]*2) saves two. – Jonathan Allan Jun 12 '17 at 3:47
• There is Canvas from tkinter as well, so it only saves a byte, but thanks! – nore Jun 12 '17 at 4:09
• I don't have enough reputation to comment on the corresponding answer yet, but @Gryphon could save a few bytes by writing 4*(x>b)-2 in their solution. – nore Jun 12 '17 at 4:14
• You can put the body of r in a single line to save indentation: def r():d=p-q;u=(d*d.T+.1)**-0.5;c.move(z,*u*d);q[:]+=u*d;c.after(9,r) – Esolanging Fruit Jun 12 '17 at 5:42

# Python 2 + Pygame, 178 Bytes

-2 bytes thanks to @ASCII-only, because I was being an idiot

-12 bytes thanks to @officialaimm, also because I was being an idiot

-11 bytes thanks to @JonathanAllan, for telling me the default window size was the screen size

-2 bytes thanks to @WheatWizard, also because I was being an idiot

-18 bytes thanks to @nore, because I didn't have to use the if/else statements

-24 bytes thanks to @nore, who reminded me to put the whole loop on one line.

-42 bytes thanks to @WheatWizard

-3 bytes thanks to @ASCII-only

from pygame.locals import*
from pygame import*
init()
a=display.set_mode()
b=c=0
while 1:a.fill((0,0,0));x,y=mouse.get_pos();draw.rect(a,(9,9,9),
(b,c,b+10,c+10));display.update()


This is definitely no longer the best way to do this, so I may come out with a version that's better suited to the new requirements of the question. The dot is 10 pixels by 10 pixels. The screen size is the size of the computer screen. If you can see the dot, I'm impressed, as it is almost the exact same colour as the background, to save on byte counts for RGB colours.

• Noncompeting status is reserved for languages that were made after the challenge; however, I rolled back the OP's useless edits. – MD XF Jun 12 '17 at 0:15
• I'm assuming 100 pixels means 10x10 – ASCII-only Jun 12 '17 at 0:43
• You can strip off few bytes by using: b+=2if x>b else-2 for updating b & c both. – officialaimm Jun 12 '17 at 1:07
• @officialaimm, Ummm, where? I'm looking and I can't see anywhere where I can do that, but I'm sure I'm just being an idiot again. – Gryphon - Reinstate Monica Jun 12 '17 at 1:08
• BTW you should be able to change while True to while 1 – ASCII-only Jun 19 '17 at 11:56