我有一个使用绘制的窗口DirectX
,我需要单击非活动窗口中的某些坐标。
这怎么可能实现?
它可以很好地处理点击和输入pydirectinput
,但我找不到任何有关如何点击非活动窗口的信息。
更新:
Clickermann
它也可以处理任务,但仅限于活动窗口,并且不允许您在工作时使用鼠标。
我有一个使用绘制的窗口DirectX
,我需要单击非活动窗口中的某些坐标。
这怎么可能实现?
它可以很好地处理点击和输入pydirectinput
,但我找不到任何有关如何点击非活动窗口的信息。
更新:
Clickermann
它也可以处理任务,但仅限于活动窗口,并且不允许您在工作时使用鼠标。
通过 pip install 安装任何库时出现错误
这是 aiogram 的示例(这并不重要)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied'))': /simple/aiogram/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied'))': /simple/aiogram/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied'))': /simple/aiogram/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied'))': /simple/aiogram/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', PermissionError(13, 'Permission denied'))': /simple/aiogram/
ERROR: Could not find a version that satisfies the requirement aiogram (from versions: none)
ERROR: No matching distribution found for aiogram
如何修复它?我尝试使用不同的连接点,情况没有改变。
附加信息:
Windows 11 (22621.2134) Python 3.11.4 pip 23.2.11
您需要用细线在画布上绘制网格。我正在制作像素艺术画布。
我用了ctx.lineWidth = 0.1;
,然后网格就模糊了。模糊通过放大镜非常明显。当您在绘制网格时
添加偏移量时,一切都变得很好,但是它的边缘进入了图片,这是一个问题,因为单元格大小只有。0.5px
5х5px
为了使网格不会绘制在像素之上,我决定将绘图本身移动0.5px
。结果却是相反的效果——网格清晰漂亮,画面模糊不美观。
然后我决定在 Photoshop 中绘制一个网格,画布的大小(它是固定大小)并以这种方式放置网格会更容易。Photoshop 断然拒绝绘制较小的线条1px
(这是可以理解的),但我仍然决定看看会发生什么。结果,我们得到了一个均匀的网格,一个均匀的图像,但同时,每个像素现在不是5x5
,但是4х4
(谁会想到)
问题:如何用单元格绘制细网格5x5px
,以最小的线条粗细,使网格清晰且图像本身不变形?
网格无位移:
带偏移的网格,图像 - 无:
网格和偏移图像:
// Canvas с сеткой без смещения
var canvas = document.getElementById('example1');
var ctx = canvas.getContext('2d');
//Рисуем пиксели для наглядности
ctx.fillStyle = "yellow";
ctx.fillRect(20, 20, 5, 5);
ctx.fillRect(20, 30, 5, 5);
ctx.fillRect(30, 30, 5, 5);
//Задаём толщину линии и цвет
ctx.lineWidth = 0.1;
ctx.strokeStyle = "red"
// Рисуем вертикальные линии
for (var x = 0; x < canvas.width; x += 5) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
// Рисуем горизонтальные линии
for (var y = 0; y < canvas.height; y += 5) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvas.width, y);
ctx.stroke();
}
// Canvas с сеткой со смещением в 0.5
var canvas = document.getElementById('example2');
var ctx = canvas.getContext('2d');
//Рисуем пиксели для наглядности
ctx.fillStyle = "yellow";
ctx.fillRect(20, 20, 5, 5);
ctx.fillRect(20, 30, 5, 5);
ctx.fillRect(30, 30, 5, 5);
//Задаём толщину линии и цвет
ctx.lineWidth = 0.1;
ctx.strokeStyle = "red"
// Рисуем вертикальные линии
for (var x = 0.5; x < canvas.width; x += 5) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
// Рисуем горизонтальные линии
for (var y = 0.5; y < canvas.height; y += 5) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvas.width, y);
ctx.stroke();
}
// Canvas с сеткой со смещением в 0.5
var canvas = document.getElementById('example3');
var ctx = canvas.getContext('2d');
//Рисуем пиксели для наглядности
ctx.fillStyle = "yellow";
ctx.fillRect(20.5, 20.5, 5, 5);
ctx.fillRect(20.5, 30.5, 5, 5);
ctx.fillRect(30.5, 30.5, 5, 5);
//Задаём толщину линии и цвет
ctx.lineWidth = 0.1;
ctx.strokeStyle = "red"
// Рисуем вертикальные линии
for (var x = 0.5; x < canvas.width; x += 5) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
// Рисуем горизонтальные линии
for (var y = 0.5; y < canvas.height; y += 5) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvas.width, y);
ctx.stroke();
}
canvas{
background-color: lightgrey;
}
<p>Canvas с сеткой без смещения</p>
<canvas id="example1" width="100" height="100"></canvas>
<p>Canvas с сеткой со смещением в 0.5</p>
<canvas id="example2" width="100" height="100"></canvas>
<p>Canvas с сеткой со смещением в 0.5 и смещением изображения</p>
<canvas id="example3" width="100" height="100"></canvas>
任务是制作一个“屏幕放大镜”的类似物,以便在画布上使用它,您可以在画布上绘图。
保存的点是预先从数据库中加载的,并且需要增加它们。我对 Js 不是很强,所以我开始寻找现成的解决方案,但我发现只有使用图像、文本或画布中加载的静态图像的选项。
您能告诉我如何实施吗?
我想实现这样的目标,同时不使用图像,而仅使用预加载的点(它们是动态的)。
代码片段不是我的,取自codepen。
class Experience {
constructor(container) {
this.canvas = document.createElement("canvas");
container.appendChild(this.canvas);
this.context = this.canvas.getContext("2d");
const fps = 60;//60
this.fpsInterval = 1000 / fps;
this.then = Date.now();
this.point = { x: 0, y: 0 };
this.distPoint = { x: 0, y: 0 };
this.pos = { x: 0, y: 0 };
this.resize();
this.bind();
this.image = new Image();
this.image.src = "https://robindelaporte.fr/codepen/slide.jpg";
this.image.onload = () => {
this.loop();
};
}
bind() {
window.addEventListener("resize", this.resize.bind(this), false);
this.canvas.addEventListener("mousemove", this.onMouseMove.bind(this));
this.canvas.addEventListener("touchmove", this.onTouchMove.bind(this));
}
render() {
this.clear();
// this.context.save()
this.context.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height);
this.pos.x += (this.point.x - this.pos.x) * 0.2;
this.pos.y += (this.point.y - this.pos.y) * 0.2;
this.context.save();
this.context.beginPath();
this.context.arc(this.pos.x, this.pos.y, this.canvas.height * 0.15, 0, Math.PI * 2, true);
this.context.strokeStyle = "white";
this.context.lineWidth = 6;
// this.context.globalCompositeOperation = "screen";
this.context.stroke();
this.context.closePath();
this.context.clip();
this.context.drawImage(
this.image,
-this.canvas.width * 0.2 +
(this.canvas.width - this.canvas.width * 1.4) * (this.distPoint.x * 1), //0.05,
-this.canvas.height * 0.2 +
(this.canvas.height - this.canvas.height * 1.4) * (this.distPoint.y * 1), //0.05,
this.canvas.width * 1.4,
this.canvas.height * 1.4
);
// this.context.opacity = 1;
this.context.restore();
}
loop() {
this.raf = window.requestAnimationFrame(this.loop.bind(this));
const now = Date.now();
const delta = now - this.then;
if (delta > this.fpsInterval) {
// this.context.clearRect( 0, 0, this.canvas.width, this.canvas.height )
this.render();
this.then = now;
}
}
onMouseMove(ev){
var rect = this.canvas.getBoundingClientRect();
this.point = {
x:
(ev.clientX - 7) - rect.left,
y: (ev.clientY - 7) - rect.top
};
this.distPoint = {
x: (this.point.x - this.canvas.width * 0.5) / this.canvas.width,
y: (this.point.y - this.canvas.height * 0.5) / this.canvas.height
};
}
onTouchMove(ev){
var rect = this.canvas.getBoundingClientRect();
this.point = {
x:
ev.touches[0].clientX - rect.left,
y: ev.touches[0].clientY - rect.top
};
this.distPoint = {
x: (this.point.x - this.canvas.width * 0.5) / this.canvas.width,
y: (this.point.y - this.canvas.height * 0.5) / this.canvas.height
};
}
resize() {
this.canvas.width = window.innerWidth * 0.7;
this.canvas.height = window.innerWidth * 0.7 / 1.77;
this.screen = {
center: { x: this.canvas.width / 2, y: this.canvas.height / 2 }
};
//this.reset();
}
clear(){
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
reset() {
window.cancelAnimationFrame(this.raf);
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.loop();
}
}
const experience = new Experience(document.body);
body {
width: 100vw;
height: 100vh;
background: #fff;
margin: 0;
padding: 0;
position: relative;
overflow: hidden;
}
canvas {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 7px solid rgba(255, 255, 255, .1);
box-shadow: 0px 0px 10px #00000038;
cursor: pointer;
box-sizing: border-box;
}
.info {
position: absolute;
bottom: 1rem;
left: 0;
font-family: monospace;
width: 100%;
text-align: center;
font-size: 1rem;
}
在为我的任务编辑此代码时,我遇到了一个问题,此代码在画布本身上绘制放大镜并再次绘制图像,这不太适合数据库中的动态点(它们闪烁)
当前月份的每一天都有一组数据[0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0]
(一天一个值)。
如何QCalendaryWidget
以某种(例如红色)颜色为某个单元格着色?
日期兴趣上background-color
一个单元格t 的变化。QCalendaryWidge
例子:
a = [0,1,0,0,0,1,1,0,0,1,1,1,1,0,0]
i = 0
while i < len(a):
if (a[i] == 0):
print('Красим красным день i')
else:
print('Красим зелёным день i')
i += 1
pyQT 中日历小部件的事件是什么?就像按钮有一个 clicked() 事件。我不能谷歌它。