Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Noob Help: How to Make a Wavy Line
- kajdna
-
13 posts
Noob Help: How to Make a Wavy Line
Hi,
I want to make a wavy line. I can make one half-circle facing up and one half circle facing down, one script each.
I want to join these scripts and use a repeat to make a wave line with the above two elements.
I can't figure it out. My combined script makes a circle.
Can you remix my example?
Thanks!
https://scratch.mit.edu/projects/70354562/
I want to make a wavy line. I can make one half-circle facing up and one half circle facing down, one script each.
I want to join these scripts and use a repeat to make a wave line with the above two elements.
I can't figure it out. My combined script makes a circle.
Can you remix my example?
Thanks!
https://scratch.mit.edu/projects/70354562/
- eric-pratt
-
15 posts
Noob Help: How to Make a Wavy Line
Here it draws a perfect line instantly. This project is a demo, so just take the code out and put it in your project(Credit please)
- idlegamemaker
-
41 posts
Noob Help: How to Make a Wavy Line
https://scratch.mit.edu/projects/69393686/
this includes sine curve and the circle. check the code,
this includes sine curve and the circle. check the code,
- kajdna
-
13 posts
Noob Help: How to Make a Wavy Line
Hi.
Here you are.
Dimitri.
Wow! Your code executes exactly what I was trying to do. There's no way I could have figured this out myself. So now, with your instruction, my learning begins. I have downloaded your script to my computer and will upload it to my Scripts area for this project. Then I'm going to re-build my script, using your example, paying attention to exactly what I needed that I did not include. And then I will play further. For example, can I further alter your script and still get the same wavy line? Perhaps I can remove the speed variable . . . So after I understand your script, I'll try stripping it down to the fewest parts that will still give me the same output.
- kajdna
-
13 posts
Noob Help: How to Make a Wavy Line
Here it draws a perfect line instantly. This project is a demo, so just take the code out and put it in your project(Credit please)
It is too difficult for me to extract a static wavy line from your dynamic sine wave. But I'm impressed nevertheless.
Not wishing to change topic of thread BUT have you used a micro-controller board with Scratch and can you give a simple example of what you have done? Check out the edex.org MOOC Electronic Interfaces from Berkeley. It uses a language called Energia and I can see elements of Scratch in it.
The class includes a robot project, 50% of grade. I'm browsing and learning a lot. Check it out.
- dimitrip
-
500+ posts
Noob Help: How to Make a Wavy Line
Hi Kadjna.
The speed variable is there only to speed up a bit the drawing.
Instead of turning the cat 1° left or right at each step, it turns it 2°, or 3°, or more degrees (the “speed”).
Until about 15°, there is no noticeable difference in the drawing's resulting shape.
Of course, to make the half of a circle, you need to turn for a total of 180°.
That's why for each half circle, the repeat loop says “repeat 180/speed”).
Of course also, if you want quite the same result with a different “speed”, the distance that the cat has to move at each step must vary in function of the “speed”.
Here the distance the cat moves at each step, has been set to simply “speed/2”.
This is a rough approximation of what it should be. Because, the cat moves in straight line (a chord of the half circle*) and there is a difference between the length of the chord and the length of arc, specially when the angle of the arc becomes bigger.
If you mind, re-look at remix, I've been emphasizing the effect of changing the speed parameter.
(*) see wiki circle: https://en.wikipedia.org/wiki/Circle
Greetz,
Dimitri.
The speed variable is there only to speed up a bit the drawing.
Instead of turning the cat 1° left or right at each step, it turns it 2°, or 3°, or more degrees (the “speed”).
Until about 15°, there is no noticeable difference in the drawing's resulting shape.
Of course, to make the half of a circle, you need to turn for a total of 180°.
That's why for each half circle, the repeat loop says “repeat 180/speed”).
Of course also, if you want quite the same result with a different “speed”, the distance that the cat has to move at each step must vary in function of the “speed”.
Here the distance the cat moves at each step, has been set to simply “speed/2”.
This is a rough approximation of what it should be. Because, the cat moves in straight line (a chord of the half circle*) and there is a difference between the length of the chord and the length of arc, specially when the angle of the arc becomes bigger.
If you mind, re-look at remix, I've been emphasizing the effect of changing the speed parameter.
(*) see wiki circle: https://en.wikipedia.org/wiki/Circle
Greetz,
Dimitri.
Last edited by dimitrip (July 15, 2015 16:51:33)
- kajdna
-
13 posts
Noob Help: How to Make a Wavy Line
Hi Kadjna.
The speed variable is there only to speed up a bit the drawing.
Instead of turning the cat 1° left or right at each step, it turns it 2°, or 3°, or more degrees (the “speed”).
Until about 15°, there is no noticeable difference in the drawing's resulting shape.
Of course, to make the half of a circle, you need to turn for a total of 180°.
That's why for each half circle, the repeat loop says “repeat 180/speed”).
Of course also, if you want quite the same result with a different “speed”, the distance that the cat has to move at each step must vary in function of the “speed”.
Here the distance the cat moves at each step, has been set to simply “speed/2”.
This is a rough approximation of what it should be. Because, the cat moves in straight line (a chord of the half circle*) and there is a difference between the length of the chord and the length of arc, specially when the angle of the arc becomes bigger.
If you mind, re-look at remix, I've been emphasizing the effect of changing the speed parameter.
(*) see wiki circle: https://en.wikipedia.org/wiki/Circle
Greetz,
Dimitri.
Hi Dimitri,
Just read your explanation now BEFORE I wrote the following, which I will add now, then go back to what you wrote above:
Hi Dimitri,
When I looked at your script I was quite mystified, for example, I had (and have) no idea why you set a block to speed 12. So, to simplify the script, I took out all the set speed instances and just re-calculated the math.
So the script gave the same output without that block. Then, I realized that everything above the outer repeat I understood, including the Sprite facing up.
The outer repeat just iterated the main motif of the squiggled circles, so I could remove that.
So the essence that I was left with (that I couldn't get in my script) included two consecutive repeats with two blocks in each.
The only thing I'm left with that I don't understand still is that if a circle is 360 degrees and a half-circle is 180 degrees, I don't understand how your script can give a half-circle at 12 degrees. Oh, wait, that's repeated 15 times, so maybe 12 degrees are added each time, so that's 15 x 12 = 180. Cool!
Intuitively, the number of steps and degrees you are using with the repeat of 3 makes no sense to me. So I think for the last step to understand this is that I'll select my own number of repeats, steps and degrees, using your same sequence of blocks, then use “guess and check” to get my numbers right to execute same. Maybe then I'll be clearer on what those numbers mean.
- dimitrip
-
500+ posts
Noob Help: How to Make a Wavy Line
Sure.
The most important if you want to draw half a circle, is that the number of times n that you repeat your (move+turn direction angle by speed), is at total 180°. So, n * speed = 180.
Since n equals 180 / speed[ (see repeat), then (180/speed)*speed always equals 180.
To draw the second half of circle, you just turn in the other direction.
The outer repeat 3 is just to have three consecutive waves (3 times twice half a circle), yes.
Greetz,
D.
The most important if you want to draw half a circle, is that the number of times n that you repeat your (move+turn direction angle by speed), is at total 180°. So, n * speed = 180.
Since n equals 180 / speed[ (see repeat), then (180/speed)*speed always equals 180.
To draw the second half of circle, you just turn in the other direction.
The outer repeat 3 is just to have three consecutive waves (3 times twice half a circle), yes.
Greetz,
D.
Last edited by dimitrip (July 17, 2015 08:14:10)
- Discussion Forums
- » Help with Scripts
-
» Noob Help: How to Make a Wavy Line