22//% weight=100 color=#008080
33//% groups=[ "Create", "Properties", "Actions"]
44namespace circle {
5+ //% group="Create"
6+ //% block="destroy %circle=variables_get(myCircle)"
7+ export function destroy ( circle :Circle ) {
8+ circle . destroy ( )
9+ }
510 //% group="Create"
611 //% block="create circle of radius %radius and color $color || fill=$filled"
712 //% blockSetVariable=myCircle
@@ -11,131 +16,125 @@ namespace circle {
1116 export function createCircle ( radius : number , color : number , filled :boolean = false ) : Circle {
1217 return new Circle ( radius , color , filled )
1318 }
14-
15- //% group="Create"
16- //% block="destroy %circle=variables_get(myCircle)"
17- export function destroy ( circle :Circle ) {
18- circle . destroy ( )
19- }
2019}
2120//% blockNamespace=circle
2221class Circle {
23- _sprite : Sprite = null
24- _img : Image = null
25- _radius : number = 0
26- _color : number = 0
27- _fillColor : number = 0
28- _filled : boolean = false
29- _dataText :string = ""
30- _dataNumber :number = 0
31- imageWH : number = 0
32- centerXY :number = 0
33- constructor ( radius : number , color : number , filled : boolean = false ) {
34- this . _radius = radius
35- this . _color = color
36- this . _fillColor = 0 ;
37- this . _dataText = ""
38- this . _dataNumber = 0
39- this . _filled = filled
40- this . _fillColor = this . _color
41- this . imageWH = 2 * ( this . _radius + 2 )
42- this . centerXY = this . imageWH / 2
43- this . _img = image . create ( this . imageWH , this . imageWH )
44- this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color )
45- if ( this . _filled ) {
46- this . _img . fillCircle ( this . centerXY , this . centerXY , this . _radius , this . _fillColor )
47- }
48- this . _sprite = sprites . create ( this . _img )
49- }
50- //% group="Properties"
51- //% blockSetVariable="myCircle"
52- //% blockCombine block="data text"
53- get datatext ( ) : string {
54- return this . _dataText ;
55- }
56- //% group="Properties"
57- //% blockSetVariable="myCircle"
58- //% blockCombine block="data text"
59- set datatext ( value : string ) {
60- this . _dataText = value ;
61- }
62- //% group="Properties"
63- //% blockSetVariable="myCircle"
64- //% blockCombine block="data number"
65- get dataNumber ( ) : number {
66- return this . _dataNumber ;
67- }
68- //% group="Properties"
69- //% blockSetVariable="myCircle"
70- //% blockCombine block="data number"
71- set dataNumber ( value : number ) {
72- this . _dataNumber = value ;
73- }
74- //% group="Properties"
75- //% blockSetVariable="myCircle"
76- //% blockCombine block="color"
77- get color ( ) : number {
78- return this . _color ;
79- }
80- //% group="Properties"
81- //% blockSetVariable="myCircle"
82- //% blockCombine block="color"
83- set color ( value : number ) {
84- this . _color = value ;
85- this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color ) ;
86- }
87- //% group="Properties"
88- //% blockSetVariable="myCircle"
89- //% blockCombine block="radius"
90- get radius ( ) : number {
91- return this . _radius ;
92- }
93- //% group="Properties"
94- //% blockSetVariable="myCircle"
95- //% blockCombine block="fill color"
96- set fillColor ( value : number ) {
97- this . _fillColor = value ;
98- this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color ) ;
99- }
100- //% group="Properties"
101- //% blockSetVariable="myCircle"
102- //% blockCombine block="fill color"
103- get fillColor ( ) {
104- return this . _fillColor ;
105- }
106-
107- //% group="Properties"
108- //% blockSetVariable="myCircle"
109- //% blockCombine block="sprite"
110- get circle ( ) : Sprite {
111- return this . _sprite ;
112- }
113- //% group="Actions"
114- //% block="fill %Circle(myCircle) || with color $color"
115- fill ( color : number = - 1 ) {
116- this . _filled = true
117- if ( color == - 1 )
118- {
119- this . _fillColor = this . _color
120- } else {
121- this . _fillColor = color
122- }
22+ _sprite : Sprite = null
23+ _img : Image = null
24+ _radius : number = 0
25+ _color : number = 0
26+ _fillColor : number = 0
27+ _filled : boolean = false
28+ _dataText :string = ""
29+ _dataNumber :number = 0
30+ imageWH : number = 0
31+ centerXY :number = 0
32+ constructor ( radius : number , color : number , filled : boolean = false ) {
33+ this . _radius = radius
34+ this . _color = color
35+ this . _fillColor = 0 ;
36+ this . _dataText = ""
37+ this . _dataNumber = 0
38+ this . _filled = filled
39+ this . _fillColor = this . _color
40+ this . imageWH = 2 * ( this . _radius + 2 )
41+ this . centerXY = this . imageWH / 2
42+ this . _img = image . create ( this . imageWH , this . imageWH )
43+ this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color )
44+ if ( this . _filled ) {
12345 this . _img . fillCircle ( this . centerXY , this . centerXY , this . _radius , this . _fillColor )
12446 }
125- //% group="Actions"
126- //% block="erase fill from %Circle(myCircle)"
127- unfill ( ) {
128- this . _filled = false ;
129- this . _fillColor = 0 ;
130- this . _img . fill ( 0 ) ; //clear anything in image
131- this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color ) ;
47+ this . _sprite = sprites . create ( this . _img )
48+ }
49+ //% group="Properties"
50+ //% blockSetVariable="myCircle"
51+ //% blockCombine block="data text"
52+ get datatext ( ) : string {
53+ return this . _dataText ;
54+ }
55+ //% group="Properties"
56+ //% blockSetVariable="myCircle"
57+ //% blockCombine block="data text"
58+ set datatext ( value : string ) {
59+ this . _dataText = value ;
60+ }
61+ //% group="Properties"
62+ //% blockSetVariable="myCircle"
63+ //% blockCombine block="data number"
64+ get dataNumber ( ) : number {
65+ return this . _dataNumber ;
66+ }
67+ //% group="Properties"
68+ //% blockSetVariable="myCircle"
69+ //% blockCombine block="data number"
70+ set dataNumber ( value : number ) {
71+ this . _dataNumber = value ;
72+ }
73+ //% group="Properties"
74+ //% blockSetVariable="myCircle"
75+ //% blockCombine block="color"
76+ get color ( ) : number {
77+ return this . _color ;
78+ }
79+ //% group="Properties"
80+ //% blockSetVariable="myCircle"
81+ //% blockCombine block="color"
82+ set color ( value : number ) {
83+ this . _color = value ;
84+ this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color ) ;
85+ }
86+ //% group="Properties"
87+ //% blockSetVariable="myCircle"
88+ //% blockCombine block="radius"
89+ get radius ( ) : number {
90+ return this . _radius ;
91+ }
92+ //% group="Properties"
93+ //% blockSetVariable="myCircle"
94+ //% blockCombine block="fill color"
95+ set fillColor ( value : number ) {
96+ this . _fillColor = value ;
97+ this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color ) ;
98+ }
99+ //% group="Properties"
100+ //% blockSetVariable="myCircle"
101+ //% blockCombine block="fill color"
102+ get fillColor ( ) {
103+ return this . _fillColor ;
104+ }
105+
106+ //% group="Properties"
107+ //% blockSetVariable="myCircle"
108+ //% blockCombine block="sprite"
109+ get circle ( ) : Sprite {
110+ return this . _sprite ;
111+ }
112+ //% group="Actions"
113+ //% block="fill %Circle(myCircle) || with color $color"
114+ fill ( color : number = - 1 ) {
115+ this . _filled = true
116+ if ( color == - 1 )
117+ {
118+ this . _fillColor = this . _color
119+ } else {
120+ this . _fillColor = color
132121 }
133- destroy ( ) {
134- if ( this . _sprite != null ) {
135- this . _sprite . destroy ( )
136- }
122+ this . _img . fillCircle ( this . centerXY , this . centerXY , this . _radius , this . _fillColor )
123+ }
124+ //% group="Actions"
125+ //% block="erase fill from %Circle(myCircle)"
126+ unfill ( ) {
127+ this . _filled = false ;
128+ this . _fillColor = 0 ;
129+ this . _img . fill ( 0 ) ; //clear anything in image
130+ this . _img . drawCircle ( this . centerXY , this . centerXY , this . _radius , this . _color ) ;
131+ }
132+ destroy ( ) {
133+ if ( this . _sprite != null ) {
134+ this . _sprite . destroy ( )
137135 }
138136 }
137+ }
139138//% weight=100 color=#008080
140139//% groups=["List", "List Beginning", "List Middle", "List End"]
141140namespace circlelist {
@@ -151,11 +150,7 @@ class CircleList{
151150 _circles : Circle [ ] = [ ]
152151 constructor ( ) {
153152 }
154- //% group="List"
155- //% block="length of array %myCircleList"
156- length ( ) : number {
157- return this . _circles . length
158- }
153+
159154 //% group="List"
160155 //% block=" reverse %myCircleList"
161156 reverse ( ) {
@@ -169,6 +164,11 @@ class CircleList{
169164 }
170165 return - 1
171166 }
167+ //% group="List"
168+ //% block="length of array %myCircleList"
169+ length ( ) : number {
170+ return this . _circles . length
171+ }
172172 /*
173173 beginning
174174 */
0 commit comments