1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ ///|
1516#external
1617type Canvas_ctx
1718
18- fn begin_path (self : Canvas_ctx ) = "canvas" "begin_path"
19+ ///|
20+ fn Canvas_ctx ::begin_path (self : Canvas_ctx ) = "canvas" "begin_path"
1921
20- fn clear_rect (self : Canvas_ctx , x : Double , y : Double , w : Double ,
21- h : Double ) = "canvas" "clear_rect"
22+ ///|
23+ fn Canvas_ctx ::clear_rect (
24+ self : Canvas_ctx ,
25+ x : Double ,
26+ y : Double ,
27+ w : Double ,
28+ h : Double ,
29+ ) = "canvas" "clear_rect"
2230
23- fn move_to (self : Canvas_ctx , x : Double , y : Double ) = "canvas" "move_to"
31+ ///|
32+ fn Canvas_ctx ::move_to (self : Canvas_ctx , x : Double , y : Double ) = "canvas" "move_to"
2433
25- fn line_to (self : Canvas_ctx , x : Double , y : Double ) = "canvas" "line_to"
34+ ///|
35+ fn Canvas_ctx ::line_to (self : Canvas_ctx , x : Double , y : Double ) = "canvas" "line_to"
2636
27- fn stroke (self : Canvas_ctx ) = "canvas" "stroke"
37+ ///|
38+ fn Canvas_ctx ::stroke (self : Canvas_ctx ) = "canvas" "stroke"
2839
40+ ///|
2941fn sqrt (x : Double ) -> Double = "canvas" "sqrt"
3042
43+ ///|
3144fn cos (x : Double ) -> Double = "canvas" "cos"
3245
46+ ///|
3347fn get_pi () -> Double = "canvas" "get_pi"
3448
35- fn koch (ctx : Canvas_ctx , x1 : Double , y1 : Double , x2 : Double ,
36- y2 : Double , n : Double , m : Double ) -> Unit {
49+ ///|
50+ fn koch (
51+ ctx : Canvas_ctx ,
52+ x1 : Double ,
53+ y1 : Double ,
54+ x2 : Double ,
55+ y2 : Double ,
56+ n : Double ,
57+ m : Double ,
58+ ) -> Unit {
3759 ctx .clear_rect (0.0 , 0.0 , 400.0 , 400.0 )
3860 let x3 = (x2 - x1 ) / 3.0 + x1
3961 let y3 = (y2 - y1 ) / 3.0 + y1
@@ -57,11 +79,11 @@ fn koch(ctx : Canvas_ctx, x1 : Double, y1 : Double, x2 : Double,
5779 koch (ctx , x4 , y4 , x2 , y2 , n , m )
5880}
5981
82+ ///|
6083pub fn draw (ctx : Canvas_ctx , deep : Double ) -> Unit {
6184 ctx .begin_path ()
6285 let y = 80.0 + cos (get_pi () / 6.0 ) * 200.0
6386 koch (ctx , 150.0 , y , 250.0 , 80.0 , 0.0 , deep )
6487 koch (ctx , 250.0 , 80.0 , 50.0 , 80.0 , 0.0 , deep )
6588 koch (ctx , 50.0 , 80.0 , 150.0 , y , 0.0 , deep )
6689}
67-
0 commit comments