I have created a nice pattern using the following one line code
repeat 36 [repeat 10[fd 10 rt 36] rt 10]
Now I want this to appear as if it is rotating. I have tried to clear the screen and then rotate the turtle a at a specific angle and then print the pattern again. But there is something completely wrong in my logic. Can anybody help?
In order to accomplish animation, you need an interpreter which supports it. The interpreter must be one which renders the entire output before displaying it (doesn't show the turtle movement during drawing), and it also must support the wait command (or something similar to it). An example of an interpreter that meets these qualifications would be the one at www.logointerpreter.com. Here's an example which spins your wheel a full rotation and works with that interpreter:
ht
repeat 360
[
clean
repeat 36 [repeat 10[fd 10 rt 36] rt 10]
wait 10
rt 1
]
As you can see, the outer loop draws 360 separate frames. After drawing each frame, it waits 10 milliseconds, so you can see the frame. It then rotates the turtle one degree before clearing the screen and beginning the drawing of the next frame. If you need a little more control, you could also store the starting angle for each frame in a variable, like this:
ht
make "start 0
repeat 360
[
cs
rt :start
repeat 36 [repeat 10[fd 10 rt 36] rt 10]
wait 10
make "start (:start + 1)
]
Related
I am trying to write a script which will spin my character 180 degrees in game while holding lctrl and right clicking. This script works, but takes forever to spin around because of the sleep timer:
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsModifierPressed("lctrl")) then
for i = 0, 96 do
MoveMouseRelative (125,0)
Sleep (1)
end
end
end
If I increase MouseMoveRelative beyond 125, it starts to move the mouse in the wrong direction. No matter what value I use (I've tried lots of values between 100 and 12,000), it always moves the mouse a very small distance either left or right.
If I eliminate the Sleep function, the results are inconsistent. It usually rotates my character between 80-140 degrees. I suspect this is because MoveMouseRelative starts by getting the current mouse position and it requires a delay before the position it gets is accurate.
Any guidance as to why MouseMoveRelative doesn't work correctly for values above 125? Or any advice on how to quickly move the mouse 12,000 relative units on the x-axis instantaneously?
If I increase MouseMoveRelative beyond 125, it starts to move the mouse in the wrong direction.
The allowed range is -127...+127
I suspect this is because MoveMouseRelative starts by getting the current mouse position
No.
It does not ask the current mouse position.
It invokes SendInput() without flag MOUSEEVENTF_ABSOLUTE to simulate relative mouse movement.
how to quickly move the mouse 12,000 relative units on the x-axis instantaneously?
for i = 0, 96 do
MoveMouseRelative (125,0)
end
If I eliminate the Sleep function, the results are inconsistent. It usually rotates my character between 80-140 degrees.
Try more precise version of Sleep()
for i = 0, 96 do
MoveMouseRelative (125,0)
FastSleep(1)
end
Or any advice on how to quickly move the mouse 12,000 relative units
on the x-axis instantaneously?
If you want to move relative 12000 instantaneously, why do you move 97 steps of 125 with 1ms delays?
97*125 is 12125
Why not MoveMouseRelative(12125, 0) ?
According to the manual MoveMouseRelative takes "a few milliseconds" to complete.
1 ms is not a few. Reading the mouse position too early will give you the starting position. So I would presume that spamming relative movements which refer to that position might cause problems.
I am trying to write a program to print a circle of given diameter in Berkeley logo. I get the input diameter from the user of the program and draw a circle accordingly. But I do not know of any method to display a circle given the diameter. All along I have been using,
repeat 36 [fd 10 rt 10]
to draw a circle. But it is not what I want. I tried using formulas for diameter, but it is not working. Can anybody please help?
You have to find the perimeter first, then divide it by the total number of rotations, then set that as the value of forward in your loop.
E.g.
make "d 100
make "p 3.141592654*:d
make "i :p/36
repeat 36[fd :i rt 10]
you can have all of them in a single statement as
repeat 36[fd 3.141592654*:d/36 rt 10]
where d is the accepted value of the diameter
I want to create a script to automatically click on a moving target on a game.
To do this I want to check colours on the screen to determine where my target is and then click him, repeating this if he moves.
I'm not skilled at programming and there might be an easier solution to what I have proposed below:
1/Split the screen into equal tiles - size of tile should represent the in game object.
2/Loop through each pixel of each tile and create a histogram of the pixel colours.
3/If the most common recorded colour matches what we need, we MIGHT have the correct tile. Save the coords and click the object to complete task
4/Every 0.5 seconds check colour to determine if the object has moved, if it hasnt, keep clicking, if it has repeat steps 1, 2 and 3.
The step I am unsure of how to do technically is step 1. What data structure would I need for a tile? Would a 2D array suffice? Store the value of each colour in this array and then determine if it is the object. Also in pseudo how would I split the screen up into tiles to be searched? The tile issue is my main problem.
EDIT for rayryeng 2:
I will be using Python for this task. This is not my game, I just want to create a macro to automatically perform a task for me in the game. I have no code yet, I am looking more for the ideas behind making this work than actual code.
3rd edit and final code:
#!/usr/bin/python
import win32gui, win32api
#function to take in coords and return colour
def colour_return(x,y):
colours = win32gui.GetPixel(win32gui.GetDC(win32gui.GetActiveWindow()), x,y)
return colours
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
#variable declaration
x = 1
y = 1
pixel_value = []
colour_found = 0
while x < 1600:
pixel_value = colour_return(x,y)
if pixel_value == 1844766:
click(x,y)
x=x+1
#print x
print y
if x == 1600:
y=y+1
x=1
#print tile
pixel_value = 0
This is the final code that I have produced. It works but it is incredibly slow. It takes 30 seconds seconds to search all 1600 pixels of y=1. I guess it is my method that is not working. Instead of using histograms and tiles I am now just searching for a colour and clicking the coordinates when it matches. What is the fastest method to use when searching an entire screen for a certain colour? I've seen colour detection bots that manage to keep up every second with a moving character.
I am creating a football simulation game and I would like to make a 2D view of match. My match is 90 minutes long and there are 22 players on the field. How could I save a movements/path for players so that it wouldn't take lots of space. I know I could save it something like
Minute: min,
Player: id,
X: xCoord,
Y: yCoord
and then just move objects with jQuery from point A to point B, but I am sure it isn't the best solution, because it would require lots of space and database entries.
I am using MongoDB, but all suggestions are welcome.
How do the players move? They move a little in each step of the main loop? Or they go in long straight lines and then make sudden turns and go in other straight lines? In the first case you would probably need to save each milisecond or so (each step of the main loop), or you could save their positions every ten steps or every second, etc. And the replay could interpolate the saved points (thought the replay would look "gross" like that, it could save a lot of space in your db). In the second case (straight lines), you could just save the points where the players turn in another direction. In this case you'll save their position, angle and speed (along with time, obviously).
The first table could be (the intervals could be more than 1ms, depending on the power of the machine):
PLAYER TIME(ms) X Y
1 0 0 0
1 1 0 2
1 2 0 4
1 3 0 7
1 4 0 10
1 5 4 13
While the second table would be:
PLAYER TIME(ms) X Y Dir Speed
1 0 0 0 90 2
1 2 0 4 90 3
1 4 0 10 60 5
or something like that. Dir is the direction in degrees. Hope that helps!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
How do I move the turtle in LOGO?
// MOVE FORWARD
FD 75
// TURN RIGHT
RT 54
// TURN LEFT
LT 21
// MOVE BACKWARD
BK 17
Check out some other turtle commands found here...
Turtle Commands
BACK ## [BK] - Move turtle back
BACKGROUND ## [BG] - Set Background color (0-15)
0 - Black
1 - White
2 - Red
3 - Cyan
4 - Purple
5 - Green
6 - Blue
7 - Yellow
8 - Orange
9 - Brown
10 - Light Red
11 - Grey 1
12 - Grey 2
13 - Light Green
14 - Light Blue
15 - Grey 3
CLEARSCREEN [CS] - Clear Screen without moving turtle
DRAW - Clear Screen and take turtle home
EACH - Tell several sprites, whose numbers are in a list, to accept commands in a second list, e.g. EACH [1 2] [SQUARE 10]
FORWARD ## [FD] - Move turtle forward
FULLSCREEN - Full graphics screen (same as pressing F5)
HEADING - Output turtle heading as a number (0-359)
HIDETURTLE [HT] - Make turtle invisible
HOME - Move turtle to center of screen pointing up
LEFT [LT] - Turn turtle left
NODRAW [ND] - Enter text mode with clear screen
NOWRAP - Prevent drawings from wrapping around screen
PENCOLOR [PC] - Change pen color
PENDOWN [PD] - Turtle leaves trail
PENUP [PU] - Turtle ceases to leave trail
RIGHT ## [RT] - Turn turtle right
SETHEADING [SETH] - Set turtle heading, e.g. SETH 180
SETSHAPE - Set the current sprite shape (0-7)
SETX Move the turtle to the specified x co-ordinates e.g. SETX 50
SETXY Move the turtle to the specified x, y co-ordinates Eg. SETXY 50 50
SETY Move the turtle to the specified y co-ordinate, e.g. SETY 50
SHAPE - Output number of current sprite's shape
SHOWTURTLE [ST] - Make turtle visible
SPLITSCREEN - Mixed graphics and text screen (same as pressing F3)
STAMPCHAR - Make the turtle stamp a character at the current location, e.g. STAMPCHAR "A
TELL - Tell designated sprite to receive commands, e.g. TELL 2
TEXTSCREEN - Use whole screen for text (same as pressing F1)
TOWARDS - Output heading for turtle to face an X,Y coordinate, e.g. TOWARDS 0 0
WRAP - Make turtle drawings wrap around the screen
XCOR - Output current x co-ordinate of turtle
YCOR - Output current y co-ordinate of turtle
ASPECT - Set verticle screen scale factor, default is 0.76
Samples taken directly from website: http://gaza.freehosting.net/logo/index.html
Logo is all about moving the turtle... you give it commands like this:
Forward 100
Right 45
You can do stuff like repeating commands too:
Repeat 8 [Forward 100 Right 45] ; Draw an octagon
(What do I win? 8-)
Whoa! Is it still around?
fd 300 // Forward
rt 90 // Right 90°
fd 300
lt 90 // Left 90°
That used to work.
I've seen a few LOGO implementations where you can use localized commands like:
NAPRZOD (FORWARD),
LEWO (LEFT),
PRAWO (RIGTH)
or even NAPRZÓD (with Polish letter Ó).
LOGO is nice language to teach kids programming in their native spoken language.
By issuing commands in the correct syntax. E.G.:
forward 100
There is only one necessary command to move the turtle. It is forward which has the mnemonic fd. When working with a robot (real) turtle as opposed to a graphics based (virtual) one, you might find that the turning commands left and right [lt & rt] move the turtle a little, accidentally.
Most implementations also allow the command backwards [bk].
When the turtle moves, it may draw a line as it goes depending on whether the pen is up or down at the time, and whether the current pen color is different from the background color.
A graphics based (virtual) turtle can also jump around the screen with setx, sety, and setxy
try: bk(back), fd(forward), ld(left turn in degrees), rt(right turn).