Python move to in-game X and Y? - python-3.x

I started Python a couple of weeks ago and I’d like to write a program that would be useful to myself.
I play a game that displays the in game X and Y (which is not the same as the screen X and Y)
I believe I know what to do but don’t know ‘how’ to do it.
I want to be able to type in X and Y coordinates and have the mouse direct me to said spot, I imagine I’d need a memory address of the in game coords and if statements to compare the user input to the current one in memory then move mouse and click in the appropriate direction?
Could someone provide an example that I can study or guide me to something made for this purpose?
Many thanks!

This can be done using pynput, a cross-platform python module that can set the mouse position, as well as checking what it is at any given time. Examples are on the other side of the link.

Related

Odd behaviour in gravity from different directions matter js phaser 3

I'm making a platformer game, in which I have a powerup that lets you fly. On collision, I removed the powerup using powerup.gameObject.destroy() and disabled gravity using player.setIgnoreGravity(true). Now when I touch the powerup from different directions, it produces a different result like shown below.
Here's a minimal example: https://jsfiddle.net/prateek_1/rsoj0h2z/
Any help is greatly appreciated. Thanks!
Well the code works as it should, here is why:
Scenario 1)
you touch the powerup while not touching the platform (playertouchingground==false) -> no gravity, and the player doesn't fall to the ground. AND because the player is in the air you can't jump.
Scenario 2)
you touch the powerup while touching the platform (playertouchingground==true) -> no gravity, now you can jump, and when you jump you fly away, since nothing is "pulling" the player down.
The question is, what do you want to happen, when the objects collide?

How to program moving a robot(e-puck) to the specific position?

I'm newbie in programming world especially in webots.
Do you guys have any ideas/tutorial to move e-puck robot to a specific position in webots?
In my case, I'm trying to move the e-puck robot to the start position and when the robot finish performing wall following behavior, it will stop at the same position as start.
I'm searching for the ideas/tutorial to solve the problem, but in the end, I'm stuck. Can anyone help me?
Thank you.
I recommend you to take a look at the e-puck curriculum for Webots, particularly at the advanced part:
http://en.wikibooks.org/wiki/Cyberbotics%27_Robot_Curriculum/Advanced_Programming_Exercises
The idea is the following: if you would like to do this in real conditions, implementing the odometry of the robot is a first step. A "goto" function based on the odometry would be the second step. The link contains information about this.
Ultimately, taking care of the other sensors (distance sensors, etc.) is the best solution, but it requires to do "SLAM". In this case, you can link your controller with a SLAM library (e.g. gmapping or Karto):
http://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping
If you don't care about realism, you can get the absolute coordinates of the robot (using a Supervisor, or a GPS+Compass device). Writing a "goto" function on this is trivial.

How do I make smooth curves for a CNC?

I making an Arduino-based X-Y laser cutter. I've built the mechanics for it and accomplished basic motion, but I am having trouble getting it to plot lines and curves. I eventually want to be able to convert SVG or Illustrator files to Gcode or have the Arduino interpret and plot them directly
A picture of my setup.
There are libraries like GRBL and Rstepper that provide 2-wire (step and direction) instructions based on Gcode. The problems is that I'm driving two stepper motors using ULN2003 chips, which use 4 wires to step through the phases of the motor.
Could I make either of these libraries work for 4-wire control?
If not, I will need to find another way to plot my designs.
How I'm currently thinking of making functions for SVG or G-code style instructions.
//given a new position to go to and how we want to get there (i.e. curves)
for (i=0;xposition!==newx;i++) //run until x gets to the right spot
{
//get the values for X, Y, NewX, NewY, and any other parameters (e.g. for curves)
//figure out how many steps (say, +1 or -1) x should take for cycle number i
//figure out how many steps y should move given new x
//make the x stepper step the right number of steps
//make the y stepper step the right number of steps
//delay (control speed for adequate laser burning & don't make the steppers angry)
}
Will that be too slow?
Having been down this road and wasted much time, I would strongly suggest that you just get a couple of Easy Drivers for $15-$20 ea. and move on with your project using GRBL. It is a great library and there is a nice Java-based open source laser cutter front end project called Visicut. Visicut can handle either SVG files or gcode.
If you must use the chips you have, the Connecting Grbl pages lists this site Driving stepper motor using ULN2003 but cautions: "It is out-dated and uses Grbl v0.7."
(But seriously, hardware choices because "that is what one has" rather than what might be easier to implement can really suck the joy out of a fun hacker project like you have going)
I might be late, but there are a few modified versions of GRBL that support unipolars now. Here are the links:
https://github.com/TGit-Tech/GRBL-28byj-48
https://github.com/ruizivo/GRBL-28byj-48-Servo (this one didn't work when I tried it but it might work on your setup)
Note that in my testing the x/y axis invert messed everything up. It might be because I'm using a coreXY setup though.

Getting Mouse Coordinates in Gloss(Haskell)

I am trying to implement drag-and-drop functionality into a haskell gloss (scheduling) program of mine, but to do that I need to be able to read the coordinates of the mouse. I have been researching how to do this for multiple hours and am coming up empty, except for the fact that it is possible in GLUT, which gloss is based off of, but going that deep is over my head.
I was wondering if there is already some way to do this in gloss, and if not, what library should I switch to?
Thank you in advance!
For your serve function you'll want to handle an event such as:
serveWorld (EventKey (MouseButton LeftButton) Down xPos yPos) world = ...
Or perhaps you don't want to look for buttons but instead just motion? In that case serveWorld should handle EventMotion.
You might want to look at the gloss-draw example program, which is in the gloss-examples package.

x86 assembly practice about graphics

I'm trying to answer this practice question:
Write a code segment that draws an X on the whole screen, using XGA frame buffers.
All i know is that you have to increment each x and y pixel by 1 to get a diagonal line.
If you are looking for resources on how to accomplish the drawing, you can look at this, this or this (if you like really bright colored text...). however, the point of a practice question (or homework) is for one to do ones own research.

Resources