Шаблон:Stub
A Bezier Curve is a smooth curve with many control points. It is infinitely scalable and often used in graphics and terrain generation. To make one in Scratch , one must use the following two methods:
Method 1
when clicked hide pen up set pen size to 2 forever erase all def p-line set pen color to draw p-line set pen color to 255 draw b-line steps: 90 end define set q-point A: A.x A.y B: B.x B.y progress: progress set q.x to A.x + progress * B.x - A.x set q.y to A.y + progress * B.y - A.y define def p-line delete all of p.x delete all of p.y add x position of P.00 to p.x add y position of P.00 to p.y add x position of P.01 to p.x add y position of P.01 to p.y add x position of P.02 to p.x add y position of P.02 to p.y add x position of P.03 to p.x add y position of P.03 to p.y add x position of P.04 to p.x add y position of P.04 to p.y add x position of P.05 to p.x add y position of P.05 to p.y add x position of P.06 to p.x add y position of P.06 to p.y add x position of P.07 to p.x add y position of P.07 to p.y add x position of P.08 to p.x add y position of P.08 to p.y add x position of P.09 to p.x add y position of P.09 to p.y add x position of P.10 to p.x add y position of P.10 to p.y add x position of P.11 to p.x add y position of P.11 to p.y add x position of P.12 to p.x add y position of P.12 to p.y add x position of P.13 to p.x add y position of P.13 to p.y define set b-point progress: progress delete all of b.x delete all of b.y repeat length of p.x add item length of b.x + 1 of p.x to b.x add item length of b.y + 1 of p.y to b.y end set index.n to 1 repeat length of b.x - index.n repeat length of b.x - index.n set q-point A: item index.n of b.x item index.n of b.y B: item index.n + 1 of b.x item index.n + 1 of b.y progress: progress add q.x to b.x add q.y to b.y change index.n by 1 end change index.n by 1 end define draw p-line set loop.n to 1 go to x: item loop.n of p.x y: item loop.n of p.y pen down repeat length of p.x - loop.n change loop.n by 1 go to x: item loop.n of p.x y: item loop.n of p.y end pen up define draw b-line steps: steps set loop.n to 0 set b-point progress: loop.n / steps go to x: q.x y: q.y pen down repeat steps - loop.n change loop.n by 1 set b-point progress: loop.n / steps go to x: q.x y: q.y end pen up
Method 2
One sprite needs this:
when clicked hide delete all of clone x delete all of clone y set drag mode draggable make clones define make clones set Clone ID to 1 repeat 10 create clone of myself add to clone x add to clone y end When I start as a clone show go to random position forever replace item clone ID of clone x with x position replace item clone ID of clone y with y position end
In another sprite, put this:
when clicked forever erase all draw line between dots Find curve points end define copy main points delete all of x delete all of y set counter to 1 repeat length of clone x add item counter of clone x to x add item counter of clone y to y change counter by 1 end define find curve points delete all of curve x delete all of curve y set t to 1 repeat 100 copy main points repeat until length of x = 1 find lines end add x to curve x add y to curve y change t by 1 end Draw curve define move t % to x: x y: y point in direction atan of x position - x / y position - y + 180 * y position < y move sqrt of x position - x * x position - x + y position - y * y position - y * t / 100 steps define find lines set line counter to 1 repeat length of x - 1 go to x: item line counter of x y: item line counter of y move t % to x: item line counter + 1 of x y: item line counter + 1 of y add x position to x add y position to y change line counter by 1 end repeat line counter - 1 delete 1 of x delete 1 of y end define Draw curve go to x: item 1 of curve x y: item 1 of curve y pen down set line counter to 1 repeat length of curve x go to x: item line counter of curve x y: item line counter of curve y change line counter by 1 end pen up define draw line between dots go to x: item 1 of clone x y: item 1 of clone y pen down set line counter to 1 repeat length of clone x go to x: item line counter of clone x y: item line counter of clone y change line counter by 1 end pen up
Example located here
Uses of Bezier Curves
There are many uses of Bezier curves within Scratch. These can include:
Combining them with velocity to make things fall or bounce.
Rendering a terrain with hills so that when one zooms in, the curve still looks nice.
Making customisable graphs.
See Also