TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: My latest pet project, pydroid

109 点作者 meese_超过 15 年前

15 条评论

hugs超过 15 年前
I love it, except for the project name. I was thinking it was going to be another "Run Python on Android" project.
评论 #1043648 未加载
评论 #1043982 未加载
评论 #1043557 未加载
ZitchDog超过 15 年前
I'm loving this library. I'm having a ton of fun messing around with it.<p>Here's a script to play basketball at <a href="http://www.onlinegames.com/basketball" rel="nofollow">http://www.onlinegames.com/basketball</a><p>I'm having trouble getting calculate_shot_pos right given the ball pos and basketball pos. My trig is pretty rusty, so if anyone wants to help me out (even with some strategy) I would love to hear it! I've learned the library, so getting it to actually play the game well is just a bonus.<p>Anyway, here goes:<p><pre><code> from pydroid import mouse, bitmap from math import floor, sqrt import time rim_color = 15474 ball_color = 10440243 basket_pos = (143, 365) def is_ball_on_screen(screen): return len(screen.find_every_color(ball_color)) &#62; 0 and find_ball_pos(screen)[0] &#62; basket_pos[0] def is_basket_on_screen(screen): return screen.get_color(basket_pos[0], basket_pos[1]) == rim_color def average(xs): return int(sum(xs, 0.0) / len(xs)) def find_ball_pos(screen): coords = screen.find_every_color(ball_color) xs = [coord[0] for coord in coords] ys = [coord[1] for coord in coords] return (average(xs), average(ys)) def calculate_shot_pos(basket, ball): x = basket[0] + (ball[0] - basket[0]) / 3.0 y = basket[1] - (ball[1] - basket[1]) return (int(x), int(y)) while(True): screen = bitmap.capture_screen() if is_basket_on_screen(screen) and is_ball_on_screen(screen): ball_pos = find_ball_pos(screen) shot_pos = calculate_shot_pos(basket_pos, ball_pos) mouse.move(shot_pos[0], shot_pos[1]) time.sleep(.5) mouse.click() time.sleep(1)</code></pre>
m0th87超过 15 年前
Script to play Winterbells (<a href="http://www.ferryhalim.com/orisinal/g3/bells.htm" rel="nofollow">http://www.ferryhalim.com/orisinal/g3/bells.htm</a>) based on pydroid:<p><pre><code> import pydroid INIT_COLOR = 473428 BELL_COLORS = set([12702690, 8950940, 9016477, 9017249, 9018536, 12505567, 12505568, 11715538, 10862803, 12965603, 12439776, 12834019, 14411502, 8953000, 5401724]) def find_init_color(screen, xr, yr): for x in xr: for y in yr: if screen.get_color(x, y) == INIT_COLOR: return (x, y) def init(): while True: screen = pydroid.bitmap.capture_screen() first = find_init_color(screen, xrange(0, screen.width), xrange(0, screen.height)) last = find_init_color(screen, xrange(screen.width - 1, -1, -1), xrange(screen.height - 1, -1, -1)) if first is not None and last is not None: return first, last def check(first, last): screen = pydroid.bitmap.capture_screen() for y in xrange(last[1] - 1, first[1], -1): for x in xrange(first[0] + 1, last[0]): if screen.get_color(x, y) in BELL_COLORS: return pydroid.mouse.move(x, y) def main(): print 'Searching for Winterbells...' first, last = init() print 'Found at %s, %s. Running.' % (first, last) while True: check(first, last) if __name__ == '__main__': main() </code></pre> It's far from perfect, but it's a good start. To run it, execute the script, then open the game in a resolution large enough such that the whole game is visible.<p>All it does is find pixels with colors unique to the bells and moves the mouse there. I made the same script in C# a while ago. This script is faster (even though it's Python!) and far more concise. It was astonishingly easy to make too thanks to pydroid. The only time-consuming bit was finding the bell colors. Kudos for the nice library!
评论 #1043978 未加载
meese_超过 15 年前
"The prize is the pleasure of finding the thing out, the kick in the discovery, the observation that other people use it. Those are the real things." — Richard Feynman<p>:)
csytan超过 15 年前
This sounds like it would be very useful for writing a poker bot.
评论 #1044954 未加载
ehsanul超过 15 年前
This reminds me of how I started "programming", making bots for online text-based mmorpgs with AutoIt V3 (<a href="http://www.autoitscript.com/" rel="nofollow">http://www.autoitscript.com/</a>), automating IE. That was a great introduction to programming for me, very simple language with useful functions and great help files. Since I switched to using Linux, I've been trying to find a Linux equivalent. Of course, a general programming language with an http library could be used to do what I was initially doing with AutoIt, but it's kind of fun to see windows being manipulated and the mouse moving, keyboard text being sent out, like a ghost user.<p>AutoPy gives me an excuse to learn python too. Totally sweet.
pizza超过 15 年前
It looks great. I have a slight issue, though; whenever I try to import pydroid, it goes<p><pre><code> Traceback (most recent call last): File "&#60;pyshell#0&#62;", line 1, in &#60;module&#62; import pydroid File "C:\Python26\lib\site-packages\pydroid\__init__.py", line 8, in &#60;module&#62; import pydroid.bitmap ImportError: DLL load failed: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail.</code></pre>
评论 #1043841 未加载
评论 #1043840 未加载
wensing超过 15 年前
I've been trying to figure out a way to automatically do screen captures of the Stormpulse map at various intervals. Being able to use Python ... perfect. Thank you.
sili超过 15 年前
Sounds very interesting. I'm going to try writing some simple tests for my application.<p>On a side-note, the name sounds a little inapropriate in Russian.
评论 #1043971 未加载
gridspy超过 15 年前
To use this to script applications there could be a few useful wrappers -<p>For example: - Enumerate open windows (with names from title of each) - Get xy coords, height + width - Enumerate controls that windows knows about and their locations
bob647超过 15 年前
The bitmap matching really sucks though. It won't match images that have been taken straight from larger images.
ciupicri超过 15 年前
How about some distutils/setuptools based packaging? Or a RPM spec file?
Oranj超过 15 年前
You are my favorite person today.
BearOfNH超过 15 年前
Doesn't seem to work on Python 2.5.x under WinXP. I get the DLL load failure message "This application has failed to start because python26.dll was not found."<p>The installer was happy finding Python 2.5.<p>Oh well, I should probably upgrade to 2.6 anyway ...
dustingetz超过 15 年前
um, <a href="http://www.autohotkey.com/" rel="nofollow">http://www.autohotkey.com/</a> ?<p>it doesn't matter if your scripts are cross platform when the apps they script aren't.
评论 #1043770 未加载