我在body onmousemove
函数上使用这个脚本:
function lineDraw() {
// Get the context and the canvas:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// Clear the last canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the line:
context.moveTo(0, 0);
context.lineTo(event.clientX, event.clientY);
context.stroke();
}
Run Code Online (Sandbox Code Playgroud)
每次我移动鼠标时都应该清除画布,然后绘制一条新线,但它不能正常工作.我试图在不使用jQuery,鼠标监听器或类似工具的情况下解决它.
这是一个演示:https://jsfiddle.net/0y4wf31k/
我具有以下Python函数来递归查找集合的所有分区:
def partitions(set_):
if not set_:
yield []
return
for i in xrange(2**len(set_)/2):
parts = [set(), set()]
for item in set_:
parts[i&1].add(item)
i >>= 1
for b in partitions(parts[1]):
yield [parts[0]]+b
for p in partitions(["a", "b", "c", "d"]):
print(p)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我将其翻译成Java吗?这是我到目前为止的内容:
private static List<List<List<String>>> partitions(List<String> inputSet) {
List<List<List<String>>> res = Lists.newArrayList();
if (inputSet.size() == 0) {
List<List<String>> empty = Lists.newArrayList();
res.add(empty);
return res;
}
int limit = (int)(Math.pow(2, inputSet.size())/2);
for (int i = 0; i<limit; i++) {
List<List<String>> parts = Lists.newArrayList(); …
Run Code Online (Sandbox Code Playgroud)