-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDice.pck.st
118 lines (94 loc) · 3.59 KB
/
Dice.pck.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'From Cuis 6.0 [latest update: #5041] on 7 January 2022 at 2:31:31 pm'!
'Description A morph simulating a dice with an arbitrary number of faces, bellow 9.'!
!provides: 'Dice' 1 2!
SystemOrganization addCategory: 'Dice'!
!classDefinition: #DiceMorph category: 'Dice'!
BoxedMorph subclass: #DiceMorph
instanceVariableNames: 'faces value isRolling'
classVariableNames: ''
poolDictionaries: ''
category: 'Dice'!
!classDefinition: 'DiceMorph class' category: 'Dice'!
DiceMorph class
instanceVariableNames: ''!
!DiceMorph commentStamp: 'HilaireFernandes 10/28/2017 16:57:58' prior: 0!
Simulate a dice with an arbitrary number of faces. The dice can be rolling..
| dice |
dice := DiceMorph new openInWorld.
dice startRolling.
!
!DiceMorph methodsFor: 'drawing' stamp: 'hlsf 1/7/2022 14:21:20'!
drawDotOn: canvas at: aPoint
| radius center |
center _ aPoint * extent.
radius _ extent // 12.
canvas
ellipseCenter: center
radius: radius
borderWidth: 0 borderColor: Color black fillColor: Color black! !
!DiceMorph methodsFor: 'drawing' stamp: 'hlsf 1/7/2022 14:30:42'!
drawOn: canvas
canvas roundRect: self morphLocalBounds color: color radius: 10.
(self perform: ('face', value asString) asSymbol) do: [:eachPoint |
self drawDotOn: canvas at: eachPoint]! !
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:37:38'!
face1
! !
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:37:48'!
face2
^{[email protected] . [email protected]}! !
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:37:56'!
face3
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:38:07'!
face4
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:38:21'!
face5
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 16:17:29'!
face6
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:38:35'!
face7
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:38:46'!
face8
!DiceMorph methodsFor: 'faces' stamp: 'HilaireFernandes 10/28/2017 15:38:53'!
face9
!DiceMorph methodsFor: 'accessing' stamp: 'HilaireFernandes 10/28/2017 16:43:09'!
faces: integer
"Its number of faces"
faces _ integer min: 9.
self redrawNeeded ! !
!DiceMorph methodsFor: 'accessing' stamp: 'HilaireFernandes 10/28/2017 15:40:46'!
value
^ value! !
!DiceMorph methodsFor: 'initialization' stamp: 'HilaireFernandes 10/28/2017 16:48:31'!
initialize
super initialize.
extent _ 70@70.
faces _ 6.
value _ 1.
isRolling _ false! !
!DiceMorph methodsFor: 'stepping' stamp: 'HilaireFernandes 10/28/2017 16:55:24'!
startRolling
isRolling _ true.
self startStepping! !
!DiceMorph methodsFor: 'stepping' stamp: 'HilaireFernandes 10/28/2017 16:45:06'!
step
value _ faces atRandom.
self redrawNeeded ! !
!DiceMorph methodsFor: 'stepping' stamp: 'HilaireFernandes 10/28/2017 16:56:56'!
stepTime
^ 100! !
!DiceMorph methodsFor: 'stepping' stamp: 'HilaireFernandes 10/28/2017 16:56:02'!
stopRolling
isRolling _ false.
self stopStepping! !
!DiceMorph methodsFor: 'stepping' stamp: 'HilaireFernandes 10/28/2017 16:46:00'!
wantsSteps
^ isRolling! !