06-22-2025 10:14 AM
I am creating a program that takes the behavior of a triangular wave and scans in both the x- and y-axis directions.
The x-axis and y-axis are moving between 0 and 255 pixels.
One round trip on the x-axis causes the y to move +1.
After the y-axis reaches 255, it makes one round trip on the x-axis and then 254. how do I make one more round trip on the x before y reaches 254?
I would like to make an addition to the attached program to change it.
I am attaching the program.
I would appreciate any advice you could give me.
06-22-2025 11:26 AM - edited 06-22-2025 11:34 AM
I recommend to do a few simple tutorial before continuing.
Also please define words such as round trip in the following sentence:
@ikeda_kaoru wrote:
After the y-axis reaches 255, it makes one round trip on the x-axis and then 254. how do I make one more round trip on the x before y reaches 254?
Can you show it graphically on a 2D plane?
Also please fix the inconsistencies in datatypes and labeling. a wait time is not a "frequency" and zero is probably not a good default. Everything should be U8. You don't need the numeric display is you show the digital display of the charts.
06-22-2025 02:27 PM
One of the first things to do is to (as clearly as possible) describe the task. I'm not entirely sure what you want to do, nor how you want to do it.
The "known" factor is a 256 x 256 array of (presumably uniformly-spaced) "destinations" that you want to "visit" and either give a "value" to or to "get" a value from. The basic question appear to be how you traverse this 256 x 256 array.
So here's a question -- are you able to read (or write) all 65536 values (256 x 256) all at once, or do you need to "traverse" this space, one element at a time? If you are "traversing", do you go from one element to an adjacent element, moving at a uniform rate from element to (adjacent) element (and hence a fixed delta-t) or can you go from any element to any other element in a single time step? (Note that if the time step is short enough compared, say, to the relatively slow time of human vision, which lets us watch TV or a movie and not notice that the images are changing every 10 ms or so -- we don't notice the screen being "painted").
There are several ways to traverse a 256 x 256 array, depending on the timing you want to use. If you are "painting with an electron beam" (like a TV), positioning the beam is very fast (provided you can turn it on and off so you don't notice the sweeps), so you "paint" row 0, then row 1, ... then row 255, then row 0 again.
If, on the other hand, you have a stationary "beam" and are moving the "object being scanned", then you might want to move one step at a time (at a constant rate). How do you want to do this?
One way (for a single 256 x 256 scan) is the following:
But what if you want to do multiple scans? How do you get from (255, 0) back to (0, 0)? There are many ways to do this (one is to simply do the whole algorithm again, but reverse the Y increment, i.e. basically reverse your steps -- the draw back, of course, is if the image is changing, the time-between-samples becomes a complicated function of pixel location -- my head hurts even thinking about this!
Anyway, once you clearly describe the algorithm you want to use, coding it should be a piece of cake. Here's how to do the "TV Algorithm":
Because moving electrons is so much faster than moving larger objects, cameras are easier to use (and program) than microscope stages.
Bob Schor
06-23-2025 02:27 AM
Sorry for the lack of explanation.
@altenbach さんは書きました:
I recommend to do a few simple tutorial before continuing.
Also please define words such as round trip in the following sentence:
@ikeda_kaoru wrote:
After the y-axis reaches 255, it makes one round trip on the x-axis and then 254. how do I make one more round trip on the x before y reaches 254?
Can you show it graphically on a 2D plane?
Also please fix the inconsistencies in datatypes and labeling. a wait time is not a "frequency" and zero is probably not a good default. Everything should be U8. You don't need the numeric display is you show the digital display of the charts.
Maybe this can give you a start.
I apologize for the confusing explanation.
The “round trip” is (x,y)=(0,0)(1,0)... (254,0)(255,0)(254,0)... (1,0)(0,0) which indicates a move of 255 in the x-axis direction and 255 back.
When it reaches (x,y)=(0,255), it moves 255 in the x-axis direction and comes back 255. Next, it moves to (0,254) and continues to move in the x-axis direction as before, but now we want it to move 255 again from (0,255) in the x-axis direction and back before it reaches (0,254). Next, we want to move to (0,254) and continue the same behavior as before.
Image
Now: (x,y)=(2,254)(1,254)(0,254)(0,255)(1,255)(2,255)... (255,255)(254,255)... (0,255)(0,254)(1,254)(2,254)...
After Improvement:(x,y)=(2,254)(1,254)(0,254)(0,255)(1,255)(2,255)...(255,255)(254,255)...(0,255)(0,255)(1,255)(2,255)...(255,255)(254,255)...(0,255)(0,254)(1,254)(2,254)...
The waiting time has been changed to 1 by default.
Thanks also for the advice about the digital display of the chart.
06-23-2025 02:40 AM
@Bob_Schor さんは書きました:
One of the first things to do is to (as clearly as possible) describe the task. I'm not entirely sure what you want to do, nor how you want to do it.
The "known" factor is a 256 x 256 array of (presumably uniformly-spaced) "destinations" that you want to "visit" and either give a "value" to or to "get" a value from. The basic question appear to be how you traverse this 256 x 256 array.
So here's a question -- are you able to read (or write) all 65536 values (256 x 256) all at once, or do you need to "traverse" this space, one element at a time? If you are "traversing", do you go from one element to an adjacent element, moving at a uniform rate from element to (adjacent) element (and hence a fixed delta-t) or can you go from any element to any other element in a single time step? (Note that if the time step is short enough compared, say, to the relatively slow time of human vision, which lets us watch TV or a movie and not notice that the images are changing every 10 ms or so -- we don't notice the screen being "painted").
There are several ways to traverse a 256 x 256 array, depending on the timing you want to use. If you are "painting with an electron beam" (like a TV), positioning the beam is very fast (provided you can turn it on and off so you don't notice the sweeps), so you "paint" row 0, then row 1, ... then row 255, then row 0 again.
If, on the other hand, you have a stationary "beam" and are moving the "object being scanned", then you might want to move one step at a time (at a constant rate). How do you want to do this?
One way (for a single 256 x 256 scan) is the following:
- Start at Row 0, Column 0.
- Scan even Rows one column at a time, incrementing the column until you reach Column 255.
- When you finish 0, 255, increment the row (but leave the column unchanged).
- Scan odd Rows one column at a time, decrementing the column until you reach Column 0.
- When you finish (odd row), 0,
- If the Row is 255, you are done, exit.
- Otherwise, increment the row (to make it even) and go back to Step 2.
But what if you want to do multiple scans? How do you get from (255, 0) back to (0, 0)? There are many ways to do this (one is to simply do the whole algorithm again, but reverse the Y increment, i.e. basically reverse your steps -- the draw back, of course, is if the image is changing, the time-between-samples becomes a complicated function of pixel location -- my head hurts even thinking about this!
Anyway, once you clearly describe the algorithm you want to use, coding it should be a piece of cake. Here's how to do the "TV Algorithm":
- For each frame:
- Move to 0, 0
- For each of 256 rows:
- Process Pixel.(x, y)
- If x < 255, increment x and move to (x, y)
- otherwise if y < 255, increment y and move to (0, y)
- otherwise go back to Step 1 and "do it all over again"
Because moving electrons is so much faster than moving larger objects, cameras are easier to use (and program) than microscope stages.
Bob Schor
I apologize for the confusing explanation.
I want to traverse a 256 x 256 space one element at a time. We intend to get data at each location. We intend to move from adjacent element to element at a uniform speed (about 300μs).
When it reaches (x,y)=(0,255), it moves 255 in the x-axis direction and comes back 255. Next, it moves to (0,254) and continues to move in the x-axis direction as before, but now we want it to move 255 again from (0,255) in the x-axis direction and back before it reaches (0,254). Next, we want to move to (0,254) and continue the same behavior as before.
Image
Now: (x,y)=(2,254)(1,254)(0,254)(0,255)(1,255)(2,255)... (255,255)(254,255)... (0,255)(0,254)(1,254)(2,254)...
After Improvement:(x,y)=(2,254)(1,254)(0,254)(0,255)(1,255)(2,255)...(255,255)(254,255)...(0,255)(0,255)(1,255)(2,255)...(255,255)(254,255)...(0,255)(0,254)(1,254)(2,254)...
Thank you for your kind reply.
06-23-2025 09:50 AM
06-24-2025 07:15 AM
Thank you for your reply.
I tried running the program.
The “round trip” movement is the same as I had imagined.
Thank you very much.
However, with this movement, Y returns to 0 after reaching 255. I would like Y to decrease to 0 after reaching 255, such as 254...253...252...
The program I attached also does this.
Here, after reaching 255, I want it to decrease to 254 after two round trips, not one.
If possible, I would appreciate it if you could modify the program I attached earlier.
This is because I plan to set different scan ranges for X and Y, such as 10,000 pixels for the X-axis and 256 pixels for the Y-axis.