我正在努力做到这一点,所以在我的鼠标要移动的每个位置都会生成一个黑色圆圈,但我无法让它显示出来,我知道我正在接收输入,但我不知道为什么我的东西不是没有出现?是否有某种我缺少的重绘方法?我已经尝试了很多我不太明白如何requestAnimation
在这里工作的东西。
我究竟做错了什么?
import 'dart:html';
import 'dart:async';
import 'package:polymer/polymer.dart';
CanvasElement canvas = document.querySelector('#myPaintCanvas');
CanvasRenderingContext2D context = canvas.getContext('2d');
//circle deminsions
var centerX;
var centerY;
var radius = 15;
var PI = 3.14;
void requestRedraw(){
window.requestAnimationFrame(scribble());
}
void scribble(pointX, pointY){
print("MouseX: " + pointX.toString() + " MouseY: " + pointY.toString());
context.arc(pointX, pointY, radius, 0, 2 * PI, false);
context.fillStyle = 'black';
context.fill();
context.strokeStyle = '#003300';
context.stroke();
}
void main(){
canvas.onMouseDown.listen((onDown){
StreamSubscription mouseMoveStream = canvas.onMouseMove.listen((onData){
scribble(onData.client.x, onData.client.y);
});
//to end my stream when the mouse is up
canvas.onMouseUp.listen((onData) => mouseMoveStream.cancel());
});
}