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";
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{";
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
):
91 return (255, 89, 198);
95 return (123, 56, 255);
101 return (255, 162, 0);
103 return (255, 203, 165);
109 return (255, 227, 0);
111 return (189, 186, 189);
115 return (255, 251, 255);
121 return (140, 48, 41);
123 return (156, 89, 132);
125 return (33, 56, 132);
127 return (99, 73, 148);
129 return (41, 113, 140);
133 return (140, 97, 41);
135 return (165, 146, 132);
139 return (33, 130, 49);
141 return (140, 121, 41);
143 return (132, 130, 132);
145 return (255, 251, 255);
153 return (66, 97, 255);
155 return (181, 211, 255);
159 return (255, 65, 16);
161 return (255, 195, 189);
163 return (115, 73, 24);
165 return (206, 178, 123);
167 return (255, 227, 181);
171 return (148, 146, 148);
173 return (231, 227, 231);
175 return (255, 251, 255);
179 return (189, 186, 189);
187 return (255, 97, 82);
191 return (123, 97, 49);
193 return (198, 162, 99);
195 return (115, 105, 0);
197 return (189, 178, 0);
199 return (255, 251, 0);
201 return (90, 56, 255);
203 return (148, 130, 255);
205 return (222, 211, 255);
207 return (255, 251, 255);
211 return (255, 227, 0);
217 return (255, 40, 24);
219 return (255, 146, 107);
223 return (0, 178, 255);
225 return (82, 251, 255);
229 return (198, 154, 90);
231 return (255, 203, 123);
237 return (156, 251, 156);
239 return (255, 251, 255);
249 return (107, 130, 255);
251 return (181, 211, 255);
259 return (140, 97, 49);
261 return (189, 170, 82);
263 return (239, 227, 156);
269 return (255, 130, 74);
271 return (255, 251, 255);
281 return (255, 251, 0);
283 return (255, 251, 156);
287 return (255, 0, 132);
289 return (255, 178, 214);
291 return (148, 97, 24);
293 return (214, 195, 123);
295 return (255, 251, 239);
299 return (99, 251, 74);
301 return (206, 251, 189);
303 return (255, 251, 255);
307 return (255, 203, 165);
313 return (255, 0, 255);
315 return (255, 113, 255);
319 return (189, 178, 16);
321 return (255, 251, 0);
323 return (181, 97, 24);
325 return (247, 195, 123);
327 return (255, 251, 239);
329 return (66, 65, 255);
331 return (132, 130, 255);
333 return (222, 219, 255);
335 return (255, 251, 255);
339 return (255, 162, 0);
347 return (123, 65, 24);
349 return (148, 89, 41);
351 return (181, 121, 66);
353 return (206, 170, 115);
357 return (16, 162, 16);
359 return (74, 211, 90);
361 return (148, 138, 231);
363 return (189, 178, 239);
365 return (222, 211, 255);
367 return (255, 251, 255);
371 return (148, 89, 41);
381 return (132, 73, 33);
383 return (148, 97, 41);
385 return (165, 121, 74);
391 return (33, 154, 66);
393 return (99, 65, 181);
395 return (165, 138, 214);
397 return (198, 178, 247);
399 return (181, 219, 255);
403 return (0, 186, 255);
411 return (90, 121, 90);
413 return (132, 170, 132);
415 return (181, 211, 181);
417 return (231, 251, 231);
421 return (173, 146, 49);
423 return (214, 203, 148);
425 return (132, 105, 0);
427 return (255, 251, 0);
429 return (255, 251, 214);
431 return (255, 251, 255);
435 return (123, 56, 255);
443 return (123, 121, 132);
445 return (156, 162, 173);
447 return (181, 186, 198);
449 return (206, 211, 231);
451 return (222, 121, 0);
453 return (255, 195, 16);
455 return (255, 251, 90);
459 return (255, 97, 57);
461 return (255, 154, 156);
463 return (255, 251, 255);
473 return (16, 48, 148);
475 return (57, 81, 165);
477 return (115, 138, 198);
479 return (173, 186, 231);
481 return (222, 227, 255);
485 return (99, 113, 156);
487 return (181, 203, 255);
493 return (255, 211, 173);
495 return (255, 251, 255);
499 return (255, 89, 198);
505 return (156, 56, 24);
507 return (173, 81, 49);
509 return (193, 113, 99);
511 return (239, 178, 165);
513 return (255, 211, 206);
517 return (156, 113, 99);
519 return (255, 203, 181);
523 return (0, 130, 255);
525 return (173, 211, 255);
527 return (255, 251, 255);
539 return (115, 113, 49);
541 return (156, 154, 74);
543 return (198, 195, 107);
545 return (247, 243, 140);
549 return (165, 113, 0);
551 return (231, 211, 132);
553 return (132, 8, 148);
555 return (255, 32, 173);
557 return (255, 170, 255);
559 return (255, 251, 255);
567 return (123, 121, 123);
569 return (132, 130, 132);
571 return (148, 146, 148);
573 return (156, 154, 156);
575 return (165, 162, 165);
577 return (173, 170, 173);
579 return (189, 186, 189);
581 return (198, 195, 198);
583 return (206, 203, 206);
585 return (214, 211, 214);
587 return (231, 227, 231);
591 return (181, 178, 181);
595 return (239, 235, 239);
598 def SmileBasic_Hex_Console_Palette(sb_color
):
599 return SmileBasic_Console_Palette(int(sb_code
, 16));
601 def SmileBasic_Graphic_Palette(sb_color
):
609 return (255, 89, 198);
613 return (123, 56, 255);
615 return (0, 186, 255);
617 return (148, 89, 41);
619 return (255, 162, 0);
621 return (255, 203, 165);
627 return (255, 227, 0);
629 return (189, 186, 189);
633 return (255, 251, 255);
639 return (140, 48, 41);
641 return (156, 89, 132);
643 return (33, 56, 132);
645 return (99, 73, 148);
647 return (41, 113, 140);
651 return (140, 97, 41);
653 return (165, 146, 132);
657 return (33, 130, 49);
659 return (140, 121, 41);
661 return (132, 130, 132);
663 return (255, 251, 255);
667 return (255, 251, 255);
669 return (255, 251, 206);
671 return (255, 251, 156);
673 return (255, 251, 99);
675 return (255, 251, 49);
677 return (255, 251, 0);
679 return (255, 203, 255);
681 return (255, 203, 206);
683 return (255, 203, 156);
685 return (255, 203, 99);
687 return (255, 203, 49);
689 return (255, 203, 0);
691 return (255, 154, 255);
693 return (255, 154, 206);
695 return (255, 154, 156);
697 return (255, 154, 99);
699 return (255, 154, 49);
701 return (255, 154, 0);
703 return (255, 97, 255);
705 return (255, 97, 206);
707 return (255, 97, 156);
709 return (255, 97, 99);
711 return (255, 97, 49);
715 return (255, 48, 255);
717 return (255, 48, 206);
719 return (255, 48, 156);
721 return (255, 48, 99);
723 return (255, 48, 49);
727 return (255, 0, 255);
729 return (255, 0, 206);
731 return (255, 0, 156);
739 return (206, 251, 255);
741 return (206, 251, 206);
743 return (206, 251, 156);
745 return (206, 251, 99);
747 return (206, 251, 49);
749 return (206, 251, 0);
751 return (206, 203, 255);
753 return (206, 203, 206);
755 return (206, 203, 156);
757 return (206, 203, 99);
759 return (206, 203, 49);
761 return (206, 203, 0);
763 return (206, 154, 255);
765 return (206, 154, 206);
767 return (206, 154, 156);
769 return (206, 154, 99);
771 return (206, 154, 49);
773 return (206, 154, 0);
775 return (206, 97, 255);
777 return (206, 97, 206);
779 return (206, 97, 156);
781 return (206, 97, 99);
783 return (206, 97, 49);
787 return (206, 48, 255);
789 return (206, 48, 206);
791 return (206, 48, 156);
793 return (206, 48, 99);
795 return (206, 48, 49);
799 return (206, 0, 255);
801 return (206, 0, 206);
803 return (206, 0, 156);
811 return (156, 251, 255);
813 return (156, 251, 206);
815 return (156, 251, 156);
817 return (156, 251, 99);
819 return (156, 251, 49);
821 return (156, 251, 0);
823 return (156, 203, 255);
825 return (156, 203, 206);
827 return (156, 203, 156);
829 return (156, 203, 99);
831 return (156, 203, 49);
833 return (156, 203, 0);
835 return (156, 154, 255);
837 return (156, 154, 206);
839 return (156, 154, 156);
841 return (156, 154, 99);
843 return (156, 154, 49);
845 return (156, 154, 0);
847 return (156, 97, 255);
849 return (156, 97, 206);
851 return (156, 97, 156);
853 return (156, 97, 99);
855 return (156, 97, 49);
859 return (156, 48, 255);
861 return (156, 48, 206);
863 return (156, 48, 156);
865 return (156, 48, 99);
867 return (156, 48, 49);
871 return (156, 0, 255);
873 return (156, 0, 206);
875 return (156, 0, 156);
883 return (99, 251, 255);
885 return (99, 251, 206);
887 return (99, 251, 156);
889 return (99, 251, 99);
891 return (99, 251, 49);
895 return (99, 203, 255);
897 return (99, 203, 206);
899 return (99, 203, 156);
901 return (99, 203, 99);
903 return (99, 203, 49);
907 return (99, 154, 255);
909 return (99, 154, 206);
911 return (99, 154, 156);
913 return (99, 154, 99);
915 return (99, 154, 49);
919 return (99, 97, 255);
921 return (99, 97, 206);
923 return (99, 97, 156);
931 return (99, 48, 255);
933 return (99, 48, 206);
935 return (99, 48, 156);
955 return (49, 251, 255);
957 return (49, 251, 206);
959 return (49, 251, 156);
961 return (49, 251, 99);
963 return (49, 251, 49);
967 return (49, 203, 255);
969 return (49, 203, 206);
971 return (49, 203, 156);
973 return (49, 203, 99);
975 return (49, 203, 49);
979 return (49, 154, 255);
981 return (49, 154, 206);
983 return (49, 154, 156);
985 return (49, 154, 99);
987 return (49, 154, 49);
991 return (49, 97, 255);
993 return (49, 97, 206);
995 return (49, 97, 156);
1003 return (49, 48, 255);
1005 return (49, 48, 206);
1007 return (49, 48, 156);
1009 return (49, 48, 99);
1011 return (49, 48, 49);
1015 return (49, 0, 255);
1017 return (49, 0, 206);
1019 return (49, 0, 156);
1027 return (0, 251, 255);
1029 return (0, 251, 206);
1031 return (0, 251, 156);
1033 return (0, 251, 99);
1035 return (0, 251, 49);
1039 return (0, 203, 255);
1041 return (0, 203, 206);
1043 return (0, 203, 156);
1045 return (0, 203, 99);
1047 return (0, 203, 49);
1051 return (0, 154, 255);
1053 return (0, 154, 206);
1055 return (0, 154, 156);
1057 return (0, 154, 99);
1059 return (0, 154, 49);
1063 return (0, 97, 255);
1065 return (0, 97, 206);
1067 return (0, 97, 156);
1075 return (0, 48, 255);
1077 return (0, 48, 206);
1079 return (0, 48, 156);
1097 return (235, 235, 239);
1099 return (222, 219, 222);
1101 return (189, 186, 189);
1103 return (173, 170, 173);
1105 return (140, 138, 140);
1107 return (115, 113, 115);
1109 return (82, 81, 82);
1111 return (66, 65, 66);
1113 return (33, 32, 33);
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));
1128 http://www.petitcomputer.com/manual/manual.pdf
1130 def Parse_SmileBasic(sb_code
, screen
, usegfx
, code_output
):
1135 draw_screen
= "ds_top_screen";
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"):
1142 if(code_output
=="C"):
1143 print " "+gcode_exp
[0];
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"):
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];
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]+";";
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]+": ";
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];
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];
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);";
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]))+")));";
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):
1206 if(int(gpage_exp
[0])==1):
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];";
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);";
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);";
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);";
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];
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]))+"));";
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);";
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];
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]))+"));";
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);";
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];
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]))+"));";
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);";
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];
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]))+"));";
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);";
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];
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);";
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);";
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];
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);";
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);";
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])
1340 x_arg
=int(gfill_exp
[2])
1341 if int(gfill_exp
[1]) < int(gfill_exp
[3]):
1342 y_arg
=int(gfill_exp
[1])
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;
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
))+"));";
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);";
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])
1367 x_arg
=int(gfill_exp
[2])
1368 if int(gfill_exp
[1]) < int(gfill_exp
[3]):
1369 y_arg
=int(gfill_exp
[1])
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;
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
))+"));";
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);";
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];
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);";
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);";
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";
1404 if(drawupdate
==True):
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);";
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";
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")):
1428 SB_File
= gzip
.open(sys
.argv
[1], "rb");
1429 if(SB_FileType
!=binascii
.unhexlify("1F8B")):
1431 SB_FileType
= SB_File
.read(3);
1432 if(SB_FileType
=="BZh"):
1434 SB_File
= bz2
.BZ2File(sys
.argv
[1], "rb");
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";
1443 if(SB_FileType
=="PX01"):
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";
1451 SB_Exp
=SB_File
.readlines();
1456 if(SB_Exp
[SB_i
]!=" "):
1457 Parse_SmileBasic(SB_Exp
[SB_i
].strip(), "ds_screen", enable_gfxdraw
, code_output
);
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();";
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;";
1480 print " case SDL_KEYDOWN:";
1481 print " switch (event.key.keysym.sym) {";
1482 print " case SDLK_ESCAPE:";
1483 print " done = true;";
1490 print " SDL_Quit();";
1491 print " return 0;\n}";