Another small update to gui.
[Python-Scripts.git] / PySmile / pysmile.py
blobe127ab1da8c0fa2c9e46267050646f25bea4445f
1 #!/usr/bin/python2
3 import gzip, bz2, binascii, os, re, sys, math, time;
5 enable_gfxdraw = False;
6 code_output = "Python";
8 if(len(sys.argv)>2 and (sys.argv[2]=="C" or sys.argv[2]=="Python" or sys.argv[2]=="Py")):
9 code_output = sys.argv[2];
11 if(len(sys.argv)>3 and sys.argv[3]=="draw"):
12 enable_gfxdraw = False;
14 if(len(sys.argv)>3 and sys.argv[3]=="gfxdraw"):
15 enable_gfxdraw = True;
17 if(code_output=="Python" or code_output=="Py"):
18 print "#!/usr/bin/python2\n";
19 print "import gzip, bz2, binascii, os, re, sys, math, time, pygame, pygame.draw, pygame.gfxdraw;";
20 print "from pygame.locals import *;\n";
21 print "pygame.init();";
22 print "pygame.display.init();";
23 print "tstart = time.clock();";
24 print "pyicon = pygame.image.load(\"./icon.png\");";
25 print "pygame.display.set_icon(pyicon);";
26 print "ds_screen = pygame.display.set_mode((256, 384), pygame.HWSURFACE | pygame.DOUBLEBUF);";
27 print "pygame.display.set_caption(\"Petit Computer\");";
28 print "ds_screen.fill((0, 0, 0));";
29 print "pygame.display.update();\n";
30 print "ds_top_screen = pygame.Surface((256, 192));";
31 print "ds_top_screen.fill((0, 0, 0));";
32 print "ds_bottom_screen = pygame.Surface((256, 192));";
33 print "ds_bottom_screen.fill((0, 0, 0));";
34 print "draw_screen = ds_top_screen;";
35 print "ptgcolor = 0;";
36 print "done = False;\n";
37 print "# We need this if we want to be able to specify our";
38 print "# arc in degrees instead of radians";
39 print "def degreesToRadians(deg):";
40 print " return deg / 180.0 * math.pi;\n";
41 print "# Draw an arc that is a portion of a circle.";
42 print "# We pass in screen and color,";
43 print "# followed by a tuple (x,y) that is the center of the circle, and the radius.";
44 print "# Next comes the start and ending angle on the \"unit circle\" (0 to 360)";
45 print "# of the circle we want to draw, and finally the thickness in pixels";
46 print "def drawCircleArc(screen, color, center, radius, startDeg, endDeg, thickness):";
47 print " (x, y) = center;";
48 print " rect = (x - radius, y - radius, radius * 2, radius * 2);";
49 print " startRad = degreesToRadians(startDeg);";
50 print " endRad = degreesToRadians(endDeg);";
51 print " pygame.draw.arc(screen, color, rect, startRad, endRad, thickness);\n";
53 if(code_output=="C"):
54 print "#include \"stdio.h\"";
55 print "#include \"stdbool.h\"";
56 print "#include \"SDL.h\"\n";
57 print "#include \"SDL_gfxPrimitives.h\"\n";
58 print "int main ( int argc, char *argv[] )\n{";
59 print " bool done;";
60 print " SDL_Event event;";
61 print " SDL_Surface* ds_screen;";
62 print " SDL_Surface* ds_top_screen;";
63 print " SDL_Surface* ds_bottom_screen;";
64 print " SDL_Rect ds_top_screen_rect;";
65 print " SDL_Rect ds_bottom_screen_rect;\n";
66 print " ds_top_screen_rect.x = 0;";
67 print " ds_top_screen_rect.y = 0;";
68 print " ds_bottom_screen_rect.x = 0;";
69 print " ds_bottom_screen_rect.y = 192;\n";
70 print " SDL_Init(SDL_INIT_VIDEO);";
71 print " SDL_WM_SetCaption(\"Petit Computer\", \"Petit Computer\");";
72 print " ds_screen = SDL_SetVideoMode(256, 384, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);";
73 print " ds_top_screen = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF, 256, 192, 24, 0, 0, 0, 0);";
74 print " SDL_FillRect(ds_top_screen, NULL, SDL_MapRGB(ds_top_screen->format, 0, 0, 0));";
75 print " SDL_Flip(ds_top_screen);";
76 print " SDL_BlitSurface(ds_top_screen, NULL, ds_screen, &ds_top_screen_rect);";
77 print " ds_bottom_screen = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF, 256, 192, 24, 0, 0, 0, 0);";
78 print " SDL_FillRect(ds_bottom_screen, NULL, SDL_MapRGB(ds_bottom_screen->format, 0, 0, 0));";
79 print " SDL_Flip(ds_bottom_screen);";
80 print " SDL_BlitSurface(ds_bottom_screen, NULL, ds_screen, &ds_bottom_screen_rect);";
81 print " SDL_Flip(ds_screen);\n";
83 def SmileBasic_Console_Palette(sb_color):
84 if(sb_color==0):
85 return (0, 0, 0);
86 if(sb_color==1):
87 return (57, 56, 57);
88 if(sb_color==2):
89 return (255, 24, 0);
90 if(sb_color==3):
91 return (255, 89, 198);
92 if(sb_color==4):
93 return (0, 56, 247);
94 if(sb_color==5):
95 return (123, 56, 255);
96 if(sb_color==6):
97 return (0, 186, 255);
98 if(sb_color==7):
99 return (148, 89, 41);
100 if(sb_color==8):
101 return (255, 162, 0);
102 if(sb_color==9):
103 return (255, 203, 165);
104 if(sb_color==10):
105 return (0, 121, 0);
106 if(sb_color==11):
107 return (0, 243, 24);
108 if(sb_color==12):
109 return (255, 227, 0);
110 if(sb_color==13):
111 return (189, 186, 189);
112 if(sb_color==14):
113 return (0, 0, 0);
114 if(sb_color==15):
115 return (255, 251, 255);
116 if(sb_color==16):
117 return (0, 0, 0);
118 if(sb_color==17):
119 return (41, 40, 41);
120 if(sb_color==18):
121 return (140, 48, 41);
122 if(sb_color==19):
123 return (156, 89, 132);
124 if(sb_color==20):
125 return (33, 56, 132);
126 if(sb_color==21):
127 return (99, 73, 148);
128 if(sb_color==22):
129 return (41, 113, 140);
130 if(sb_color==23):
131 return (90, 65, 49);
132 if(sb_color==24):
133 return (140, 97, 41);
134 if(sb_color==25):
135 return (165, 146, 132);
136 if(sb_color==26):
137 return (16, 65, 16);
138 if(sb_color==27):
139 return (33, 130, 49);
140 if(sb_color==28):
141 return (140, 121, 41);
142 if(sb_color==29):
143 return (132, 130, 132);
144 if(sb_color==30):
145 return (255, 251, 255);
146 if(sb_color==31):
147 return (0, 0, 0);
148 if(sb_color==32):
149 return (0, 0, 0);
150 if(sb_color==33):
151 return (16, 48, 82);
152 if(sb_color==34):
153 return (66, 97, 255);
154 if(sb_color==35):
155 return (181, 211, 255);
156 if(sb_color==36):
157 return (173, 0, 0);
158 if(sb_color==37):
159 return (255, 65, 16);
160 if(sb_color==38):
161 return (255, 195, 189);
162 if(sb_color==39):
163 return (115, 73, 24);
164 if(sb_color==40):
165 return (206, 178, 123);
166 if(sb_color==41):
167 return (255, 227, 181);
168 if(sb_color==42):
169 return (66, 65, 66);
170 if(sb_color==43):
171 return (148, 146, 148);
172 if(sb_color==44):
173 return (231, 227, 231);
174 if(sb_color==45):
175 return (255, 251, 255);
176 if(sb_color==46):
177 return (0, 0, 0);
178 if(sb_color==47):
179 return (189, 186, 189);
180 if(sb_color==48):
181 return (0, 0, 0);
182 if(sb_color==49):
183 return (82, 0, 0);
184 if(sb_color==50):
185 return (181, 24, 0);
186 if(sb_color==51):
187 return (255, 97, 82);
188 if(sb_color==52):
189 return (74, 65, 16);
190 if(sb_color==53):
191 return (123, 97, 49);
192 if(sb_color==54):
193 return (198, 162, 99);
194 if(sb_color==55):
195 return (115, 105, 0);
196 if(sb_color==56):
197 return (189, 178, 0);
198 if(sb_color==57):
199 return (255, 251, 0);
200 if(sb_color==58):
201 return (90, 56, 255);
202 if(sb_color==59):
203 return (148, 130, 255);
204 if(sb_color==60):
205 return (222, 211, 255);
206 if(sb_color==61):
207 return (255, 251, 255);
208 if(sb_color==62):
209 return (0, 0, 0);
210 if(sb_color==63):
211 return (255, 227, 0);
212 if(sb_color==64):
213 return (0, 0, 0);
214 if(sb_color==65):
215 return (123, 0, 0);
216 if(sb_color==66):
217 return (255, 40, 24);
218 if(sb_color==67):
219 return (255, 146, 107);
220 if(sb_color==68):
221 return (0, 73, 255);
222 if(sb_color==69):
223 return (0, 178, 255);
224 if(sb_color==70):
225 return (82, 251, 255);
226 if(sb_color==71):
227 return (140, 73, 0);
228 if(sb_color==72):
229 return (198, 154, 90);
230 if(sb_color==73):
231 return (255, 203, 123);
232 if(sb_color==74):
233 return (0, 113, 0);
234 if(sb_color==75):
235 return (0, 227, 0);
236 if(sb_color==76):
237 return (156, 251, 156);
238 if(sb_color==77):
239 return (255, 251, 255);
240 if(sb_color==78):
241 return (0, 0, 0);
242 if(sb_color==79):
243 return (0, 243, 24);
244 if(sb_color==80):
245 return (0, 0, 0);
246 if(sb_color==81):
247 return (0, 73, 165);
248 if(sb_color==82):
249 return (107, 130, 255);
250 if(sb_color==83):
251 return (181, 211, 255);
252 if(sb_color==84):
253 return (33, 73, 8);
254 if(sb_color==85):
255 return (33, 146, 0);
256 if(sb_color==86):
257 return (16, 243, 0);
258 if(sb_color==87):
259 return (140, 97, 49);
260 if(sb_color==88):
261 return (189, 170, 82);
262 if(sb_color==89):
263 return (239, 227, 156);
264 if(sb_color==90):
265 return (148, 32, 0);
266 if(sb_color==91):
267 return (222, 65, 0);
268 if(sb_color==92):
269 return (255, 130, 74);
270 if(sb_color==93):
271 return (255, 251, 255);
272 if(sb_color==94):
273 return (0, 0, 0);
274 if(sb_color==95):
275 return (0, 121, 0);
276 if(sb_color==96):
277 return (0, 0, 0);
278 if(sb_color==97):
279 return (99, 81, 0);
280 if(sb_color==98):
281 return (255, 251, 0);
282 if(sb_color==99):
283 return (255, 251, 156);
284 if(sb_color==100):
285 return (156, 0, 66);
286 if(sb_color==101):
287 return (255, 0, 132);
288 if(sb_color==102):
289 return (255, 178, 214);
290 if(sb_color==103):
291 return (148, 97, 24);
292 if(sb_color==104):
293 return (214, 195, 123);
294 if(sb_color==105):
295 return (255, 251, 239);
296 if(sb_color==106):
297 return (33, 178, 0);
298 if(sb_color==107):
299 return (99, 251, 74);
300 if(sb_color==108):
301 return (206, 251, 189);
302 if(sb_color==109):
303 return (255, 251, 255);
304 if(sb_color==110):
305 return (0, 0, 0);
306 if(sb_color==111):
307 return (255, 203, 165);
308 if(sb_color==112):
309 return (0, 0, 0);
310 if(sb_color==113):
311 return (99, 0, 107);
312 if(sb_color==114):
313 return (255, 0, 255);
314 if(sb_color==115):
315 return (255, 113, 255);
316 if(sb_color==116):
317 return (74, 73, 0);
318 if(sb_color==117):
319 return (189, 178, 16);
320 if(sb_color==118):
321 return (255, 251, 0);
322 if(sb_color==119):
323 return (181, 97, 24);
324 if(sb_color==120):
325 return (247, 195, 123);
326 if(sb_color==121):
327 return (255, 251, 239);
328 if(sb_color==122):
329 return (66, 65, 255);
330 if(sb_color==123):
331 return (132, 130, 255);
332 if(sb_color==124):
333 return (222, 219, 255);
334 if(sb_color==125):
335 return (255, 251, 255);
336 if(sb_color==126):
337 return (0, 0, 0);
338 if(sb_color==127):
339 return (255, 162, 0);
340 if(sb_color==128):
341 return (0, 0, 0);
342 if(sb_color==129):
343 return (74, 32, 8);
344 if(sb_color==130):
345 return (99, 56, 16);
346 if(sb_color==131):
347 return (123, 65, 24);
348 if(sb_color==132):
349 return (148, 89, 41);
350 if(sb_color==133):
351 return (181, 121, 66);
352 if(sb_color==134):
353 return (206, 170, 115);
354 if(sb_color==135):
355 return (33, 113, 0);
356 if(sb_color==136):
357 return (16, 162, 16);
358 if(sb_color==137):
359 return (74, 211, 90);
360 if(sb_color==138):
361 return (148, 138, 231);
362 if(sb_color==139):
363 return (189, 178, 239);
364 if(sb_color==140):
365 return (222, 211, 255);
366 if(sb_color==141):
367 return (255, 251, 255);
368 if(sb_color==142):
369 return (0, 0, 0);
370 if(sb_color==143):
371 return (148, 89, 41);
372 if(sb_color==144):
373 return (0, 0, 0);
374 if(sb_color==145):
375 return (33, 0, 0);
376 if(sb_color==146):
377 return (66, 24, 0);
378 if(sb_color==147):
379 return (123, 56, 0);
380 if(sb_color==148):
381 return (132, 73, 33);
382 if(sb_color==149):
383 return (148, 97, 41);
384 if(sb_color==150):
385 return (165, 121, 74);
386 if(sb_color==151):
387 return (0, 48, 0);
388 if(sb_color==152):
389 return (0, 97, 24);
390 if(sb_color==153):
391 return (33, 154, 66);
392 if(sb_color==154):
393 return (99, 65, 181);
394 if(sb_color==155):
395 return (165, 138, 214);
396 if(sb_color==156):
397 return (198, 178, 247);
398 if(sb_color==157):
399 return (181, 219, 255);
400 if(sb_color==158):
401 return (0, 0, 0);
402 if(sb_color==159):
403 return (0, 186, 255);
404 if(sb_color==160):
405 return (0, 0, 0);
406 if(sb_color==161):
407 return (0, 32, 0);
408 if(sb_color==162):
409 return (41, 81, 41);
410 if(sb_color==163):
411 return (90, 121, 90);
412 if(sb_color==164):
413 return (132, 170, 132);
414 if(sb_color==165):
415 return (181, 211, 181);
416 if(sb_color==166):
417 return (231, 251, 231);
418 if(sb_color==167):
419 return (132, 89, 0);
420 if(sb_color==168):
421 return (173, 146, 49);
422 if(sb_color==169):
423 return (214, 203, 148);
424 if(sb_color==170):
425 return (132, 105, 0);
426 if(sb_color==171):
427 return (255, 251, 0);
428 if(sb_color==172):
429 return (255, 251, 214);
430 if(sb_color==173):
431 return (255, 251, 255);
432 if(sb_color==174):
433 return (0, 0, 0);
434 if(sb_color==175):
435 return (123, 56, 255);
436 if(sb_color==176):
437 return (0, 0, 0);
438 if(sb_color==177):
439 return (57, 56, 57);
440 if(sb_color==178):
441 return (82, 81, 90);
442 if(sb_color==179):
443 return (123, 121, 132);
444 if(sb_color==180):
445 return (156, 162, 173);
446 if(sb_color==181):
447 return (181, 186, 198);
448 if(sb_color==182):
449 return (206, 211, 231);
450 if(sb_color==183):
451 return (222, 121, 0);
452 if(sb_color==184):
453 return (255, 195, 16);
454 if(sb_color==185):
455 return (255, 251, 90);
456 if(sb_color==186):
457 return (231, 24, 0);
458 if(sb_color==187):
459 return (255, 97, 57);
460 if(sb_color==188):
461 return (255, 154, 156);
462 if(sb_color==189):
463 return (255, 251, 255);
464 if(sb_color==190):
465 return (0, 0, 0);
466 if(sb_color==191):
467 return (0, 56, 247);
468 if(sb_color==192):
469 return (0, 0, 0);
470 if(sb_color==193):
471 return (0, 32, 132);
472 if(sb_color==194):
473 return (16, 48, 148);
474 if(sb_color==195):
475 return (57, 81, 165);
476 if(sb_color==196):
477 return (115, 138, 198);
478 if(sb_color==197):
479 return (173, 186, 231);
480 if(sb_color==198):
481 return (222, 227, 255);
482 if(sb_color==199):
483 return (8, 32, 57);
484 if(sb_color==200):
485 return (99, 113, 156);
486 if(sb_color==201):
487 return (181, 203, 255);
488 if(sb_color==202):
489 return (132, 8, 0);
490 if(sb_color==203):
491 return (255, 32, 0);
492 if(sb_color==204):
493 return (255, 211, 173);
494 if(sb_color==205):
495 return (255, 251, 255);
496 if(sb_color==206):
497 return (0, 0, 0);
498 if(sb_color==207):
499 return (255, 89, 198);
500 if(sb_color==208):
501 return (0, 0, 0);
502 if(sb_color==209):
503 return (148, 40, 0);
504 if(sb_color==210):
505 return (156, 56, 24);
506 if(sb_color==211):
507 return (173, 81, 49);
508 if(sb_color==212):
509 return (193, 113, 99);
510 if(sb_color==213):
511 return (239, 178, 165);
512 if(sb_color==214):
513 return (255, 211, 206);
514 if(sb_color==215):
515 return (57, 32, 8);
516 if(sb_color==216):
517 return (156, 113, 99);
518 if(sb_color==217):
519 return (255, 203, 181);
520 if(sb_color==218):
521 return (0, 8, 156);
522 if(sb_color==219):
523 return (0, 130, 255);
524 if(sb_color==220):
525 return (173, 211, 255);
526 if(sb_color==221):
527 return (255, 251, 255);
528 if(sb_color==222):
529 return (0, 0, 0);
530 if(sb_color==223):
531 return (255, 24, 0);
532 if(sb_color==224):
533 return (0, 0, 0);
534 if(sb_color==225):
535 return (41, 48, 0);
536 if(sb_color==226):
537 return (82, 89, 24);
538 if(sb_color==227):
539 return (115, 113, 49);
540 if(sb_color==228):
541 return (156, 154, 74);
542 if(sb_color==229):
543 return (198, 195, 107);
544 if(sb_color==230):
545 return (247, 243, 140);
546 if(sb_color==231):
547 return (107, 89, 0);
548 if(sb_color==232):
549 return (165, 113, 0);
550 if(sb_color==233):
551 return (231, 211, 132);
552 if(sb_color==234):
553 return (132, 8, 148);
554 if(sb_color==235):
555 return (255, 32, 173);
556 if(sb_color==236):
557 return (255, 170, 255);
558 if(sb_color==237):
559 return (255, 251, 255);
560 if(sb_color==238):
561 return (0, 0, 0);
562 if(sb_color==239):
563 return (57, 56, 57);
564 if(sb_color==240):
565 return (99, 97, 99);
566 if(sb_color==241):
567 return (123, 121, 123);
568 if(sb_color==242):
569 return (132, 130, 132);
570 if(sb_color==243):
571 return (148, 146, 148);
572 if(sb_color==244):
573 return (156, 154, 156);
574 if(sb_color==245):
575 return (165, 162, 165);
576 if(sb_color==246):
577 return (173, 170, 173);
578 if(sb_color==247):
579 return (189, 186, 189);
580 if(sb_color==248):
581 return (198, 195, 198);
582 if(sb_color==249):
583 return (206, 203, 206);
584 if(sb_color==250):
585 return (214, 211, 214);
586 if(sb_color==251):
587 return (231, 227, 231);
588 if(sb_color==252):
589 return (49, 48, 49);
590 if(sb_color==253):
591 return (181, 178, 181);
592 if(sb_color==254):
593 return (0, 0, 0);
594 if(sb_color==255):
595 return (239, 235, 239);
596 return (0, 0, 0);
598 def SmileBasic_Hex_Console_Palette(sb_color):
599 return SmileBasic_Console_Palette(int(sb_code, 16));
601 def SmileBasic_Graphic_Palette(sb_color):
602 if(sb_color==0):
603 return (0, 0, 0);
604 if(sb_color==1):
605 return (57, 56, 57);
606 if(sb_color==2):
607 return (255, 24, 0);
608 if(sb_color==3):
609 return (255, 89, 198);
610 if(sb_color==4):
611 return (0, 56, 247);
612 if(sb_color==5):
613 return (123, 56, 255);
614 if(sb_color==6):
615 return (0, 186, 255);
616 if(sb_color==7):
617 return (148, 89, 41);
618 if(sb_color==8):
619 return (255, 162, 0);
620 if(sb_color==9):
621 return (255, 203, 165);
622 if(sb_color==10):
623 return (0, 121, 0);
624 if(sb_color==11):
625 return (0, 243, 24);
626 if(sb_color==12):
627 return (255, 227, 0);
628 if(sb_color==13):
629 return (189, 186, 189);
630 if(sb_color==14):
631 return (0, 0, 0);
632 if(sb_color==15):
633 return (255, 251, 255);
634 if(sb_color==16):
635 return (0, 0, 0);
636 if(sb_color==17):
637 return (41, 40, 41);
638 if(sb_color==18):
639 return (140, 48, 41);
640 if(sb_color==19):
641 return (156, 89, 132);
642 if(sb_color==20):
643 return (33, 56, 132);
644 if(sb_color==21):
645 return (99, 73, 148);
646 if(sb_color==22):
647 return (41, 113, 140);
648 if(sb_color==23):
649 return (90, 65, 49);
650 if(sb_color==24):
651 return (140, 97, 41);
652 if(sb_color==25):
653 return (165, 146, 132);
654 if(sb_color==26):
655 return (16, 65, 16);
656 if(sb_color==27):
657 return (33, 130, 49);
658 if(sb_color==28):
659 return (140, 121, 41);
660 if(sb_color==29):
661 return (132, 130, 132);
662 if(sb_color==30):
663 return (255, 251, 255);
664 if(sb_color==31):
665 return (0, 0, 0);
666 if(sb_color==32):
667 return (255, 251, 255);
668 if(sb_color==33):
669 return (255, 251, 206);
670 if(sb_color==34):
671 return (255, 251, 156);
672 if(sb_color==35):
673 return (255, 251, 99);
674 if(sb_color==36):
675 return (255, 251, 49);
676 if(sb_color==37):
677 return (255, 251, 0);
678 if(sb_color==38):
679 return (255, 203, 255);
680 if(sb_color==39):
681 return (255, 203, 206);
682 if(sb_color==40):
683 return (255, 203, 156);
684 if(sb_color==41):
685 return (255, 203, 99);
686 if(sb_color==42):
687 return (255, 203, 49);
688 if(sb_color==43):
689 return (255, 203, 0);
690 if(sb_color==44):
691 return (255, 154, 255);
692 if(sb_color==45):
693 return (255, 154, 206);
694 if(sb_color==46):
695 return (255, 154, 156);
696 if(sb_color==47):
697 return (255, 154, 99);
698 if(sb_color==48):
699 return (255, 154, 49);
700 if(sb_color==49):
701 return (255, 154, 0);
702 if(sb_color==50):
703 return (255, 97, 255);
704 if(sb_color==51):
705 return (255, 97, 206);
706 if(sb_color==52):
707 return (255, 97, 156);
708 if(sb_color==53):
709 return (255, 97, 99);
710 if(sb_color==54):
711 return (255, 97, 49);
712 if(sb_color==55):
713 return (255, 97, 0);
714 if(sb_color==56):
715 return (255, 48, 255);
716 if(sb_color==57):
717 return (255, 48, 206);
718 if(sb_color==58):
719 return (255, 48, 156);
720 if(sb_color==59):
721 return (255, 48, 99);
722 if(sb_color==60):
723 return (255, 48, 49);
724 if(sb_color==61):
725 return (255, 48, 0);
726 if(sb_color==62):
727 return (255, 0, 255);
728 if(sb_color==63):
729 return (255, 0, 206);
730 if(sb_color==64):
731 return (255, 0, 156);
732 if(sb_color==65):
733 return (255, 0, 99);
734 if(sb_color==66):
735 return (255, 0, 49);
736 if(sb_color==67):
737 return (255, 0, 0);
738 if(sb_color==68):
739 return (206, 251, 255);
740 if(sb_color==69):
741 return (206, 251, 206);
742 if(sb_color==70):
743 return (206, 251, 156);
744 if(sb_color==71):
745 return (206, 251, 99);
746 if(sb_color==72):
747 return (206, 251, 49);
748 if(sb_color==73):
749 return (206, 251, 0);
750 if(sb_color==74):
751 return (206, 203, 255);
752 if(sb_color==75):
753 return (206, 203, 206);
754 if(sb_color==76):
755 return (206, 203, 156);
756 if(sb_color==77):
757 return (206, 203, 99);
758 if(sb_color==78):
759 return (206, 203, 49);
760 if(sb_color==79):
761 return (206, 203, 0);
762 if(sb_color==80):
763 return (206, 154, 255);
764 if(sb_color==81):
765 return (206, 154, 206);
766 if(sb_color==82):
767 return (206, 154, 156);
768 if(sb_color==83):
769 return (206, 154, 99);
770 if(sb_color==84):
771 return (206, 154, 49);
772 if(sb_color==85):
773 return (206, 154, 0);
774 if(sb_color==86):
775 return (206, 97, 255);
776 if(sb_color==87):
777 return (206, 97, 206);
778 if(sb_color==88):
779 return (206, 97, 156);
780 if(sb_color==89):
781 return (206, 97, 99);
782 if(sb_color==90):
783 return (206, 97, 49);
784 if(sb_color==91):
785 return (206, 97, 0);
786 if(sb_color==92):
787 return (206, 48, 255);
788 if(sb_color==93):
789 return (206, 48, 206);
790 if(sb_color==94):
791 return (206, 48, 156);
792 if(sb_color==95):
793 return (206, 48, 99);
794 if(sb_color==96):
795 return (206, 48, 49);
796 if(sb_color==97):
797 return (206, 48, 0);
798 if(sb_color==98):
799 return (206, 0, 255);
800 if(sb_color==99):
801 return (206, 0, 206);
802 if(sb_color==100):
803 return (206, 0, 156);
804 if(sb_color==101):
805 return (206, 0, 99);
806 if(sb_color==102):
807 return (206, 0, 49);
808 if(sb_color==103):
809 return (206, 0, 0);
810 if(sb_color==104):
811 return (156, 251, 255);
812 if(sb_color==105):
813 return (156, 251, 206);
814 if(sb_color==106):
815 return (156, 251, 156);
816 if(sb_color==107):
817 return (156, 251, 99);
818 if(sb_color==108):
819 return (156, 251, 49);
820 if(sb_color==109):
821 return (156, 251, 0);
822 if(sb_color==110):
823 return (156, 203, 255);
824 if(sb_color==111):
825 return (156, 203, 206);
826 if(sb_color==112):
827 return (156, 203, 156);
828 if(sb_color==113):
829 return (156, 203, 99);
830 if(sb_color==114):
831 return (156, 203, 49);
832 if(sb_color==115):
833 return (156, 203, 0);
834 if(sb_color==116):
835 return (156, 154, 255);
836 if(sb_color==117):
837 return (156, 154, 206);
838 if(sb_color==118):
839 return (156, 154, 156);
840 if(sb_color==119):
841 return (156, 154, 99);
842 if(sb_color==120):
843 return (156, 154, 49);
844 if(sb_color==121):
845 return (156, 154, 0);
846 if(sb_color==122):
847 return (156, 97, 255);
848 if(sb_color==123):
849 return (156, 97, 206);
850 if(sb_color==124):
851 return (156, 97, 156);
852 if(sb_color==125):
853 return (156, 97, 99);
854 if(sb_color==126):
855 return (156, 97, 49);
856 if(sb_color==127):
857 return (156, 97, 0);
858 if(sb_color==128):
859 return (156, 48, 255);
860 if(sb_color==129):
861 return (156, 48, 206);
862 if(sb_color==130):
863 return (156, 48, 156);
864 if(sb_color==131):
865 return (156, 48, 99);
866 if(sb_color==132):
867 return (156, 48, 49);
868 if(sb_color==133):
869 return (156, 48, 0);
870 if(sb_color==134):
871 return (156, 0, 255);
872 if(sb_color==135):
873 return (156, 0, 206);
874 if(sb_color==136):
875 return (156, 0, 156);
876 if(sb_color==137):
877 return (156, 0, 99);
878 if(sb_color==138):
879 return (156, 0, 49);
880 if(sb_color==139):
881 return (156, 0, 0);
882 if(sb_color==140):
883 return (99, 251, 255);
884 if(sb_color==141):
885 return (99, 251, 206);
886 if(sb_color==142):
887 return (99, 251, 156);
888 if(sb_color==143):
889 return (99, 251, 99);
890 if(sb_color==144):
891 return (99, 251, 49);
892 if(sb_color==145):
893 return (99, 251, 0);
894 if(sb_color==146):
895 return (99, 203, 255);
896 if(sb_color==147):
897 return (99, 203, 206);
898 if(sb_color==148):
899 return (99, 203, 156);
900 if(sb_color==149):
901 return (99, 203, 99);
902 if(sb_color==150):
903 return (99, 203, 49);
904 if(sb_color==151):
905 return (99, 203, 0);
906 if(sb_color==152):
907 return (99, 154, 255);
908 if(sb_color==153):
909 return (99, 154, 206);
910 if(sb_color==154):
911 return (99, 154, 156);
912 if(sb_color==155):
913 return (99, 154, 99);
914 if(sb_color==156):
915 return (99, 154, 49);
916 if(sb_color==157):
917 return (99, 154, 0);
918 if(sb_color==158):
919 return (99, 97, 255);
920 if(sb_color==159):
921 return (99, 97, 206);
922 if(sb_color==160):
923 return (99, 97, 156);
924 if(sb_color==161):
925 return (99, 97, 99);
926 if(sb_color==162):
927 return (99, 97, 49);
928 if(sb_color==163):
929 return (99, 97, 0);
930 if(sb_color==164):
931 return (99, 48, 255);
932 if(sb_color==165):
933 return (99, 48, 206);
934 if(sb_color==166):
935 return (99, 48, 156);
936 if(sb_color==167):
937 return (99, 48, 99);
938 if(sb_color==168):
939 return (99, 48, 49);
940 if(sb_color==169):
941 return (99, 48, 0);
942 if(sb_color==170):
943 return (99, 0, 255);
944 if(sb_color==171):
945 return (99, 0, 206);
946 if(sb_color==172):
947 return (99, 0, 156);
948 if(sb_color==173):
949 return (99, 0, 99);
950 if(sb_color==174):
951 return (99, 0, 49);
952 if(sb_color==175):
953 return (99, 0, 0);
954 if(sb_color==176):
955 return (49, 251, 255);
956 if(sb_color==177):
957 return (49, 251, 206);
958 if(sb_color==178):
959 return (49, 251, 156);
960 if(sb_color==179):
961 return (49, 251, 99);
962 if(sb_color==180):
963 return (49, 251, 49);
964 if(sb_color==181):
965 return (49, 251, 0);
966 if(sb_color==182):
967 return (49, 203, 255);
968 if(sb_color==183):
969 return (49, 203, 206);
970 if(sb_color==184):
971 return (49, 203, 156);
972 if(sb_color==185):
973 return (49, 203, 99);
974 if(sb_color==186):
975 return (49, 203, 49);
976 if(sb_color==187):
977 return (49, 203, 0);
978 if(sb_color==188):
979 return (49, 154, 255);
980 if(sb_color==189):
981 return (49, 154, 206);
982 if(sb_color==190):
983 return (49, 154, 156);
984 if(sb_color==191):
985 return (49, 154, 99);
986 if(sb_color==192):
987 return (49, 154, 49);
988 if(sb_color==193):
989 return (49, 154, 0);
990 if(sb_color==194):
991 return (49, 97, 255);
992 if(sb_color==195):
993 return (49, 97, 206);
994 if(sb_color==196):
995 return (49, 97, 156);
996 if(sb_color==197):
997 return (49, 97, 99);
998 if(sb_color==198):
999 return (49, 97, 49);
1000 if(sb_color==199):
1001 return (49, 97, 0);
1002 if(sb_color==200):
1003 return (49, 48, 255);
1004 if(sb_color==201):
1005 return (49, 48, 206);
1006 if(sb_color==202):
1007 return (49, 48, 156);
1008 if(sb_color==203):
1009 return (49, 48, 99);
1010 if(sb_color==204):
1011 return (49, 48, 49);
1012 if(sb_color==205):
1013 return (49, 48, 0);
1014 if(sb_color==206):
1015 return (49, 0, 255);
1016 if(sb_color==207):
1017 return (49, 0, 206);
1018 if(sb_color==208):
1019 return (49, 0, 156);
1020 if(sb_color==209):
1021 return (49, 0, 99);
1022 if(sb_color==210):
1023 return (49, 0, 49);
1024 if(sb_color==211):
1025 return (49, 0, 0);
1026 if(sb_color==212):
1027 return (0, 251, 255);
1028 if(sb_color==213):
1029 return (0, 251, 206);
1030 if(sb_color==214):
1031 return (0, 251, 156);
1032 if(sb_color==215):
1033 return (0, 251, 99);
1034 if(sb_color==216):
1035 return (0, 251, 49);
1036 if(sb_color==217):
1037 return (0, 251, 0);
1038 if(sb_color==218):
1039 return (0, 203, 255);
1040 if(sb_color==219):
1041 return (0, 203, 206);
1042 if(sb_color==220):
1043 return (0, 203, 156);
1044 if(sb_color==221):
1045 return (0, 203, 99);
1046 if(sb_color==222):
1047 return (0, 203, 49);
1048 if(sb_color==223):
1049 return (0, 203, 0);
1050 if(sb_color==224):
1051 return (0, 154, 255);
1052 if(sb_color==225):
1053 return (0, 154, 206);
1054 if(sb_color==226):
1055 return (0, 154, 156);
1056 if(sb_color==227):
1057 return (0, 154, 99);
1058 if(sb_color==228):
1059 return (0, 154, 49);
1060 if(sb_color==229):
1061 return (0, 154, 0);
1062 if(sb_color==230):
1063 return (0, 97, 255);
1064 if(sb_color==231):
1065 return (0, 97, 206);
1066 if(sb_color==232):
1067 return (0, 97, 156);
1068 if(sb_color==233):
1069 return (0, 97, 99);
1070 if(sb_color==234):
1071 return (0, 97, 49);
1072 if(sb_color==235):
1073 return (0, 97, 0);
1074 if(sb_color==236):
1075 return (0, 48, 255);
1076 if(sb_color==237):
1077 return (0, 48, 206);
1078 if(sb_color==238):
1079 return (0, 48, 156);
1080 if(sb_color==239):
1081 return (0, 48, 99);
1082 if(sb_color==240):
1083 return (0, 48, 49);
1084 if(sb_color==241):
1085 return (0, 48, 0);
1086 if(sb_color==242):
1087 return (0, 0, 255);
1088 if(sb_color==243):
1089 return (0, 0, 206);
1090 if(sb_color==244):
1091 return (0, 0, 156);
1092 if(sb_color==245):
1093 return (0, 0, 99);
1094 if(sb_color==246):
1095 return (0, 0, 49);
1096 if(sb_color==247):
1097 return (235, 235, 239);
1098 if(sb_color==248):
1099 return (222, 219, 222);
1100 if(sb_color==249):
1101 return (189, 186, 189);
1102 if(sb_color==250):
1103 return (173, 170, 173);
1104 if(sb_color==251):
1105 return (140, 138, 140);
1106 if(sb_color==252):
1107 return (115, 113, 115);
1108 if(sb_color==253):
1109 return (82, 81, 82);
1110 if(sb_color==254):
1111 return (66, 65, 66);
1112 if(sb_color==255):
1113 return (33, 32, 33);
1114 return (0, 0, 0);
1116 def Print_Color(color):
1117 return "("+str(color[0])+", "+str(color[1])+", "+str(color[2])+")";
1119 def Print_C_Color(color):
1120 return str(color[0])+", "+str(color[1])+", "+str(color[2]);
1122 def SmileBasic_Hex_Graphic_Palette(sb_color):
1123 return SmileBasic_Graphic_Palette(int(sb_code, 16));
1125 use_screen = 0;
1128 http://www.petitcomputer.com/manual/manual.pdf
1130 def Parse_SmileBasic(sb_code, screen, usegfx, code_output):
1131 global use_screen;
1132 codedone = False;
1133 drawupdate = False;
1134 if(use_screen==0):
1135 draw_screen = "ds_top_screen";
1136 if(use_screen==1):
1137 draw_screen = "ds_bottom_screen";
1138 if(re.findall("^CODE (.*)", sb_code, re.IGNORECASE) and codedone==False):
1139 gcode_exp = re.findall("^CODE (.*)", sb_code, re.IGNORECASE);
1140 if(code_output=="Python" or code_output=="Py"):
1141 print gcode_exp[0];
1142 if(code_output=="C"):
1143 print " "+gcode_exp[0];
1144 codedone = True;
1145 drawupdate = False;
1146 if(re.findall("^PYCODE (.*)", sb_code, re.IGNORECASE) and codedone==False):
1147 gcode_exp = re.findall("^PYCODE (.*)", sb_code, re.IGNORECASE);
1148 if(code_output=="Python" or code_output=="Py"):
1149 print gcode_exp[0];
1150 codedone = True;
1151 drawupdate = False;
1152 if(re.findall("^CCODE (.*)", sb_code, re.IGNORECASE) and codedone==False):
1153 gcode_exp = re.findall("^CCODE (.*)", sb_code, re.IGNORECASE);
1154 if(code_output=="C"):
1155 print " "+gcode_exp[0];
1156 codedone = True;
1157 drawupdate = False;
1158 if(re.findall("^GOTO \@([A-Z0-9])", sb_code, re.IGNORECASE) and codedone==False):
1159 glabel_exp = re.findall("^GOTO \@([A-Z0-9])", sb_code, re.IGNORECASE);
1160 if(code_output=="C"):
1161 print " goto "+glabel_exp[0]+";";
1162 codedone = True;
1163 drawupdate = False;
1164 if(re.findall("^\@([A-Z0-9])", sb_code, re.IGNORECASE) and codedone==False):
1165 glabel_exp = re.findall("^\@([A-Z0-9])", sb_code, re.IGNORECASE);
1166 if(code_output=="C"):
1167 print " "+glabel_exp[0]+": ";
1168 codedone = True;
1169 drawupdate = False;
1170 if(re.findall("^REM(.*)", sb_code, re.IGNORECASE) and codedone==False):
1171 grem_exp = re.findall("^REM(.*)", sb_code, re.IGNORECASE);
1172 if(code_output=="Python" or code_output=="Py"):
1173 print "#"+grem_exp[0];
1174 if(code_output=="C"):
1175 print " //"+grem_exp[0];
1176 codedone = True;
1177 drawupdate = False;
1178 if(re.findall("^\'(.*)", sb_code, re.IGNORECASE) and codedone==False):
1179 grem_exp = re.findall("^\'(.*)", sb_code, re.IGNORECASE);
1180 if(code_output=="Python" or code_output=="Py"):
1181 print "#"+grem_exp[0];
1182 if(code_output=="C"):
1183 print " //"+grem_exp[0];
1184 codedone = True;
1185 drawupdate = False;
1186 if(re.findall("^GCLS ([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1187 gcls_exp = re.findall("^GCLS\s*([0-9]+)", sb_code, re.IGNORECASE);
1188 if(code_output=="Python" or code_output=="Py"):
1189 print draw_screen+".fill("+Print_Color(SmileBasic_Graphic_Palette(int(gcls_exp[0])))+");";
1190 if(code_output=="C"):
1191 print " SDL_FillRect("+draw_screen+", NULL, SDL_MapRGB("+draw_screen+"->format, "+Print_C_Color(SmileBasic_Graphic_Palette(int(gcls_exp[0])))+"));";
1192 #print " boxRGBA("+draw_screen+", 0, 0, 255, 383, "+Print_C_Color(SmileBasic_Graphic_Palette(int(gcls_exp[0])))+", 255);";
1193 codedone = True;
1194 drawupdate = True;
1195 if(re.findall("^GSPOIT\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*\)", sb_code, re.IGNORECASE) and codedone==False):
1196 gspoit_exp = re.findall("^GSPOIT\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*\)", sb_code, re.IGNORECASE);
1197 gspoit_exp = gspoit_exp[0];
1198 if(code_output=="Python" or code_output=="Py"):
1199 print "tuple("+draw_screen+".get_at(("+str(int(gspoit_exp[0]))+", "+str(int(gspoit_exp[0]))+")));";
1200 codedone = True;
1201 drawupdate = True;
1202 if(re.findall("^GPAGE ([0-1])", sb_code, re.IGNORECASE) and codedone==False):
1203 gpage_exp = re.findall("^GPAGE ([0-1])", sb_code, re.IGNORECASE);
1204 if(int(gpage_exp[0])==0):
1205 use_screen = 0;
1206 if(int(gpage_exp[0])==1):
1207 use_screen = 1;
1208 codedone = True;
1209 drawupdate = False;
1210 if(re.findall("^GCOLOR ([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1211 gcolor_exp = re.findall("^GCOLOR ([0-9]+)", sb_code, re.IGNORECASE);
1212 if(code_output=="Python" or code_output=="Py"):
1213 print "ptcolor = gcolor_exp[0];";
1214 codedone = True;
1215 drawupdate = False;
1216 if(re.findall("^GPAINT ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1217 gpaint_exp = re.findall("^GPAINT ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1218 gpaint_exp = gpaint_exp[0];
1219 if(code_output=="Python" or code_output=="Py"):
1220 print draw_screen+".fill("+Print_Color(SmileBasic_Graphic_Palette(int(gpaint_exp[0])))+");";
1221 if(code_output=="C"):
1222 print " SDL_FillRect("+draw_screen+", NULL, SDL_MapRGB("+draw_screen+"->format, "+Print_C_Color(SmileBasic_Graphic_Palette(int(gpaint_exp[0])))+"));";
1223 #print " boxRGBA("+draw_screen+", 0, 0, 255, 383, "+Print_C_Color(SmileBasic_Graphic_Palette(int(gpaint_exp[0])))+", 255);";
1224 codedone = True;
1225 drawupdate = True;
1226 if(re.findall("^GPAINT ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1227 gpaint_exp = re.findall("^GPAINT ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1228 gpaint_exp = gpaint_exp[0];
1229 if(code_output=="Python" or code_output=="Py"):
1230 print draw_screen+".fill("+Print_Color(SmileBasic_Graphic_Palette(int(gpaint_exp[2])))+");";
1231 if(code_output=="C"):
1232 print " SDL_FillRect("+draw_screen+", NULL, SDL_MapRGB("+draw_screen+"->format, "+Print_C_Color(SmileBasic_Graphic_Palette(int(gpaint_exp[2])))+"));";
1233 #print " boxRGBA("+draw_screen+", 0, 0, 255, 383, "+Print_C_Color(SmileBasic_Graphic_Palette(int(gpaint_exp[2])))+", 255);";
1234 codedone = True;
1235 drawupdate = True;
1236 if(re.findall("^GPAINT ([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1237 gpaint_exp = re.findall("^GPAINT ([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1238 gpaint_exp = gpaint_exp[0];
1239 if(code_output=="Python" or code_output=="Py"):
1240 print draw_screen+".fill("+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1241 if(code_output=="C"):
1242 print " SDL_FillRect("+draw_screen+", NULL, SDL_MapRGB("+draw_screen+"->format, "+Print_C_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+"));";
1243 #print " boxRGBA("+draw_screen+", 0, 0, 255, 383, "+Print_C_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", 255);";
1244 codedone = True;
1245 drawupdate = True;
1246 if(re.findall("^GSPOT ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1247 gspot_exp = re.findall("^GSPOT ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1248 gspot_exp = gspot_exp[0];
1249 if(usegfx==False):
1250 if(code_output=="Python" or code_output=="Py"):
1251 print "pygame.draw.line("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(gcls_exp[2])))+", ("+str(int(gspot_exp[0]))+", "+str(int(gspot_exp[0]))+"), ("+str(int(gspot_exp[1]))+", "+str(int(gspot_exp[1]))+"));";
1252 if(usegfx==True):
1253 if(code_output=="Python" or code_output=="Py"):
1254 print "pygame.gfxdraw.pixel("+draw_screen+", "+str(int(gspot_exp[0]))+", "+str(int(gspot_exp[1]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gcls_exp[2])))+");";
1255 if(code_output=="C"):
1256 print " pixelRGBA("+draw_screen+", "+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(gline_exp[4])))+", 255);";
1257 codedone = True;
1258 drawupdate = True;
1259 if(re.findall("^GSPOT ([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1260 gspot_exp = re.findall("^GSPOT ([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1261 gspot_exp = gspot_exp[0];
1262 if(usegfx==False):
1263 if(code_output=="Python" or code_output=="Py"):
1264 print "pygame.draw.line("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", ("+str(int(gspot_exp[0]))+", "+str(int(gspot_exp[0]))+"), ("+str(int(gspot_exp[1]))+", "+str(int(gspot_exp[1]))+"));";
1265 if(usegfx==True):
1266 if(code_output=="Python" or code_output=="Py"):
1267 print "pygame.gfxdraw.pixel("+draw_screen+", "+str(int(gspot_exp[0]))+", "+str(int(gspot_exp[1]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1268 if(code_output=="C"):
1269 print " pixelRGBA("+draw_screen+", "+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", 255);";
1270 codedone = True;
1271 drawupdate = True;
1272 if(re.findall("^GLINE ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1273 gline_exp = re.findall("^GLINE ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1274 gline_exp = gline_exp[0];
1275 if(usegfx==False):
1276 if(code_output=="Python" or code_output=="Py"):
1277 print "pygame.draw.line("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(gline_exp[4])))+", ("+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+"), ("+str(int(gline_exp[2]))+", "+str(int(gline_exp[3]))+"));";
1278 if(usegfx==True):
1279 if(code_output=="Python" or code_output=="Py"):
1280 print "pygame.gfxdraw.line("+draw_screen+", "+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+", "+str(int(gline_exp[2]))+", "+str(int(gline_exp[3]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gline_exp[4])))+");";
1281 if(code_output=="C"):
1282 print " lineRGBA("+draw_screen+", "+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+", "+str(int(gline_exp[2]))+", "+str(int(gline_exp[3]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(gline_exp[4])))+", 255);";
1283 codedone = True;
1284 drawupdate = True;
1285 if(re.findall("^GLINE ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1286 gline_exp = re.findall("^GLINE ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1287 gline_exp = gline_exp[0];
1288 if(usegfx==False):
1289 if(code_output=="Python" or code_output=="Py"):
1290 print "pygame.draw.line("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", ("+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+"), ("+str(int(gline_exp[2]))+", "+str(int(gline_exp[3]))+"));";
1291 if(usegfx==True):
1292 if(code_output=="Python" or code_output=="Py"):
1293 print "pygame.gfxdraw.line("+draw_screen+", "+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+", "+str(int(gline_exp[2]))+", "+str(int(gline_exp[3]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1294 if(code_output=="C"):
1295 print " lineRGBA("+draw_screen+", "+str(int(gline_exp[0]))+", "+str(int(gline_exp[1]))+", "+str(int(gline_exp[2]))+", "+str(int(gline_exp[3]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", 255);";
1296 codedone = True;
1297 drawupdate = True;
1298 if(re.findall("^GBOX ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1299 gbox_exp = re.findall("^GBOX ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1300 gbox_exp = gbox_exp[0];
1301 if(usegfx==False):
1302 if(code_output=="Python" or code_output=="Py"):
1303 print "pygame.draw.lines("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(gbox_exp[4])))+", False, [("+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+"), ("+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[1]))+"), ("+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[3]))+"), ("+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[3]))+"), ("+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+")], True);";
1304 if(usegfx==True):
1305 if(code_output=="Python" or code_output=="Py"):
1306 print "pygame.gfxdraw.hline("+draw_screen+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[1]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gbox_exp[4])))+");";
1307 print "pygame.gfxdraw.vline("+draw_screen+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+", "+str(int(gbox_exp[3]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gbox_exp[4])))+");";
1308 print "pygame.gfxdraw.hline("+draw_screen+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[3]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gbox_exp[4])))+");";
1309 print "pygame.gfxdraw.vline("+draw_screen+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[3]))+", "+str(int(gbox_exp[1]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gbox_exp[4])))+");";
1310 if(code_output=="C"):
1311 print " rectangleRGBA("+draw_screen+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[3]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(gbox_exp[4])))+", 255);";
1312 codedone = True;
1313 drawupdate = True;
1314 if(re.findall("^GBOX ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1315 gbox_exp = re.findall("^GBOX ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1316 gbox_exp = gbox_exp[0];
1317 if(usegfx==False):
1318 if(code_output=="Python" or code_output=="Py"):
1319 print "pygame.draw.lines("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", False, [("+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+"), ("+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[1]))+"), ("+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[3]))+"), ("+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[3]))+"), ("+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+")], True);";
1320 if(usegfx==True):
1321 if(code_output=="Python" or code_output=="Py"):
1322 print "pygame.gfxdraw.hline("+draw_screen+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[1]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1323 print "pygame.gfxdraw.vline("+draw_screen+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+", "+str(int(gbox_exp[3]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1324 print "pygame.gfxdraw.hline("+draw_screen+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[3]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1325 print "pygame.gfxdraw.vline("+draw_screen+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[3]))+", "+str(int(gbox_exp[1]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1326 if(code_output=="C"):
1327 print " rectangleRGBA("+draw_screen+", "+str(int(gbox_exp[0]))+", "+str(int(gbox_exp[1]))+", "+str(int(gbox_exp[2]))+", "+str(int(gbox_exp[3]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", 255);";
1328 codedone = True;
1329 drawupdate = True;
1330 if(re.findall("^GFILL ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1331 gfill_exp = re.findall("^GFILL ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1332 gfill_exp = gfill_exp[0];
1334 https://github.com/klange/Python-Asteroids-Clone/blob/master/pscreen.py
1336 if(code_output=="Python" or code_output=="Py"):
1337 if int(gfill_exp[0]) < int(gfill_exp[2]):
1338 x_arg=int(gfill_exp[0])
1339 else:
1340 x_arg=int(gfill_exp[2])
1341 if int(gfill_exp[1]) < int(gfill_exp[3]):
1342 y_arg=int(gfill_exp[1])
1343 else:
1344 y_arg=int(gfill_exp[3])
1345 w_arg=abs(int(gfill_exp[2]) - int(gfill_exp[0])) + 1;
1346 h_arg=abs(int(gfill_exp[3]) - int(gfill_exp[1])) + 1;
1347 if(usegfx==False):
1348 if(code_output=="Python" or code_output=="Py"):
1349 print "pygame.draw.rect("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(gfill_exp[4])))+", ("+str(int(x_arg))+", "+str(int(y_arg))+", "+str(int(w_arg))+", "+str(int(h_arg))+"));";
1350 if(usegfx==True):
1351 if(code_output=="Python" or code_output=="Py"):
1352 print "pygame.gfxdraw.box("+draw_screen+", ("+str(int(x_arg))+", "+str(int(y_arg))+", "+str(int(w_arg))+", "+str(int(h_arg))+"), "+Print_Color(SmileBasic_Graphic_Palette(int(gfill_exp[4])))+");";
1353 if(code_output=="C"):
1354 print " boxRGBA("+draw_screen+", "+str(int(gfill_exp[0]))+", "+str(int(gfill_exp[1]))+", "+str(int(gfill_exp[2]))+", "+str(int(gfill_exp[3]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(gfill_exp[4])))+", 255);";
1355 codedone = True;
1356 drawupdate = True;
1357 if(re.findall("^GFILL ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1358 gfill_exp = re.findall("^GFILL ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1359 gfill_exp = gfill_exp[0];
1361 https://github.com/klange/Python-Asteroids-Clone/blob/master/pscreen.py
1363 if(code_output=="Python" or code_output=="Py"):
1364 if int(gfill_exp[0]) < int(gfill_exp[2]):
1365 x_arg=int(gfill_exp[0])
1366 else:
1367 x_arg=int(gfill_exp[2])
1368 if int(gfill_exp[1]) < int(gfill_exp[3]):
1369 y_arg=int(gfill_exp[1])
1370 else:
1371 y_arg=int(gfill_exp[3])
1372 w_arg=abs(int(gfill_exp[2]) - int(gfill_exp[0])) + 1;
1373 h_arg=abs(int(gfill_exp[3]) - int(gfill_exp[1])) + 1;
1374 if(usegfx==False):
1375 if(code_output=="Python" or code_output=="Py"):
1376 print "pygame.draw.rect("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", ("+str(int(x_arg))+", "+str(int(y_arg))+", "+str(int(w_arg))+", "+str(int(h_arg))+"));";
1377 if(usegfx==True):
1378 if(code_output=="Python" or code_output=="Py"):
1379 print "pygame.gfxdraw.box("+draw_screen+", ("+str(int(x_arg))+", "+str(int(y_arg))+", "+str(int(w_arg))+", "+str(int(h_arg))+"), "+Print_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+");";
1380 if(code_output=="C"):
1381 print " boxRGBA("+draw_screen+", "+str(int(gfill_exp[0]))+", "+str(int(gfill_exp[1]))+", "+str(int(gfill_exp[2]))+", "+str(int(gfill_exp[3]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(ptcolor)))+", 255);";
1382 codedone = True;
1383 drawupdate = True;
1384 if(re.findall("^GCIRCLE ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE) and codedone==False):
1385 gcircle_exp = re.findall("^GCIRCLE ([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)", sb_code, re.IGNORECASE);
1386 gcircle_exp = gcircle_exp[0];
1387 if(usegfx==False):
1388 if(code_output=="Python" or code_output=="Py"):
1389 print "drawCircleArc("+draw_screen+", "+Print_Color(SmileBasic_Graphic_Palette(int(gcircle_exp[3])))+", ("+str(int(gcircle_exp[0]))+", "+str(int(gcircle_exp[1]))+"), "+str(int(gcircle_exp[2]))+", "+str(int(gcircle_exp[4]))+", "+str(int(gcircle_exp[5]))+", 1);";
1390 if(usegfx==True):
1391 if(code_output=="Python" or code_output=="Py"):
1392 print "pygame.gfxdraw.arc("+draw_screen+", ("+str(int(gcircle_exp[0]))+", "+str(int(gcircle_exp[1]))+"), "+str(int(gcircle_exp[2]))+", "+str(int(gcircle_exp[4]))+", "+str(int(gcircle_exp[5]))+", "+Print_Color(SmileBasic_Graphic_Palette(int(gcircle_exp[3])))+");";
1393 if(code_output=="C"):
1394 print " arcRGBA("+draw_screen+", "+str(int(gcircle_exp[0]))+", "+str(int(gcircle_exp[1]))+", "+str(int(gcircle_exp[2]))+", "+str(int(gcircle_exp[4]))+", "+str(int(gcircle_exp[5]))+", "+Print_C_Color(SmileBasic_Graphic_Palette(int(gline_exp[4])))+", 255);";
1395 codedone = True;
1396 drawupdate = True;
1397 if(re.findall("^REBOOT", sb_code, re.IGNORECASE) and codedone==False):
1398 greboot_exp = re.findall("^REBOOT", sb_code, re.IGNORECASE);
1399 greboot_exp = greboot_exp[0];
1400 if(code_output=="Python" or code_output=="Py"):
1401 print "done = True;\n";
1402 codedone = True;
1403 drawupdate = False;
1404 if(drawupdate==True):
1405 if(use_screen==0):
1406 if(code_output=="Python" or code_output=="Py"):
1407 print screen+".blit("+draw_screen+", (0, 0));";
1408 if(code_output=="C"):
1409 print " SDL_Flip("+draw_screen+");";
1410 print " SDL_BlitSurface("+draw_screen+", NULL, "+screen+", &ds_top_screen_rect);";
1411 if(use_screen==1):
1412 if(code_output=="Python" or code_output=="Py"):
1413 print screen+".blit("+draw_screen+", (0, 192));";
1414 if(code_output=="C"):
1415 print " SDL_Flip("+draw_screen+");";
1416 print " SDL_BlitSurface("+draw_screen+", NULL, "+screen+", &ds_bottom_screen_rect);";
1417 if(code_output=="Python" or code_output=="Py"):
1418 print "pygame.display.update();\n";
1419 if(code_output=="C"):
1420 print " SDL_Flip("+screen+");\n";
1421 return True;
1423 sys.argv[1] = sys.argv[1].replace("\\", "/");
1424 SB_File=open(sys.argv[1], "rbU");
1425 SB_FileType = SB_File.read(2);
1426 if(SB_FileType==binascii.unhexlify("1F8B")):
1427 SB_File.close();
1428 SB_File = gzip.open(sys.argv[1], "rb");
1429 if(SB_FileType!=binascii.unhexlify("1F8B")):
1430 SB_File.seek(0);
1431 SB_FileType = SB_File.read(3);
1432 if(SB_FileType=="BZh"):
1433 SB_File.close();
1434 SB_File = bz2.BZ2File(sys.argv[1], "rb");
1435 SB_File.seek(0);
1436 SB_FileType = SB_File.read(4);
1437 if(SB_FileType!="PX01"):
1438 if(code_output=="Python" or code_output=="Py"):
1439 print "pygame.display.set_caption(\"Petit Computer - "+os.path.splitext(os.path.basename(sys.argv[1]))[0]+"\");\n";
1440 if(code_output=="C"):
1441 print " SDL_WM_SetCaption(\"Petit Computer - "+os.path.splitext(os.path.basename(sys.argv[1]))[0]+"\", \"Petit Computer - "+os.path.splitext(os.path.basename(sys.argv[1]))[0]+"\");\n";
1442 SB_File.seek(0);
1443 if(SB_FileType=="PX01"):
1444 SB_File.seek(12);
1445 SB_FileTitle = SB_File.read(8).strip();
1446 if(code_output=="Python" or code_output=="Py"):
1447 print "pygame.display.set_caption(\"Petit Computer - "+SB_FileTitle+"\";\n";
1448 if(code_output=="C"):
1449 print " SDL_WM_SetCaption(\"Petit Computer - "+SB_FileTitle+"\", \"Petit Computer - "+SB_FileTitle+"\");\n";
1450 SB_File.seek(60);
1451 SB_Exp=SB_File.readlines();
1452 SB_File.close();
1453 SB_i=0;
1454 SB_Num=len(SB_Exp);
1455 while(SB_i<SB_Num):
1456 if(SB_Exp[SB_i]!=" "):
1457 Parse_SmileBasic(SB_Exp[SB_i].strip(), "ds_screen", enable_gfxdraw, code_output);
1458 SB_i = SB_i + 1;
1459 if(code_output=="Python" or code_output=="Py"):
1460 print "tend = time.clock();";
1461 print "print \"execution time: %.2gs\" % (tend-tstart);";
1462 print "while not done:";
1463 print " for event in pygame.event.get():";
1464 print " if (event.type == pygame.KEYDOWN):";
1465 print " if (event.key == pygame.K_ESCAPE):";
1466 print " done = True;";
1467 print " if (event.type == pygame.QUIT):";
1468 print " done = True;\n";
1469 print "pygame.display.quit();";
1470 print "pygame.quit();";
1471 print "exit();\n";
1473 if(code_output=="C"):
1474 print " while(done==false) {";
1475 print " if (SDL_PollEvent(&event)) {";
1476 print " switch (event.type) {";
1477 print " case SDL_QUIT:";
1478 print " done = true;";
1479 print " break;";
1480 print " case SDL_KEYDOWN:";
1481 print " switch (event.key.keysym.sym) {";
1482 print " case SDLK_ESCAPE:";
1483 print " done = true;";
1484 print " break;";
1485 print " }";
1486 print " break;";
1487 print " }";
1488 print " }";
1489 print " }";
1490 print " SDL_Quit();";
1491 print " return 0;\n}";
1493 exit();