File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < meta charset ="utf-8 " />
3
+ < script src ="paint.js "> </ script >
4
+
5
+ < div > </ div >
6
+ < script >
7
+ function circle ( center , state , dispatch ) {
8
+ function drawCircle ( pos ) {
9
+ const radius = Math . floor ( Math . sqrt ( ( center . x - pos . x ) ** 2 + ( center . y - pos . y ) ** 2 ) ) ;
10
+
11
+ let drawn = [ ] ;
12
+ for ( let y = 0 ; y < state . picture . height ; y ++ ) {
13
+ for ( let x = 0 ; x < state . picture . width ; x ++ ) {
14
+ const distance = Math . sqrt ( ( center . x - x ) ** 2 + ( center . y - y ) ** 2 ) ;
15
+ if ( distance < radius ) {
16
+ drawn . push ( { x, y, color : state . color } ) ;
17
+ }
18
+ }
19
+ }
20
+ dispatch ( { picture : state . picture . draw ( drawn ) } ) ;
21
+ }
22
+ drawCircle ( center ) ;
23
+ return drawCircle ;
24
+ }
25
+
26
+ let dom = startPixelEditor ( {
27
+ tools : Object . assign ( { } , baseTools , { circle } ) ,
28
+ } ) ;
29
+ document . querySelector ( 'div' ) . appendChild ( dom ) ;
30
+ </ script >
You can’t perform that action at this time.
0 commit comments