我正在使用Tampermonkey(与Greasemonkey相同,但对于Chrome)来制作脚本.我的想法是将我写的文本粘贴到Pastebin中.该文本写在其他网站上.我看到我可以使用GM_xmlhttpRequest来完成它,但它不起作用.这是我的代码:
var charac = new Array(50);
var i =0
function callkeydownhandler(evnt) {
var ev = (evnt) ? evnt : event;
var code=(ev.which) ? ev.which : event.keyCode;
charac[i]= code;
i++;
}
if (window.document.addEventListener) {
window.document.addEventListener("keydown", callkeydownhandler, false);
} else {
window.document.attachEvent("onkeydown", callkeydownhandler);
}
GM_xmlhttpRequest({
method: "POST",
url: "http://pastebin.com/post.php",
data: "user=mysuser&password=mypassword", //as you can imagine I use my credentials
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response) {
alert("posted");
document.getElementById("paste_code").value+=charac[i];
document.getElementById("submit").click();
}
});
Run Code Online (Sandbox Code Playgroud)
我确定最后两行不能正常工作,但我不知道为什么.第一个功能完美.
我做得不好?我该如何解决?
谢谢!=)
我有一个方形格子,尺寸为LxL。在这个格子中,我可以使用经典的 4 邻域网格或 8 邻域格子(还包括对角线)。
(i1,j1)给定晶格和上两点的坐标(i2,j2),我想计算 4 邻域网格和 8 邻域网格中它们之间的距离,同时考虑周期性边界条件。
对于 4 邻点情况,没有周期性边界条件,距离为曼哈顿距离d=|i1-i2|+|j1-j2|。如果我想考虑周期性边界,我可以多次计算距离(例如改变(i2,j2))(i2,j2-L)并取最小值,但我确信有一种更有效的方法来做到这一点。
关于 8-neighbor 的情况,我发现了这个问题:Calculate distance on a grid Between 2 point (在我的例子中,我将替换sqrt(2)为 1),但它并不能解决边界条件的问题。
关于如何计算这些距离的任何伪代码?越快越好。
我有一个与时间相关的矩阵,我想将演变绘制为动画。
我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
n_frames = 3 #Numero de ficheros que hemos generado
data = np.empty(n_frames, dtype=object) #Almacena los datos
#Leer todos los datos
for k in range(n_frames):
data[k] = np.loadtxt("frame"+str(k))
fig = plt.figure()
plot =plt.matshow(data[0])
def init():
plot.set_data(data[0])
return plot
def update(j):
plot.set_data(data[j])
return [plot]
anim = FuncAnimation(fig, update, init_func = init, frames=n_frames, interval = 30, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,我总是收到以下错误:draw_artist can only be used after an initial draw which …
animation ×1
distance ×1
greasemonkey ×1
javascript ×1
math ×1
matplotlib ×1
pastebin ×1
python ×1
tampermonkey ×1