抱歉这个糟糕的头衔.Java applet的目的是这样的:一个球在屏幕上弹跳.这个球的大小和速度可以通过滚动条改变.用户可以在屏幕上按下并拖动鼠标以绘制矩形.球也将从这些矩形反弹.这些矩形的边界存储在矢量中.单击矩形时,将从矢量(和屏幕)中删除它(以及该点处的所有其他矩形).
我遇到的问题有两个:一,当我点击一个矩形去除它时,它不会被删除,但这可以在以后解决.
二:球不会像它应该的那样从矩形反弹.当我在与球相同的行或列中绘制一个矩形时,球会在一个小矩形内部反弹,就像它被卡住一样.
这是我的代码,用于检测球是否正在击中小程序或任何矩形的边界:
public void move()
{
//if it will hit the right or left boundary, flip the x direction and set it
if (loc.x+size >= boundx || loc.x <= 0)
{ dx *= -1; }
//if it will hit the top or bottom boundray, flip the y direction and set it
if (loc.y+size >= boundy || loc.y <= 0)
{ dy *= -1; }
for (int i = 0; i < r.size(); i++)
{
temp = new …Run Code Online (Sandbox Code Playgroud) 我是python的新手。有人能告诉我如何检查一个小矩形(带有两个坐标)是否在 Python 中的另一个矩形(带有两个坐标)内。
我试图在面向检测算法定位面的位置绘制矩形.我想使用alpha透明度来绘制我的矩形.我已经OpenCV的文档中发现了以下这里:注意功能不支持alpha透明度当目标图像是4通道.在这种情况下,颜色[3]被简单地复制到重新绘制的像素.因此,如果要绘制半透明形状,可以将它们绘制在单独的缓冲区中,然后将其与主图像混合.
如何将主图像与缓冲图像混合?什么是缓冲图像的确切含义?
最小的工作示例:
x = pygame.draw.circle(screen, color, (x, y), radius, width)
x.center = (my_wanted_center_x, my_wanted_center_y)
Run Code Online (Sandbox Code Playgroud)
然后在更新显示后,它始终显示在其原始位置.也尝试过其他数据.也没有用x.move().如何以最简单的方式移动任何绘制的图形?
我想知道是否可以为每个数据点附加多个矩形。在我的示例中,有三个数据点。对于每个我尝试创建 2 个矩形。最后必须有6个矩形。3个红色,3个蓝色。 图片
根据这个答案,我尝试了以下解决方案:
var svg = d3.select("body").append("svg");
svg.selectAll("rect")
.data([10,60,120])
.enter()
.append("g")
.append("rect")
.attr("width", 20)
.attr("height", 20)
.attr("x", 20)
.attr("y", function(d) {return d})
.attr("fill", "red")
.selectAll("rect")
.data(function(d) { return d3.range(d); })
.enter()
.append("rect")
.attr("width", 20)
.attr("height", 20)
.attr("x", 60)
.attr("y", function(d) {return d})
.attr("fill", "blue");
Run Code Online (Sandbox Code Playgroud)
不幸的是,蓝色矩形是在红色矩形内创建的。知道如何实现这一目标吗?这是一个例子
我试图让用户使用鼠标在画布上绘制矩形,并且我已经能够在一定程度上使其工作。用户可以使用鼠标绘制矩形,但它仅在 mouseup 事件之后显示,但我也希望用户在鼠标移动事件上绘制矩形时也能看到矩形。我怎样才能实现这一点,同时让用户绘制多个当前有效的矩形,但我希望他们在绘制矩形时看到它。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
#container {
/*background-color: lime;*/
width: 150px;
height: 150px;
cursor: pointer;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
#heatmapContainer {
border: 1px solid red;
}
</style>
</head>
<body>
<div class="heatmapWrapper">
<div id="heatmapContainer" style="height: 4205px; width: 1278px">
<div id="heatmap1" class="heatmapTile" style="height: 4205px; position: relative">
<canvas …Run Code Online (Sandbox Code Playgroud)def xaxis(event):
x1, y1 = (event.x - 1), (event.y - 1)
def yaxis(event):
x2, y2 = (event.x + 1), (event.y + 1)
def create(event):
w.create_rectangle(x1,y1,x2,y2,fill='Black')
w = Canvas(root, width=canvas_width, height=canvas_height)
w.config(cursor='cross')
w.pack(expand=YES, fill=BOTH)
w.bind("<Button-1>", xaxis)
w.bind("<ButtonRelease-1>", yaxis)
w.bind("<ButtonRelease-1>", create)
Run Code Online (Sandbox Code Playgroud)
壳说
Tkinter回调中的异常回溯(最近一次调用最后一次):
文件"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py",第1410行,在call return self中. func(*args)文件"/Users/Leo/Desktop/draw.py",第22行,创建w.create_rectangle(x1,y1,x2,y2,fill ='Black')NameError:全局名称'x1'是没有定义的
它认为创建函数无法获取其他函数的坐标...
我是这样做的,因为我以后需要坐标!
我希望你能帮帮我.. ;-)谢谢!
我正在爆炸.爆炸应该击中它的矩形内的所有敌人(x,y,x + w,y + h).爆炸和敌人都继承自Sprite类,该类具有返回其矩形的getBounds()方法.当我在构造函数中创建爆炸项目时,我会通过敌人来检查矩形是否与rectangle.intersects(rectangle2)相交.但似乎当有多个目标被支持相交时,检查会忽略其中一些......
这是som代码:在Explosion类的构造函数中,继承类Sprite
List<Zombie> zombies = mGamePlay.getZombieHandeler().getZombies();
Rect r = getBounds();
for(int i = 0; i < zombies.size(); i++)
{
Rect zR = zombies.get(i).getAnimation().getBounds();
if(!zombies.get(i).isDead() && r.intersect(zR))
zombies.get(i).doDamage(new int[]{damage, 0, 0});
}
Run Code Online (Sandbox Code Playgroud)
内部类Sprite:
public Rect getBounds()
{
return new Rect(mPosX, mPosY, mPosX + mWidth, mPosY + mHeight);
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个游戏,它需要无限数量的矩形.例如,假设我将变量命名为car:
public Rectangle car1;
public Rectangle car2;
public Rectangle car3;
Run Code Online (Sandbox Code Playgroud)
等等,
会有更简单的方法吗?喜欢:
public int carNumber;
public Rectange car + carNumber;//if carNumber was one, it would be called car1
Run Code Online (Sandbox Code Playgroud)
另外,我需要测试矩形是否包含其他矩形.< - 我知道怎么做.
在PyQt标签上显示图像后,我想在显示的图像上方绘制一个矩形。请注意,我并不是说“绘制”是指用户在图像上“绘制”矩形的地方,而是我只想在图像顶部创建一个矩形。我有matplotlib轴的等效代码,但我不确定如何在PyQt中执行相同的操作。
# Create Figure/Axes Instance
figure,axes = matplotlib.pyplot.subplots()
axes.imshow(imageRGB)
# Draw Rectangle
axes.add_patch(matplotlib.patches.Rectangle((50,50),100,100,fill=False,edgecolor='red'))
Run Code Online (Sandbox Code Playgroud) rectangles ×10
python ×4
java ×3
drawing ×2
javascript ×2
android ×1
append ×1
applet ×1
c++ ×1
d3.js ×1
draw ×1
html5-canvas ×1
infinite ×1
intersection ×1
label ×1
mouseevent ×1
opencv ×1
pygame ×1
pyqt ×1
tkinter ×1
variables ×1