]> 4ch.mooo.com Git - 16.git/blob - src/lib/bakapee.c
joncampbell123 i tried ww
[16.git] / src / lib / bakapee.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include "src/lib/bakapee.h"
24
25 /* clrstdin() clear any leftover chars tha may be in stdin stream */
26 void clrstdin()
27 {
28    int ch = 0;
29    while( ( ch = getchar() ) != '\n' && ch != EOF );
30 }
31
32 //color \82Ä\82·\82Æ
33 void colortest(page_t *page, bakapee_t *pee)
34 {
35         //if(pee->coor < 256)
36         //{
37                 modexcls(page, pee->coor, VGA);
38                 pee->coor++;
39         //}else pee->coor = 0;
40 }
41
42 //color \82Ä\82·\82Æ
43 void colorz(page_t *page, bakapee_t *pee)
44 {
45         if(pee->coor <= HGQ)
46         {
47                 modexcls(page, pee->coor, VGA);
48                 pee->coor++;
49         }else pee->coor = LGQ;
50 }
51
52 //slow spectrum down
53 void ssd(page_t *page, bakapee_t *pee, word svq)
54 {
55         if(pee->sy < page->sh+1)
56         {
57                 if(pee->sx < page->sw+1)
58                 {
59                         //mxPutPixel(sx, sy, coor);
60                         //printf("%d %d %d %d\n", pee->sx, pee->sy, svq, pee->coor);
61                         dingpp(page, pee);
62                         pee->sx++;
63                 }else pee->sx = 0;
64                 if(pee->sx == page->sw)
65                 {
66                         pee->sy++;
67                         if(svq == 7) pee->coor++;
68                         if(pee->sy == page->sh && svq == 8) pee->coor = rand()%256;
69                 }
70         }else pee->sy = 0;
71 }
72
73 //plot pixel or plot tile
74 void dingpp(page_t *page, bakapee_t *pee)
75 {
76         if(pee->tile)
77         {
78 #ifndef MXLIB
79         //fill_block(pee->xx, pee->yy, pee->xx+TILEWH, pee->yy+TILEWH, pee->coor);
80                 mxFillBox(pee->xx, pee->yy, TILEWH, TILEWH, pee->coor, OP_SET);
81 #else
82                 modexClearRegion(page, pee->xx, pee->yy, TILEWH, TILEWH, pee->coor);
83 #endif
84         }
85         else
86                 modexputPixel(page, pee->xx, pee->yy, pee->coor);
87 }
88
89 void dingo(page_t *page, bakapee_t *pee)
90 {
91         if(pee->tile)
92         {
93                 if(pee->xx<0) pee->xx=(page->sw-TILEWH);
94                 if(pee->yy<0) pee->yy=(page->sh-TILEWH);
95                 if(pee->xx>(page->sw-TILEWH)) pee->xx=0;
96                 if(pee->yy>(page->sh-TILEWH)/*+(TILEWH*BUFFMX)*/) pee->yy=0;
97         }
98                 else
99         {
100                 if(pee->xx<0) pee->xx=page->sw;
101                 if(pee->yy<0) pee->yy=page->sh;
102                 if(pee->xx>page->sw) pee->xx=0;
103                 if(pee->yy>page->sh) pee->yy=0;
104         }
105 }
106
107 //assigning values from randomizer
108 void dingas(bakapee_t *pee)
109 {
110         if(pee->gq == BONK) dingu(pee);
111         if(!pee->bakax)
112         {
113                 if(pee->tile)
114                 pee->xx-=TILEWH;
115                 else pee->xx--;
116         }
117         else if(pee->bakax>1)
118         {
119                 if(pee->tile)
120                 pee->xx+=TILEWH;
121                 else pee->xx++;
122         }
123         if(!pee->bakay)
124         {
125                 if(pee->tile)
126                 pee->yy-=TILEWH;
127                 else pee->yy--;
128         }
129         else if(pee->bakay>1)
130         {
131                 if(pee->tile)
132                 pee->yy+=TILEWH;
133                 else pee->yy++;
134         }
135 }
136
137 void dingu(bakapee_t *pee)
138 {
139         if(pee->coor < HGQ && pee->coor < LGQ) pee->coor = LGQ;
140         if(pee->coor < HGQ)
141         {
142                 pee->coor++;
143         }else{
144                 pee->coor = LGQ;
145         }
146 }
147
148 //randomizer
149 void dingq(bakapee_t *pee)
150 {
151         if(pee->gq<BONK)
152         {
153                 pee->gq++;
154         }
155         else
156         {
157                 dingu(pee);
158                 pee->gq = 0;
159         }
160         pee->bakax = rand()%3; pee->bakay = rand()%3;
161 }
162
163 /*-----------ding-------------*/
164 void ding(page_t *page, bakapee_t *pee, word q)
165 {
166         word d3y, tx=0,ty=0;
167
168 //++++  if(q <= 4 && q!=2 && gq == BONK-1) coor = rand()%HGQ;
169         switch(q)
170         {
171                 case 1:
172                         dingq(pee);
173                         if(pee->xx==page->sw){pee->bakax=0;}
174                         if(pee->xx==0){pee->bakax=1;}
175                         if(pee->yy==page->sh){pee->bakay=0;}
176                         if(pee->yy==0){pee->bakay=1;}
177                 break;
178                 case 2:
179                         dingq(pee);
180                         dingas(pee);
181                         dingo(page, pee);
182                         dingpp(page, pee);      //plot the pixel/tile
183                         if(pee->tile)
184                         modexClearRegion(page, (rand()*TILEWH)%page->width, (rand()*TILEWH)%(page->height), TILEWH, TILEWH, 0);
185                         else
186                         modexputPixel(page, rand()%page->width, rand()%page->height, 0);
187                 break;
188                 case 3:
189                         dingq(pee);
190                         if(pee->xx!=page->sw||pee->yy!=page->sh)
191                         {
192                                 if(pee->xx==0){pee->bakax=1;pee->bakay=-1;d3y=1;}
193                                 if(pee->yy==0){pee->bakax=1;pee->bakay=0;d3y=1;}
194                                 if(pee->xx==page->sw){pee->bakax=-1;pee->bakay=-1;d3y=1;}
195                                 if(pee->yy==page->sh){pee->bakax=1;pee->bakay=0;d3y=1;}
196                         }else if(pee->xx==page->sw&&pee->yy==page->sh) pee->xx=pee->yy=0;
197                         if(d3y)
198                         {
199                                 if(pee->bakay<0)
200                                 {
201                                         pee->yy--;
202                                         d3y--;
203                                 }else
204                                 if(pee->bakay>0)
205                                 {
206                                         pee->yy++;
207                                         d3y--;
208                                 }
209                         }
210                         if(pee->bakax<0)
211                         {
212                                 pee->xx--;
213                         }else
214                         if(pee->bakax>0)
215                         {
216                                 pee->xx++;
217                         }
218                         dingpp(page, pee);      //plot the pixel/tile
219                 break;
220                 case 4:
221                         dingq(pee);
222                         dingas(pee);
223                         dingo(page, pee);
224                         dingpp(page, pee);      //plot the pixel/tile
225                 break;
226                 case 5:
227                         colortest(page, pee);
228                 break;
229                 case 6:
230                         pee->coor = rand()%256;
231                         modexcls(page, pee->coor, VGA);
232                 break;
233                 case 7:
234                         if(pee->coor <= HGQ)
235                         {
236                                 ssd(page, pee, q);
237                                 pee->coor++;
238                         }else pee->coor = LGQ;
239                 break;
240                 case 8:
241                         colorz(page, pee);
242                         modexprint(page, page->sw/2, page->sh/2, 1, 47, 0, "bakapi");
243                 break;
244                 case 9:
245                         if(pee->coor <= HGQ)
246                         {
247                                 ssd(page, pee, q);
248                                 pee->coor++;
249                         }else pee->coor = LGQ;
250                 break;
251                 case 10:
252                         ssd(page, pee, q); /*printf("%d\n", pee->coor);*/
253                 break;
254                 case 11:
255                         colorz(page, pee); delay(100);
256                 break;
257
258                 case 16:        //interesting effects
259                         dingq(pee);
260                         if(!pee->bakax){ pee->xx--;}
261                         else if(pee->bakax>0){ pee->xx++; }
262                         if(!pee->bakay){ pee->yy--;}
263                         else if(pee->bakay>0){ pee->yy++; }
264                         dingas(pee);
265                         tx+=pee->xx+TILEWH+4;
266                         ty+=pee->yy+TILEWH+4;
267                         modexClearRegion(page, tx, ty, 4, 4, pee->coor);
268                         if(pee->tile)
269                         modexClearRegion(page, (rand()*TILEWH)%page->width, (rand()*TILEWH)%(page->height), TILEWH, TILEWH, 0);
270                         else
271                         modexputPixel(page, rand()%page->width, rand()%(page->height), 0);
272                         //printf("%d %d %d %d %d %d\n", pee->xx, pee->yy, tx, ty, TILEWH);
273                 break;
274                 default:
275                 break;
276         }
277         //pee->coor++;
278 }