在我的应用程序中,我需要类似粒子系统的东西,所以我做了以下事情:
在应用程序初始化时,我加载了一个UIImage
laserImage = [UIImage imageNamed:@"laser.png"];
Run Code Online (Sandbox Code Playgroud)
UIImage*laserImage在我的控制器的接口中声明.现在每当我需要一个新粒子时,这个代码就会产生一个:
// add new Laserimage
UIImageView *newLaser = [[UIImageView alloc] initWithImage:laserImage];
[newLaser setTag:[model.lasers count]-9];
[newLaser setBounds:CGRectMake(0, 0, 17, 1)];
[newLaser setOpaque:YES];
[self.view addSubview:newLaser];
[newLaser release];
Run Code Online (Sandbox Code Playgroud)
请注意,图像只有17px*1px小而model.lasers是一个内部数组,用于完成从图形输出分离的所有计算.所以在我的主绘图循环中,我将所有UIImageView的位置设置为我的model.lasers数组中的计算位置:
for (int i = 0; i < [model.lasers count]; i++) {
[[self.view viewWithTag:i+10] setCenter:[[model.lasers objectAtIndex:i] pos]];
}
Run Code Online (Sandbox Code Playgroud)
我将标记增加10,因为默认值为0,我不想使用默认标记移动所有视图.
因此动画看起来很好,大约有10到20张图像,但在处理大约60张图像时确实很慢.所以我的问题是:有没有办法优化这一点而无需在OpenGl ES中重新开始?
我在列出可用的串口时遇到问题,我真的需要帮助调试这个.在Python 2.7.5中,正确列出了COM端口,而PySerial在Python 3.3.5中返回一个空列表.
我发现另一个孤独的灵魂在互联网上遇到同样的问题(没有答案),但这个问题似乎并不受欢迎 - 也许这是我的系统?
我正在使用Mac OS X 10.9.2并通过自制软件安装了python和python3.我刚才更新了一切.PySerial在pip和pip3都是2.7版本.
输出:
Python 2.7.5 (default, Nov 4 2013, 18:04:45)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from serial.tools import list_ports
>>> list_ports.comports()
[['/dev/cu.Bluetooth-Incoming-Port', 'n/a', 'n/a'], ['/dev/cu.Bluetooth-Modem', 'n/a', 'n/a']]
Python 3.3.5 (default, Mar 10 2014, 13:25:50)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from serial.tools import list_ports
>>> …Run Code Online (Sandbox Code Playgroud) 我想要实现的是将一个小的2D列表插入到一个大的列表中(我使用的是Python 2.7.3).
为什么我会得到不同的结果var1和var2?
def modify(foo):
small = [[1]*2]*2
for y, line in enumerate(small):
foo[y+1][1:3] = line
return foo
var1 = [[0]*4]*4
var2 = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
print modify(var1)
print modify(var2)
# Result:
# var1 = [
# [0, 1, 1, 0],
# [0, 1, 1, 0],
# [0, 1, 1, 0],
# [0, 1, 1, 0]]
#
# var2 = [
# …Run Code Online (Sandbox Code Playgroud) 您如何优雅地将具有未知数量元素的列表转换为用户界面的叙述文本表示?
例如:
>>> elements = ['fire', 'water', 'wind', 'earth']
>>> narrative_list(elements)
'fire, water, wind and earth'
Run Code Online (Sandbox Code Playgroud) 我想修补对象的exists()方法pathlib.Path以进行单元测试,但是我无法使它起作用。
我想做的是这样的:
from unittest.mock import patch
from pathlib import Path
def test_move_basic():
p = Path('~/test.py')
with patch.object(p, 'exists') as mock_exists:
mock_exists.return_value = True
Run Code Online (Sandbox Code Playgroud)
但是它失败了:
AttributeError: 'PosixPath' object attribute 'exists' is read-only。
有任何想法吗?
python ×3
iphone ×1
macos ×1
mocking ×1
nlp ×1
objective-c ×1
pathlib ×1
performance ×1
pyserial ×1
python-2.7 ×1
python-3.x ×1
string ×1
uiimageview ×1
unit-testing ×1