does anyone know how i can write a function for big-bang which basically loops an animation.for my task i have an animation of a car which currently goes from left to right but ends when it touches the right hand side,however,i want it to repeat itself so it continuesly goes left to right back to left and right non-stop.this is the excerise description
Exercise 45. Design a “virtual cat” world program that continuously moves the cat from left to right. Let’s call it cat-prog and let’s assume it consumes the starting position of the cat. Furthermore, make the cat move three pixels per clock tick. Whenever the cat disappears on the right, it reappears on the left. You may wish to read up on the modulo function.
i dont understand how the modulo function would be used here can someone explain
; WorldState - Image
; places the cat into the BACKGROUND scene,
; according to the given world state
;when the cat dissapears on the right it reappears on the left
(define (render cw)
(place-image CAT cw X-CAT background))
Related
Using pyautogui, I'm trying to locate an image on screen.
This finds the image (on primary monitor w/ 2560x1440 resolution), but takes nearly 5 sec:
icon1 = pyautogui.locateOnScreen('[filepath]\\icon1.png', grayscale=True)
To reduce search time, I provide a region parameter, but this doesn't find the image. It executes in ~0.7 sec
icon1 = pyautogui.locateOnScreen('[filepath]\\icon1.png', region=(1500,100,950,1100), grayscale=True)
Eliminating the grayscale parameter doesn't change the result - still ~0.7 execution time and image not found:
icon1 = pyautogui.locateOnScreen('[filepath]\\icon1.png', region=(1500,100,950,1100))
Then I tried setting the region parameter to the entire screen, but image not found and execution time is ~1.5sec, so it's searching (judging by longer execution time w/ larger region), just not finding.
icon1 = pyautogui.locateOnScreen('[filepath]\\icon1.png', region=(0,0,2559,1439))
Any suggestions on what to try next? Thanks.
I figured out what's happening. As a preface, I am working with multiple monitors, and have made modifications to pyautogui and pyscreeze as described in these 2 pyautogui github comments:
https://github.com/asweigart/pyautogui/issues/9#issuecomment-527236475
https://github.com/asweigart/pyautogui/issues/321#issuecomment-629819495
With these modifications, pyautogui works with multiple monitors, and pyautogui.position() and pyautogui.moveTo() treat the upper left corner of the primary monitor as coordinate (0,0) - this means monitors above or to the left of primary monitor will have at least one negative coordinate.
But pyscreeze is returning image search results based on treatment of the upper left corner of the upper left monitor as coordinate (0,0) - so all coordinates on extended desktop are positive.
The region parameter I was passing to locateOnScreen() was based on using pyautogui.position() reported coordinates, so the search was being executed on an incorrect area of the screen.
Once I figured that out, I was able to pass the correct region specification.
To illustrate, I inserted a print statement in pyscreeze to show where the image is found. And a print of the image search return. And in my code, I printed pyautogui.position().
retVal = Box(left=8008, top=3171, width=29, height=31)
Point(x=4182, y=1026)
mouse position:
Point(x=4182, y=1026)
So you can see that coordinates are quite different. Pyscreeze is showing coordinates based on 0,0 being upper left corner of upper left monitor, while the image search return variable are coordinates based on 0,0 being upper left corner of primary monitor, so I'm able to take the image search result variable and pass that to pyautogui.moveTo() and move the mouse there (moveTo needs coordinates based on 0,0 being upper left corner of primary monitor).
The issue stems from adopting changes from two different people to pyautogui and pyscreeze. I suppose I could adjust the changes to one of these packages to offset the coordinates so that both are referencing the same monitor's upper left corner as coordinate (0,0).
Your region is set wrong. Use (0,0,2559,1439).
And if this doesn't work make a new screenshot specifying the region for it, save it and look if that just captured screenshot would be found on the screen.
The code below should always work as expected:
from time import perf_counter as T
import pyautogui
# NOTICE that in pyautogui: region=(left, top, width, height)
pyautogui.screenshot('pyautogui_region_screenshot.png', region=(300, 500, 300, 200))
sT = T()
img = pyautogui.locateOnScreen('pyautogui_region_screenshot.png', region=(300, 500, 300, 200))
eT = T()
print(f'img = pyautogui.locateOnScreen took: {eT-sT:9.5f} seconds')
print(img)
By the way: check out https://stackoverflow.com/questions/72410958/taking-a-screenshot-of-a-specific-portion-of-the-screen-in-python to switch to another Python module ( mss ) for doing screenshots of small regions of the screen.
https://pyautogui.readthedocs.io/en/latest/screenshot.html
I have an image map with two sides. User clicks Left side (A1 through A25)
Then clicks Right Side (B1 - B25). These clicks are all recorded into a database table.
I run a function that figures out which "Click Sequences" are the most frequently used and determines the top five pairs of coordinates. Let's say the top selection was: A5,B7
I need a plugin that will overlay "streak" images (that resemble a glowing arced line) from the left side coordinates to the right side coordinates with varying transparency/color?
So in our example, an arced line going from A5 over to B7..
Hope this makes sense.
Thanks!
I am trying to make a simple arcade shooter like Galaga in TIBasic. I have successfully created some code that lets you move your character (an "X") horizontally across the screen while shooting a bullet that clears everything along the vertical path it takes. However, I'm having a problem with the "rocks" that are supposed to fall from the screen and disappear when hit. When I shoot the rock, it is cleared by the bullet, but then continues going down the screen until it hits the bottom of the screen. Here's the code for the rocks:
//outside the game loop:
1->R
//inside game loop:
If not(R=8)
Then
R+1->R
If R>1
Then
Output(E-1, 1, " " //removes last rock
End
Output(R, 1, "R" //replaces last rock with one below it (traveling towards the ground)
End
This code obviously doesn't stop the "R" from continuing to go down the screen when it is cleared (by the way, I just use Output(...," ") on wherever the bullet was to clear away anything the bullet hits). So, how would I check if the rock was cleared away on the last iteration of the game loop? Is there a way to check if something (the "R") is at a certain place on the screen in order to check if it was cleared away by a bullet on the last iteration? Or is there a better way? Thanks for the help!
It appears that the code you have doesn't test if the bullet is in the same place as the rock. To have this collision, you'd need to compare the "R" y-value of the rock with the y-value of your bullet you displayed, and compare the x-value of the rock (however you store that) with the x-value of the bullet. If both are equal to each other, then they have collided, and you can "delete" the rock by setting it to whatever value signifies it doesn't exist anymore. Assuming R is the y-value of the rock, S is the x-value of the rock, Y is the y-value of the bullet, and X is the x-value of the bullet, In the code to move the rock, I'd put this somewhere:
:If R=Y and S=X
:DelVar R
//You could also delete the bullet here because it's "stopped" by the rock
This code will test if the two are collided and set R to 0 (meaning it doesn't exist). If you wanted, you could also add a text-version of an explosion to give it some more flair. Good luck with your project, and I hoped this helped!
When making a game in Ti-Basic, there are 2 options for which "screen" to put it on: The text screen of the calculator, using functions like Disp and Output, and the graph screen, using Text, as well as the drawing functions, stored pictures, and pxl and pt functions. I'm not sure about how to check the text out put screen for the presence of an object on the screen, but the graph function has the Pxl-Test function:
:Pxl-Test(y,x)
Someone else may have know how to check for something on the text screen, but I suggest switching to the graph screen to make use of this function.
If you are going to switch to using the graph output here are some things to note:
The text function is
:Text(row,col,output)
Row and col are switched from the Output function
Rows and cols are measured in pixels on the screen, as opposed to the space it takes to type a letter
Most letters are 3 pixels wide, spaces are 1 pixel wide, so it will take multiple spaces to clear out an unwanted character
You may need to disable the graph axis (FORMAT menu), the y-functions (VARS menu, then right to Y-VARS), and the stat-plots (STAT PLOT menu) in the begging of the program then restore them at the end.
One last not on using the Pxl-Test function is that it tests a group of pixels, while a letter. For now let's pretend you only use Rs and an X in your program (I don't know if you do or don't), so you should test a spot on that character that is relatively unique to that character.
Good luck!
I've been searching and having trouble doing this the right way.So my player has 2 arms which are joined in one mc. Now I'm trying to make the body(which is doesn't belong on the container mc) go between them, so it's like R arm first then body then L arm. The 2 arms rotate on mouse direction, i don't want the body too. Any ideas what way I should go?
EDIT:
please see my sample image
The checked thing is the result I'm looking for. But since the 2 arms is combined on one MC, I can't make the body appear on the middle between the 2 arms.
You should change your nesting model like this:
And then store your arms in an Array or a Vector, and change every arm's rotation separately.
It's the only way
I'm making a game with a health bar and I am trying to make a health bar that is curved.
Currently I have a lineBar that has 20 segments that looks like this at the bottom left of the screen.
What I'd like to do is write a function that goes through and modifies the scaleY of each to get a curved bar.
I can easily scale them down in a straight line. So that it looks triangle ish.
I want exponential decay.
In normal math terms it might be something like y = Pa^x.
I developed a game with a curved health bar a while back, this is how I achieved it:
Step 1:
Create your curved bar. I suggest the Oval Primitive tool:
Draw your bar. I suggest creating a guide layer to demonstrate a whole-circle visual of your curved segment. Copy the bar onto another layer and make it a mask, this will be what reveals your healthbar. The mask and the segment should be MovieClips:
Step 2:
Set the registration point of your mask to the centre of your guide circle. Your mask will rotate around this point to reveal your actual bar. Rotate your mask so that it is to the left of your actual bar graphic:
Step 3:
Create a tween of your mask rotating clockwise across 100 frames (add more frames for finer progression). You can even apply a tween to your bar graphics where the colour changes from red to green as it fills, etc.
Step 4:
Use gotoAndStop() on this element to determine which frame you should stop on throughout the animation. The formula I use here is generally:
gotoAndStop( Math.round( currentHealth / maxHealth * x ) );
Where x is the amount of frames you created.
Hope this helps.