How can I do turtle graphics in LiveCode?
I assume somebody probably already has some scripts.
References
This question is related to
A script to draw, fill and group triangles in Livecode?
https://en.wikipedia.org/wiki/Turtle_graphics
You have to make them yourself, but they're easy. This is a simple example. You'll have to adjust a few things to make it a real turtle thing.
on foo theNumOfSteps
if there is an img 1 then delete img 1
put the width of this cd / theNumOfSteps into x
put the height of this cd / theNumOfSteps into y
choose line tool
repeat with z = 1 to theNumOfSteps
drag from 0,y*z to x*z,the height of this cd
end repeat
choose browse tool
end foo
Related
I am trying to get the color of a pixel on my screen using node.js. I want it to be returned in RGB format, e.g. (255, 0, 0). My current solution is to use screenshot-desktop to screenshot my entire screen in JPG format, decode it to get the raw pixel data, and get the color of a given pixel. However, this lags out my entire computer for 1-2 seconds as it is taking the screenshot. This is unusable as I would like to do this multiple times per second. So my question is: How can I get the color of a given pixel on the screen, without taking a full screenshot?
I am using Linux with X11. There is an X11 library for node.js, so I asssume I should use that to get the pixel color, I'm just not sure how. If you could show me how to do it in C then I can easily use node.js to do the same thing.
Thanks!
Oh my gosh I just figured it out after posting this. I was using robotjs for reading the mouse position and I totally forgot it can do screen stuff too! So, the solution would be to do
var robot = require('robotjs');
var color = robot.getPixelColor(x, y);
X11 solution using x11 node library ( I am the author ):
query windows tree with QueryTree starting at the root window
get every child geometry using GetGeometry request
if your point is not inside any child, use current window id and get 1x1 pixmap from the current image: GetImage(format, currentWindow, x, y, 1, 1, planeMask) ( 2 for format and 0xffffffff for plane mask should work ). Make sure you calculate relative x y position as you travers windows tree.
if child window covers your point query children for that window and repeat again. Note that QueryTree returns windows in bottom to top stacking order so make sure you pick last one covering your point
Once you have 1x1 pixmap from the topmost window under your point - the buffer should contain only color bytes for your image, RGB order and bit mask might depend on red_mask, green_mask, blue_mask from display.screen[0].depths[visual].
If you cache "topmost window" between requests and only start from root when no match anymore the above solution might be much more performant then the one using robotjs ( although much more low level and complicated ) Good luck!
I worked on a small fishing game in Godot for a Game Jam and as it was my first time creating something in Godot, for much of it I followed the Your first game tutorial from the Godot docs. In this tutorial, mobs are spawned from all sides of the screen, but for my game I wanted the fish to spawn only from the left and right side. Because of this change, instead of using one Path2d for the mob spawning, I used two straight lines on either side.
The lines were placed with the points in a clockwise order, so on the right side, the first point was the top and the second was the bottom, and on the left side, the first point was the bottom and the second was the bottom.
Here is a picture that shows the spawning lines.
The mobs spawn and move in the correct direction, but no matter what I tried, the fish that spawned from the right side spawned with an incorrectly placed hitbox and with the sprite upside-down.
This is an example of a fish that spawned from the left side, while this is an example of a fish that spawned from the right side.
Here is the code for spawning fish. Side is a variable that passed in and is simply 0 if the fish is spawning from the left and 1 if the fish is spawning from the right.
var fish = Fish.instance()
add_child(fish)
var fishSide
if (side == 0):
fishSide = $FishPathLeft/FishFollowLeft
else:
fishSide = $FishPathRight/FishFollowRight
fishSide.offset = randi()
fish.linear_velocity = Vector2(fish.speed, 0)
var direction = fishSide.rotation + PI / 2
fish.rotation = direction
fish.position = fishSide.position
fish.linear_velocity = fish.linear_velocity.rotated(direction)
When a fish is created, they are given a random base sprite from 4 possible bases, all of which have specific settings for the collision shape. The fish sprites default to facing left.
I assumed that the issue was because the fish is rotated 180 degrees when spawned on the right, but the problem is that even if I try to flip the fish, it still appears upside-down. I've tried flipping the fish with:
fish.scale.y = -fish.scale.y
But it doesn't seem to do anything, so I'm kind of at a loss as to what would fix it.
What I see here is that you are rotating the fish. Which also explains the pictures:
fish.rotation = direction
But that is not what you want.
Yes, you could use scale (fish.scale.y = -fish.scale.y), However, it is not recommended to scale them.
The sprite has flip_v and flip_h properties, that will solve the visual part. But they have nothing to do with the collision shape.
So you could do this:
fish.get_node("sprite").flip_h = (side == 1)
Where sprite is a sprite child of the fish.
What I'm going to suggest for the collision shape is to have two, one for the left and one for the right, and the disable the one the fish will not use (shape.disabled = true).
You could do something like this:
fish.get_node("left_collision").disabled = (side == 1)
fish.get_node("right_collision").disabled = (side == 0)
Where left_collision and right_collision are collision shapes children of the fish.
As an alternative, consider rotating the collision shape a quarter turn clockwise (-TAU / 4, a.k.a -PI / 2):
fish.get_node("collision").rotation = -TAU / 4 if (side == 1) else 0
By the way, in the long run you might benefit from placing all this logic in a function in a script attached to the root node of fish scene. Have the function take the velocity as input, and using it decide if it is going to flip and rotate the sprite, and if it is going to disable or rotate collision shapes. That way, if you later decide you want the fish to be able to change direction, it is a matter of calling that function again (in fact, you could do that in _physics_process of the fish).
Something else (I know you do it the way the tutorial does it, but): give position the node before adding it as child. If you add it first, and place it second, it might register some collisions before you change the position.
# xdotool --version
xdotool version 2.20110530.1
# wmctrl --version
1.07
# bash --version
GNU bash, version 4.1.10(1)-release (i586-suse-linux-gnu)
I have been playing around with the Commands wmctrl and xdotool for rearranging/moving windows around the desktop. And I was wondering if it's possible to use, for example, the bottom-left Corner as the transformation point for where I want that point to end up..?
For example, if wanted to move the current window to point 100,1000 (*i.e. X-Axis=100 and Y-Axis=1000), but instead of using the top-left corner as the point that will end-up at 100,1000, I want to use current window's Bottom-Left corner instead...
Is this possible to specify this with either of these commands?
I know I could probably do this with some math equations by getting the geometry of the window and then subtract or add the height of the window (*i.e. the y-axis) from the coordinate, in order to modify where the top-left corner would be, in essence putting the bottom-left corner where I want it. But in actuality I'm moving the top-left corner, but making it seem like I'm moving it using the bottom-left corner instead.
I know this isn't the same thing, but I saw you can use the "--polar" option (*moving with degrees instead of px) with the "--window" option to use the center of the window as the point of origin... But, nothing to really specify a different corner as the transformation point...
Or maybe there is another command other then the wmctrl or xdotool command to accomplish this...
Any thoughts or suggestions would be greatly appreciated!
Thanks in Advance,
Matt
I'm wondering how I can erase from the rendertexture. e.g. I fill a rectangle and then want to make a circle in the center transparent again.
I tried drawing stuff with alpha 0 and using various blendmodes. I was actually looking for a BlendMode.None of some sort to copy the alpha channel directly, but there's only BlendMode.Normal, which doesn't seem to do the job.
Is there a way to change the default color of the progress bar to any color
other than green? For instance, I would like it to be red until it gets to
100% and then it turns green.
This question was asked on a LiveCode list serve and I'm answering here because others might find it useful.
No it's not possible to do this but it is easy to create a custom progress bar that you can set the color how you like.
Create two graphics. One for the border and one for the bar. Set the colors and graphic effects however you like. Group them and then add the following to the group script:
setProp uPercent pPercent -- 0..100
put the rect of grc "border" of me into tRect
put round(item 1 of tRect+(item 3 of tRect-item 1 of tRect)*pPercent/100) into item 3 of tRect
set the rect of grc "bar" of me to tRect
end uPercent