~rabbits/uxn

uxn/projects/demos/polycat.usm -rw-r--r-- 3.7 KiB
5294b92eneauoire Added cell count to GOL 23 hours ago
                                                                                
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
( polycat )

%RTN { JMP2r }
%+ { ADD2 } %- { SUB2 } 
%* { MUL2 } %/ { DIV2 } 
%> { GTH2 }

( devices )

|00 @System     [ &vector $2 &wst      $1 &rst    $1 &pad   $4 &r      $2 &g     $2 &b      $2 ]
|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y      $2 &addr  $2 &color $1 ]
|90 @Mouse      [ &vector $2 &x        $2 &y      $2 &state $1 &chord $1 ]

( variables )

|0000

@cat     [ &x $2 &y $2 &timer $1 ]
@pointer [ &x $2 &y $2 ]

( program )

|0100 ( -> )
	
	( theme ) 
	#0a3f .System/r DEO2 
	#05df .System/g DEO2 
	#0caf .System/b DEO2

	( find center )
	.Screen/width DEI2 #0002 / #0008 - .cat/x POK2
	.Screen/height DEI2 #0004 / #0003 * #0018 - .cat/y POK2

	( vectors )
	;on-mouse .Mouse/vector DEO2
	;on-frame .Screen/vector DEO2

	;draw-polycat JSR2
	;draw-ground JSR2

BRK

@on-mouse ( -> )
	
	;draw-cursor JSR2

	.Mouse/x DEI2 .cat/x PEK2 > #20 MUL
	.Mouse/y DEI2 .cat/y PEK2 > #40 MUL
		ADD #00 SWP ;draw-eye JSR2

BRK

@on-frame ( -> )

	.cat/timer PEK #01 ADD [ DUP ] .cat/timer POK
		DUP #00 NEQ ,&skip0 JNZ #0000 ;draw-tail JSR2 &skip0
		DUP #10 NEQ ,&skip1 JNZ #0001 ;draw-tail JSR2 &skip1
		DUP #20 NEQ ,&skip2 JNZ #0002 ;draw-tail JSR2 &skip2
		DUP #30 NEQ ,&skip3 JNZ #0003 ;draw-tail JSR2 &skip3
		DUP #40 NEQ ,&skip4 JNZ #0002 ;draw-tail JSR2 &skip4
		DUP #50 NEQ ,&skip5 JNZ #0001 ;draw-tail JSR2 &skip5
	POP

BRK

@draw-polycat ( -- )

	( ears )
	.cat/y PEK2 .Screen/y DEO2
	.cat/x PEK2 DUP2 STH2 #0008 - .Screen/x DEO2
	;ears .Screen/addr DEO2
	#41 .Screen/color DEO
	STH2r .Screen/x DEO2
	;ears #0010 + .Screen/addr DEO2
	#41 .Screen/color DEO

	#0000 ,draw-eye JSR
	#0000 ,draw-tail JSR

RTN

@draw-eye ( quad* -- )
	
	.cat/y PEK2 #0008 + .Screen/y DEO2
	.cat/x PEK2 DUP2 STH2 #0008 - .Screen/x DEO2
	DUP2 ;eye + .Screen/addr DEO2
	( draw ) #41 .Screen/color DEO
	STH2r .Screen/x DEO2
	;eye #0010 + + .Screen/addr DEO2
	( draw ) #41 .Screen/color DEO

RTN

@draw-tail ( frame* -- )

	.cat/y PEK2 #0010 + .Screen/y DEO2
	.cat/x PEK2 DUP2 STH2 #0008 - .Screen/x DEO2
	;body .Screen/addr DEO2
	( draw ) #41 .Screen/color DEO
	STH2r .Screen/x DEO2
	#0010 * ;body #0010 + + .Screen/addr DEO2
	( draw ) #41 .Screen/color DEO

RTN

@draw-cursor ( -- )
	
	( clear last cursor )
	;cursor .Screen/addr DEO2 
	.pointer/x PEK2 .Screen/x DEO2 
	.pointer/y PEK2 .Screen/y DEO2 
	#30 .Screen/color DEO

	( record pointer positions )
	.Mouse/x DEI2 .pointer/x POK2 
	.Mouse/y DEI2 .pointer/y POK2

	( draw new cursor )
	.pointer/x PEK2 .Screen/x DEO2 
	.pointer/y PEK2 .Screen/y DEO2 

	( colorize on state )
	#31 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/color DEO

RTN

@draw-ground ( -- )

	.cat/y PEK2 #0018 + .Screen/y DEO2
	.cat/x PEK2 #0010 - .Screen/x DEO2
	;ground .Screen/addr DEO2

	#00 #10
	&loop
		( draw ) #21 .Screen/color DEO
		( sety ) .Screen/addr DEI2 #0008 + .Screen/addr DEO2
		( setx ) .Screen/x DEI2 #0008 + .Screen/x DEO2
		( incr ) SWP #01 ADD SWP
		DUP2 LTH ,&loop JNZ
	POP2

RTN

@cursor [ 
	80c0 e0f0 f8e0 1000 ]

@ears [
	081c 3e3e 7f7f ffff 081c 3e3e 7f7f fffc
	081c 3c3e 7e7e ffff 081c 3c3e 7e7e ff1f ]

@eye [
	ffff ffff ff7f 3f0f f7ef cfe7 f07c 3f0f
	ffff ffff fffe fcf0 87c3 c183 071e fcf0
	ffff ffff ff7f 3f0f f0e1 c1e0 f07c 3f0f
	ffff ffff fffe fcf0 f7fb f9f3 071e fcf0
	ffff ffff ff7f 3f0f f0e7 cfef f77c 3f0f
	ffff ffff fffe fcf0 0783 c1c3 871e fcf0
	ffff ffff ff7f 3f0f f0e0 c1e1 f07c 3f0f
	ffff ffff fffe fcf0 07f3 f9fb f71e fcf0
]

@body [
	0707 0707 0302 0200 0107 0707 0300 0000
	e0f0 f0e0 e080 8000 c0f2 f9f9 fef8 b000
	e0f0 f0e0 e080 8000 c0f2 f9f9 fef8 b000
	e0f0 f0e0 e080 8000 c0f2 faf9 fef8 b000
	e0f0 f0e0 e080 8000 c0f1 faf9 fef8 b000
	0707 0707 0f08 1000 0307 0707 0f00 0000
	e0e0 e0e0 e080 8000 f2f9 f9fe b884 8400 ]

@ground [
	bf00 5c02 0202 020c ef10 6f90 8080 8074
	ff00 fe01 0100 0116 fd00 3c40 4040 4028 ]