标签: rect

在pygame中将矩形转换为曲面

在我的代码中它不断给我错误:

pygame.surface.Surface.blit(a, (x1, y1))

类型错误:描述符“blit”需要“pygame.Surface”对象,但收到“pygame.Rect”。

帮助!

这是我的代码:

import pygame
import time

pygame.init()

screen = pygame.display.set_mode()

display_width = 1366
display_height = 768

white = (255,255,255)
red = (255,0,0)
green = (0,255,0)

gameDisplay = pygame.display.set_mode((display_width,display_height))
clock = pygame.time.Clock()

global x1
global y1
global x2
global y2

x1 = 683
y1 = 384
x2 = 0
y2 = 500


def game():
    y1 = 384
    gameDisplay.fill(white)
    a = pygame.draw.rect(gameDisplay, red, (x1,y1,250,250), 0)
    b = pygame.draw.rect(gameDisplay, green, (x2,y2,100,100), 0)
    pygame.display.update()
    gameStart = True
    while gameStart …
Run Code Online (Sandbox Code Playgroud)

python pygame surface rect blit

6
推荐指数
1
解决办法
1万
查看次数

Python的rect类发生了什么?

在Google搜索上,我发现了这篇文章:

http://docs.python.org/release/1.4/lib/node201.html

其中显示了使用rect类的示例,执行union/intersection /检查点是否在rect内.在Python 2.7中导入rect失败.这个班是在另一个包吗?

python rect

5
推荐指数
1
解决办法
3313
查看次数

更改选择突出显示的高度

有没有办法改变文本选择突出显示的高度而不改变line-height包含它的元素的高度?

谢谢。

javascript css range rect selection

5
推荐指数
1
解决办法
834
查看次数

是否可以在svg矩形中设置负宽度?

我想基于鼠标移动移动矩形.请参考以下链接.

http://atomicrobotdesign.com/blog_media/draw/draw1.html

在mousedown事件中获取矩形起始位置并开始拖动它将在鼠标移动事件中创建矩形.但是当我移动到先前的值(即移动到小于鼠标按下值时,它将返回负值),因此宽度变为负值.

上面的链接是画布矩形.但我创建了具有相同逻辑的svg矩形.

不支持矩形的负宽度?或者如何根据鼠标移动移动矩形?

什么出错了?

我的代码片段.

ChartMouseDown:function(e){

//       e = this.normalizeMouseEvent(e);


      var mousedownCords=this.calMousePosition(e);
      this.mouseDownX=mousedownCords.X;
      this.mouseDownY=mousedownCords.Y;

      this.chartMouseDownPoint= this.GetValuebyPoint(Math.abs(this.mouseDownX-this.model.m_AreaBounds.X),Math.abs(this.mouseDownY-(this.model.m_AreaBounds.Y + this.model.m_AreaBounds.Height)));
      this.zoomingX=true;

    },



ChartMouseMove: function (evt) {

    if( this.zoomingX)
    {

    var mouseMoveX,mouseMoveY;

     var mouseMoveCords=this.calMousePosition(evt);
      mouseMoveX=mouseMoveCords.X;
      mouseMoveY=mouseMoveCords.Y;
      $(this.ZoomAreaRect).remove();
      var width =  Math.abs(mouseMoveX - this.mouseDownX);
      var height = mouseMoveY - this.mouseDownY;
      var x;
      if(mouseMoveX > this.mouseDownX)
      x= this.mouseDownX;
      else
      x= mouseMoveX;

       this.ZoomAreaRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");

        $(this.ZoomAreaRect).attr({
            'id': 'ZoomArea', 'x': x, 'y': this.model.m_AreaBounds.Y, 'width': width, 'height': this.model.m_AreaBounds.Height,
            'fill': 'gray', 'stroke-width': 1, 'stroke':'gray'
        });

       $(this.ZoomAreaRect).appendTo(this.SvgObject); …
Run Code Online (Sandbox Code Playgroud)

svg rect jquery-svg

5
推荐指数
1
解决办法
4539
查看次数

Pygame 在碰撞检测时停止移动

我本质上是想用 pygame 制作一个“实体”对象。目标是在玩家接触时将其击退。我目前正在使用的(但无法正常工作)如下:

keys_pressed = pygame.key.get_pressed()
if 1 in keys_pressed:
    if keys_pressed[K_w]:
        self.player_l[1] += -2
        if self.player_r.colliderect(self.tower_r): self.player_l[1] -= -2
    if keys_pressed[K_a]:
        self.player_l[0] += -2
        if self.player_r.colliderect(self.tower_r): self.player_l[0] -= -2
    if keys_pressed[K_s]:
        self.player_l[1] += 2
        if self.player_r.colliderect(self.tower_r): self.player_l[1] -= 2
    if keys_pressed[K_d]:
        self.player_l[0] += 2
        if self.player_r.colliderect(self.tower_r): self.player_l[0] -= 2
Run Code Online (Sandbox Code Playgroud)

这样做的问题是,玩家被“卡”在塔楼矩形内,尽管返回到碰撞开始之前所在的位置,但玩家矩形将始终被拉回到塔楼中,并且碰撞将继续进行。扳机。最初接触塔矩形后,玩家将无法向任何方向移动。

python pygame rect

5
推荐指数
1
解决办法
4699
查看次数

DPI识别和Rect

我遇到了一个小问题,我似乎无法找到答案.我有一个应用程序,它获取某些进程并获取它的窗口大小.唯一的问题是需要一定百分比的实际屏幕尺寸(用户看到).

我想制作一个应用程序的屏幕截图,但是如果我使用窗口的Rect我得到的屏幕比它小,因为resolotion是125%.这意味着我输出的原始分辨率(1280 * 800)小于我的屏幕分辨率(1600 * 1000)你可以理解这个小的打嗝让我的程序不可靠.我的问题是如何解决这个问题?

我创建了一个我设置DPIAware为true 的清单.我还在调试中禁用了Visual Studio主机.但它没有帮助.我仍然得到相同的值和相同的问题.这是我的实际屏幕截图的代码片段:

RECT Rect = new RECT();
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("Process");
ShowWindow(p[0].MainWindowHandle, 9);
SetForegroundWindow(p[0].MainWindowHandle);

if (GetWindowRect(p[0].MainWindowHandle, ref Rect))
{
    var bmp = new Bitmap(Rect.Width, Rect.Height);
    var graphics = Graphics.FromImage(bmp);
    graphics.CopyFromScreen(Rect.Left, Rect.Top, 0, 0, new Size(Rect.Width, Rect.Height), CopyPixelOperation.SourceCopy);
    bmp.Save(@"C:\Screenshots\temp1.png");
}
Run Code Online (Sandbox Code Playgroud)

这给了我一个屏幕截图1280 * 800,不足以涵盖整个过程,这是1600 * 1000.一切都因为屏幕坐标不对而关闭.如果我将所有内容乘以1,25就可以了,但这不是解决方案,因为我不知道其他PC上的DPI设置是什么.

编辑3:

我将在其中发布包含RECT的完整代码.

RECT Rect = new RECT();
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("LoLPatcherUx");
ShowWindow(p[0].MainWindowHandle, 9);
SetForegroundWindow(p[0].MainWindowHandle);

if (GetWindowRect(p[0].MainWindowHandle, ref Rect))
{ …
Run Code Online (Sandbox Code Playgroud)

c# screenshot bitmap rect dpi-aware

5
推荐指数
1
解决办法
1877
查看次数

pygame rect碰撞小于图像

如何在pygame中定义小于图像的矩形碰撞检测?我想要像第二个图像那样的碰撞模式,但是当我尝试在方法 rect 中设置宽度和高度时,我有一个剪切图像。

在此处输入图片说明

当我尝试使用图像大小进行设置时,碰撞检测显示为红色

    self.rect = pygame.rect.Rect(location, self.image.get_size())
Run Code Online (Sandbox Code Playgroud)

如果我使用宽度和高度设置大小,我只有第三张图片

    self.rect = pygame.rect.Rect(location, (32, 150))
Run Code Online (Sandbox Code Playgroud)

我真的不喜欢使用像素完美碰撞,因为它是最慢的碰撞检测,所以有人知道如何使用 Rect 实现第二种图像碰撞方法?谢谢。

python pygame image rect collision

5
推荐指数
1
解决办法
2123
查看次数

如何在R中的矩形中包装文本

我正在对数据集执行相当复杂和长时间的统计分析,其中一个最终输出是具有居中标签的8个彩色正方形的组.颜色和标签都取决于分析结果,其中许多都是生产的,必须定期更新,因此不能手动编辑.正方形是2x2 cm2,在某些情况下,标签不适合正方形.如果我用cex减小字体大小,文本会变得太小.

这是一个简单的问题示例(我使用RStudio):

plot.new()
plot.window(xlim=c(0,5),ylim=c(0,5))
rect(1,1,4,4)
text(2,2,"This is a long text that should fit in the rectangle")
Run Code Online (Sandbox Code Playgroud)

问题是:如何在矩形中自动拟合变长字符串,如下图所示?

plot.new()
plot.window(xlim=c(0,5),ylim=c(0,5)) # Window covers whole plot space
rect(1,1,4,4)
text(2.5,3,"This is a long text")
text(2.5,2.5,"that should fit")
text(2.5,2,"in the rectangle")
Run Code Online (Sandbox Code Playgroud)

text r rect

5
推荐指数
1
解决办法
516
查看次数

将 YUP 与 Material-UI TextField 结合使用

我正在尝试将表单转换为使用 Material-ui TextField。我如何让我的 YUP 验证与之配合使用?这是我的代码:

import * as React from "react";
import { useState } from 'react';
import { Row, Col } from "react-bootstrap";
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import { Formik, Form, Field, ErrorMessage } from "formik";
import * as Yup from "yup";
import axios from "axios";

import Error from "../../Error";

type FormValues = {
  username: string;
  password: string;
  repeatPassword: string;
  fullName: string;
  country: string;
  email: string;
};

export default function CreatePrivateUserForm(props: any) {

  const [errorMessage, …
Run Code Online (Sandbox Code Playgroud)

rect material-ui yup formik

5
推荐指数
1
解决办法
1万
查看次数

带圆角的 Pygame 按钮,border_radius 参数不起作用

我目前正在学习pygame。在编写带圆角的矩形时,我遇到了一个问题。

pygame.draw.rect() 绘制一个矩形 rect(surface, color, rect) -> Rect rect(surface, color, rect, width=0, border_radius=0, border_radius=-1, border_top_left_radius=-1, border_top_right_radius=- 1, border_bottom_left_radius=-1) -> 矩形 在给定的表面上绘制一个矩形。

border_radius (int) -- (可选)用于绘制圆角矩形。支持的范围是[0, min(height, width) / 2],其中0代表没有圆角的矩形。

这是pygame官方文档的描述。

username_rect = pg.rect.Rect(screenwidth/2 - 1/8*screenwidth, screenheight*1/5, 1/4*screenwidth, username_title_render.get_height() + 10)
pg.draw.rect(screen, (0,0,0), username_rect,border_radius = 15)
Run Code Online (Sandbox Code Playgroud)

这里是主要部分。但随后我收到此错误消息:

TypeError: 'border_radius' is an invalid keyword argument for this function
Run Code Online (Sandbox Code Playgroud)

我已经尝试添加“width=2”参数,但随后它说参数太多。不幸的是,获取其他数字也无济于事。我目前使用 pygame 版本 2.0.0.dev6 (SDL 2.0.10,python 3.8.1)

如果您能帮助我,我将非常高兴,非常感谢!

python pygame rect rounded-corners

5
推荐指数
1
解决办法
8302
查看次数