Discuss Scratch

CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

I need an X Y Screen where I can plot any point. I also need to be able to input X and Y as negative numbers.
awesome-llama
Scratcher
1000+ posts

X Y Screen

Why not continue the conversation in the topic you made already?
https://scratch.mit.edu/discuss/topic/655682/

If you want an answer, you'll have to provide more information.

Plotting could be done with the pen blocks and you could simply move the sprite to the given x,y position and run pen down, then pen up to draw a dot.

Last edited by awesome-llama (Jan. 13, 2023 11:38:17)

CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

I would like a variable size for he sprite and need to be able to input negative numbers
awesome-llama
Scratcher
1000+ posts

X Y Screen

You want to make a grid that can be adjusted independently along both of its axes and be able to plot points on that grid?
deck26
Scratcher
1000+ posts

X Y Screen

What you want isn't difficult but unless you give us more information it's hard to help.

I suspect what you want is to create a mapping so your data points are translated into screen coordinates. So, for example, if your x range goes from -100 to 500 you'd probably want the middle of the screen to represent x=200 which is the middle of that range. You'd also want to adjust the values so that your range (600 wide) is mapped onto the Scratch range of 480 wide, In that example to get the Scratch x value for your data-x you'd subtract 200 and multiply by 8/10 (equivalent to 480/600).

Having negative numbers is not an issue.
CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

Like this
defineRangeStartRangeEndData-XsetRange MiddletoRangeEnd+RangeStart/2ifRange End<0thenset Rangeto absofRangeStart+RangeEndelsesetRangetoRangeEnd-RangeStartset XtoData-X-Range*480/Range
CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

But how will you change the size of the sprite so that all values of X can be plotted and it does not overlap and the sprites are as clear as possible
CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

If my previous post was unclear I am asking how to size the sprite so that all coordinates are as big as possible but don't overlap with each other
deck26
Scratcher
1000+ posts

X Y Screen

So are you saying you want a sprite that is the x-Y grid because you haven't actually said so? Why use a sprite instead of drawing the grid the size you need it to be? What are the items you're referring to the size(s) of in your last two posts?

You haven't given a clear enough explanation of what you have in mind so the question we're answering may not be the one you think you've asked!
smarthoneybadger
Scratcher
30 posts

X Y Screen

You need to find the highest absolute value of x in a point, and the highest absolute value of y in a point.

Then, divide 240 (The biggest possible x in scratch) by the highest absolute value of x.
Then, divide 180 (The biggest possible y in scratch) by the highest absolute value of y.

Set variables ‘multiply x’ and ‘multiply y’ to those numbers above.


When you're displaying the points on the screen, multiply every x for the points by the variable ‘multiply x’ and every y for the points by ‘multiply y’.



Here is the code:
whenclickedmakexandycoordinatelistsgethighestdefinegethighestsetcounterto0sethighest absolute xto0sethighest absolute yto0repeatlengthofx coordinateschangecounterby1ifabsofitemcounteroflist x>highestabsolutexthensethighest absolute xtoabsofitemcounteroflist xsetcounterto0repeatlengthofy coordinateschangecounterby1ifabsofitemcounteroflist y>highestabsoluteythensethighest absolute ytoabsofitemcounteroflist y

Last edited by smarthoneybadger (Jan. 16, 2023 15:37:59)

deck26
Scratcher
1000+ posts

X Y Screen

smarthoneybadger wrote:

You need to find the highest absolute value of x in a point, and the highest absolute value of y in a point.

Then, divide 240 (The biggest possible x in scratch) by the highest absolute value of x.
Then, divide 180 (The biggest possible y in scratch) by the highest absolute value of y.

Set variables ‘multiply x’ and ‘multiply y’ to those numbers above.


When you're displaying the points on the screen, multiply every x for the points by the variable ‘multiply x’ and every y for the points by ‘multiply y’.

Here is the code:
Just be aware that assumes you want to keep the centre of ths screen as the origin for your x and y axes.
CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

You are all telling me where to plot the point but my last question was how to plot the point.
I was asking for size because I thought I should have a sprite and stamp it on the coordinate that we have calculated
deck26
Scratcher
1000+ posts

X Y Screen

You're really not making things clear enough for us to help properly. Where does the size of the sprite come into it? What is the sprite?

All we know at the moment is you're trying to plot points on a grid that doesn't necessarily match the Scratch coordinate system. So we're told you how to map your grid onto the Scratch coordinates which tells you where any point would appear. If that's not what you want you need to be clearer on what you do want.
CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

I asked how to plot the point
I thought I should have a sprite and I can stamp it on the calculated coordinate
But the sprite will have a different sprite for every grid but I don't know how to calculate that size
The starting sprite size can also be changeable so please mention it in your post
deck26
Scratcher
1000+ posts

X Y Screen

CodeMaster_TheGreat wrote:

I asked how to plot the point
I thought I should have a sprite and I can stamp it on the calculated coordinate
But the sprite will have a different sprite for every grid but I don't know how to calculate that size
The starting sprite size can also be changeable so please mention it in your post

So what does any of that mean? Seriously, we're trying to help but need to understand what you're trying to do.

Perhaps you could create a project with static images showing what you're trying to achieve.
CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

I am making a project where I have some X-Y points as an output
The Points will change for every input
The range of the points is also be variable
I don't know how to plot the points so I am asking here
forumhelperman
Scratcher
86 posts

X Y Screen

this calls for pen!
you can make a grid out of pen, including the X and Y boundaries.

- Grid
Lets say we have 4 variables, Xmax, Xmin, Ymax, and Yminl.
Starting for x=-240, you can just use (480/(Xmax-Xmin)) to get the distance between lines. and run
repeatXmax-Xminchangexbythatnumberverticalline
the same logic can be applied to the Y axis

- Plotting points
This really depends on how you store your data. Personally, I would have a list where odd numbers are X coords, and even numbers are Y coords
You can go to the real X and Y spot, and multiply it by (that number). Pretty simple in theory, but you would need to find (0,0) relative to your grid. I cant help with that (no time)

Hope this helps! Reply and maybe I'll give some pointers, or fix some errors in my logic!

Last edited by forumhelperman (Jan. 20, 2023 05:03:18)

deck26
Scratcher
1000+ posts

X Y Screen

CodeMaster_TheGreat wrote:

I am making a project where I have some X-Y points as an output
The Points will change for every input
The range of the points is also be variable
I don't know how to plot the points so I am asking here
So you want a custom block that redraws the screen with each input, adjusting the range of points that it includes if necessary. So if you have 10 points with a graph range for x from -100 to 100 and the next point has x=150 you can still cope.

The custom block needs to be run with no screen refresh for speed. It will draw the x and y axes in the correct place (unless you want to always keep the origin in the centre) and replot each point. It will also potentially need a text engine to mark points on the axes unless you don't care about that. If you also want a grid to be drawn the custom block should do that as well.

Then it's mostly a case of working out the mapping between your coordinate system and the system Scratch uses. That has been dealt with in other posts. You can then stamp or draw a mark for the data point at the correct screen location.

CodeMaster_TheGreat
Scratcher
25 posts

X Y Screen

But I will stamp a sprite for the point right?
deck26
Scratcher
1000+ posts

X Y Screen

CodeMaster_TheGreat wrote:

But I will stamp a sprite for the point right?
You can stamp, draw or clone depending one what you want.

If you stamp or draw the points you just redraw them all when you redraw the screen. If using clones you can just broadcast to get them all to recalculate their screen positions according to any change in scaling/position values.

Powered by DjangoBB