Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 9, 2014 1:05:52 GMT 1
|
|
|
Post by vovchik on Feb 9, 2014 2:16:28 GMT 1
Dear John,
Here is alos an updated color palette demo - with some annotation to make sense of the numbers.
With kind regards, vovchik
'BBC COLOURS Demo - bits from Alex
' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL PRAGMA LDFLAGS m SDL bbc
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' EXTERNAL FUNCTIONS ' ***********************
PROTO init_screen ALIAS SCREEN PROTO emulate_modefn ALIAS GETMODE PROTO emulate_vdufn ALIAS GETVDU PROTO emulate_mode ALIAS MODE PROTO emulate_origin ALIAS ORIGIN PROTO emulate_off ALIAS OFF PROTO emulate_gcol ALIAS GCOLOR PROTO emulate_move ALIAS MOVE PROTO emulate_vdustr ALIAS GPRINT PROTO end_screen ALIAS ENDSCREEN PROTO emulate_vdu ALIAS VDU PROTO emulate_drawrect ALIAS RECTANGLE PROTO SDL_WM_SetCaption ALIAS TITLE PROTO SDL_PollEvent ALIAS BBC_GETKEY PROTO SDL_GL_SetAttribute ALIAS SDL_ATTRIBUTE PROTO printf ALIAS PRINTF 'emulate_drawrect(int32, int32, int32, int32, boolean) RECTANGLE
' *********************** ' END EXTERNAL FUNCTIONS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB KEY_WAIT() ' ------------------ LOCAL event TYPE SDL_Event WHILE TRUE DO WHILE BBC_GETKEY(&event) DO SELECT event.type CASE SDL_KEYUP ' If return is pressed, quit ' see http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlkey.html IF event.key.keysym.sym = SDLK_RETURN THEN OFF() ENDSCREEN() END 0 END IF IF event.key.keysym.sym = SDLK_RIGHT THEN PRINT "RIGHT" END IF IF event.key.keysym.sym = SDLK_LEFT THEN PRINT "LEFT" END IF IF event.key.keysym.sym = SDLK_UP THEN PRINT "UP" END IF IF event.key.keysym.sym = SDLK_DOWN THEN PRINT "DOWN" END IF CASE SDL_MOUSEMOTION PRINTF("Current mouse position is : %d,%d \n", event.motion.x,event.motion.y ) CASE SDL_MOUSEBUTTONDOWN ' If left mouse button is clicked, quit IF event.button.button == SDL_BUTTON_LEFT THEN PRINT "LEFT BUTTON" OFF() ENDSCREEN() END 0 END IF IF event.button.button == SDL_BUTTON_RIGHT THEN PRINT "RIGHT BUTTON" END IF IF event.button.button == SDL_BUTTON_MIDDLE THEN PRINT "MIDDLE BUTTON" END IF CASE SDL_QUIT END 0 END SELECT WEND SLEEP 200 WEND END SUB
' ------------------ SUB ANTIALIAS() ' ------------------ SDL_ATTRIBUTE(SDL_GL_MULTISAMPLEBUFFERS, 1) SDL_ATTRIBUTE(SDL_GL_MULTISAMPLESAMPLES, 4) END SUB
' ------------------ SUB MK_DRAWING() ' ------------------ ' initializatopm LOCAL x, y TYPE int LOCAL T1$, T2$, T3$ TYPE STRING T1$ = "BaCon BBC COLOURS - MODE 32" T2$ = "BBC Colours - Mode 32" T3$ = "Left click to quit" LOCAL rotation TYPE double ' screen prep SCREEN() TITLE(T1$, 0) ANTIALIAS() MODE(32) VDU(5) OFF() ' terminal output PRINT "MODE: ", GETMODE() PRINT "DEPTH: ", GETVDU(3) PRINT "Width: ", GETVDU(11) + 1, " Height: ", GETVDU(12) + 1 PRINT "OriginX: ", GETVDU(136), " OriginY: ", GETVDU(137) PRINT "FGcolor: ", GETVDU(153), " BGcolor: ", GETVDU(154) PRINT "OriginX: ", GETVDU(136), " OriginY: ", GETVDU(137) GCOLOR(0, 63, 192) MOVE(400, 1160) GPRINT("0", 0) MOVE(400 + 256 - 5, 1160) GPRINT("64", 0) MOVE(400 + (2 * 256) - 15, 1160) GPRINT("128", 0) MOVE(400 + (3 * 256) - 20, 1160) GPRINT("192", 0) ORIGIN(200, 100) FOR col = 0 TO 63 MOVE(10, (col * 16) + 16) GPRINT(RIGHT$(" " & STR$(col), 2), 0) NEXT col ORIGIN(270, 100) FOR col = 0 TO 63 FOR tint = 0 TO 192 STEP 64 GCOLOR(0, col, tint) RECTANGLE(tint * 4, col * 16, 256, 16, 1) PRINT RIGHT$(" " & STR$(col), 3), ". GCOLOR(0,", col, ",", tint, ")" NEXT tint NEXT col PRINT "OriginX: ", GETVDU(136), " OriginY: ", GETVDU(137) PRINT "FGcolor: ", GETVDU(153), " BGcolor: ", GETVDU(154) ORIGIN(0, 0) MOVE(620, 80) GCOLOR(0, 2, 3) PRINT "OriginX: ", GETVDU(136), " OriginY: ", GETVDU(137) PRINT "FGcolor: ", GETVDU(153), " BGcolor: ", GETVDU(154) GPRINT(T2$, 0) GCOLOR(0, 63, 192) ' GCOLOR(0, 2, 4) MOVE(635, 40) GPRINT(T3$, 0) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_DRAWING() KEY_WAIT()
' *********************** ' END MAIN ' ***********************
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 9, 2014 2:47:30 GMT 1
BaCorn
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 9, 2014 6:54:04 GMT 1
I compiled the C BASIC version of the libbbc.c under XP and attached it to the post. It compiled with TDMGCC32 (MinGW32) untouched. I gave it a quick test with ScriptBasic and DLLC and it work just like the Linux version. SDL 1.2 for Windows is a requirement. libbbc_win32.zip (53.29 KB)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 9, 2014 8:18:24 GMT 1
I thought I would try doing the graphdemo using C BASIC. // Graph Demo
#include <SDL.h> #include "libbbc.h" #include "cbasic.h"
MAIN BEGIN_FUNCTION DIM AS long xlow, xhigh, ylow, yhigh, depth, xscale, yscale, c, x, y; init_screen(); SDL_WM_SetCaption("C BASIC BBC graphdemo", 0); emulate_mode(31); emulate_origin(800, 600); xlow = -10; xhigh = 10; ylow = -10; yhigh = 10; depth = 10; xscale = 30; yscale = 12; c = -4000; x = 0; y = 0; DEF_FOR (x = xlow TO x <= xhigh STEP x += 1) BEGIN_FOR emulate_move(xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth)); DEF_FOR (y = ylow TO y <= yhigh STEP y += 1) BEGIN_FOR emulate_draw(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)); NEXT NEXT DEF_FOR (y = ylow TO y <= yhigh STEP y += 1) BEGIN_FOR emulate_move(xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth)); DEF_FOR (x = xlow TO x <= xhigh STEP x += 1) BEGIN_FOR emulate_draw(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)); NEXT NEXT SDL_Delay(5000); end_screen(); RETURN_FUNCTION(0); END_FUNCTION
This is the libbbc.dll version running under Windows with ScriptBasic and DLLC. ' Graph Demo
INCLUDE "dllcinc.sb"
bbc = dllfile("libbbc.dll") sdl = dllfile("sdl.dll") BBC_OPEN = dllproc(bbc,"init_screen i = ()") BBC_MODE = dllproc(bbc,"emulate_mode (i mode)") BBC_ORIGIN = dllproc(bbc,"emulate_origin (i x, i y)") BBC_DRAW = dllproc(bbc,"emulate_draw (i x, i y)") BBC_MOVE = dllproc(bbc,"emulate_move (i x, i y)") BBC_CLOSE = dllproc(bbc,"end_screen ()") SDL_WINTITLE = dllproc(sdl,"SDL_WM_SetCaption (z title, z icon)") SDL_WAIT = dllproc(sdl,"SDL_Delay (i millsecs)")
dllcall BBC_OPEN dllcall SDL_WINTITLE, "ScriptBasic SDL Graph Demo", "ScriptBasic" dllcall BBC_MODE, 31 dllcall BBC_ORIGIN, 800, 600 xlow = -10 xhigh = 10 ylow = -10 yhigh = 10 depth = 10 xscale = 30 yscale = 12 c = -4000
FOR x = xlow TO xhigh dllcall BBC_MOVE, xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth) FOR y = ylow TO yhigh dllcall BBC_DRAW, xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth) NEXT NEXT FOR y = ylow TO yhigh dllcall BBC_MOVE, xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth) FOR x = xlow TO xhigh dllcall BBC_DRAW, xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth) NEXT NEXT dllcall SDL_WAIT, 5000 dllcall BBC_CLOSE
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 9, 2014 23:42:20 GMT 1
I created a work in progress version of the BBC graphics library which I'm calling libbbc5.c. The original libbbc.c still remains on Bitbucket in its original form so we don't break any code. You guys may want to use this version for the BaCon BBC graphics library and roll in what Joe and Alex is working on. The work in process version is focused at a generic BBC plug-in that any language can bind to.
Here is an updated C BASIC version of the graphdemo using libbbc5.so.
// Graph Demo
#include <SDL.h> #include "libbbc5.h" #include "cbasic.h"
MAIN BEGIN_FUNCTION DIM AS long xlow, xhigh, ylow, yhigh, depth, xscale, yscale, c, x, y; BBC_OPEN(); SDL_WM_SetCaption("C BASIC BBC graphdemo", 0); BBC_MODE(31); BBC_ORIGIN(800, 600); xlow = -10; xhigh = 10; ylow = -10; yhigh = 10; depth = 10; xscale = 30; yscale = 12; c = -4000; x = 0; y = 0; DEF_FOR (x = xlow TO x <= xhigh STEP x += 1) BEGIN_FOR BBC_MOVE(xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth)); DEF_FOR (y = ylow TO y <= yhigh STEP y += 1) BEGIN_FOR BBC_DRAW(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)); NEXT NEXT DEF_FOR (y = ylow TO y <= yhigh STEP y += 1) BEGIN_FOR BBC_MOVE(xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth)); DEF_FOR (x = xlow TO x <= xhigh STEP x += 1) BEGIN_FOR BBC_DRAW(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)); NEXT NEXT SDL_Delay(5000); BBC_CLOSE(); RETURN_FUNCTION(0); END_FUNCTION
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 10, 2014 2:09:20 GMT 1
My goal with the BaCon BBC project was to get it kicked off and a library you guys could expand on. I have accomplished those goals and would like to hand over the lead to vovchik and friends. I will continue to post any improvements I make (keep an eye on the Bitbucket site) with the BBC graphics library and hope to snag a few goodies from your effort with BaCon.
Thanks to everyone for the help and interest in the project.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 10, 2014 5:18:30 GMT 1
I've added the BBC_GETKEY and BBC_WAITKEY functions to the libbbc5 library. The BBC_WAITKEY would only be used to keep the window active and any key or clicking the [X] in the title bar will exit the program. The BBC_GETKEY returns a unicode key value which can be compared with the default SDL keyboard constants. There is little CPU demand when using these functions.
#include <SDL.h> #include "libbbc5.h" #include "cbasic.h"
MAIN BEGIN_FUNCTION DIM AS long xlow, xhigh, ylow, yhigh, depth, xscale, yscale, c, x, y; BBC_OPEN(); SDL_WM_SetCaption("C BASIC BBC graphdemo", 0); BBC_MODE(31); BBC_ORIGIN(800, 600); xlow = -10; xhigh = 10; ylow = -10; yhigh = 10; depth = 10; xscale = 30; yscale = 12; c = -4000; x = 0; y = 0; DEF_FOR (x = xlow TO x <= xhigh STEP x += 1) BEGIN_FOR BBC_MOVE(xscale*(x+ylow), yscale*(ylow-x)+c/(x*x+ylow*ylow+depth)); DEF_FOR (y = ylow TO y <= yhigh STEP y += 1) BEGIN_FOR BBC_DRAW(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)); NEXT NEXT DEF_FOR (y = ylow TO y <= yhigh STEP y += 1) BEGIN_FOR BBC_MOVE(xscale*(xlow+y), yscale*(y-xlow)+c/(xlow*xlow+y*y+depth)); DEF_FOR (x = xlow TO x <= xhigh STEP x += 1) BEGIN_FOR BBC_DRAW(xscale*(x+y), yscale*(y-x)+c/(x*x+y*y+depth)); NEXT NEXT // BBC_WAITKEY(); DEF_WHILE (BBC_GETKEY() != SDLK_ESCAPE) BEGIN_WHILE WEND BBC_CLOSE(); RETURN_FUNCTION(0); END_FUNCTION
New libbbc5.c functions.
SUB BBC_WAITKEY() BEGIN_SUB DIM AS int done; DIM AS SDL_Event event; done = 0; DEF_WHILE (NOT done) BEGIN_WHILE DEF_WHILE (SDL_WaitEvent(AT event)) BEGIN_WHILE SELECT_CASE (event.type) BEGIN_SELECT CASE SDL_KEYDOWN: CASE SDL_QUIT: done = 1; SDL_Quit(); END_CASE CASE_ELSE END_CASE END_SELECT WEND WEND END_SUB
FUNCTION int BBC_GETKEY() BEGIN_FUNCTION DIM AS int done ; DIM AS SDL_Event event; done = 0; DEF_WHILE (NOT done) BEGIN_WHILE DEF_WHILE (SDL_WaitEvent(AT event)) BEGIN_WHILE SELECT_CASE (event.type) BEGIN_SELECT CASE SDL_KEYDOWN: RETURN_FUNCTION(event.key.keysym.unicode); done = 1; END_CASE CASE SDL_QUIT: done = 1; SDL_Quit(); END_CASE CASE_ELSE END_CASE END_SELECT WEND WEND RETURN_FUNCTION(0); END_FUNCTION
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 10, 2014 8:13:22 GMT 1
I added BBC_RND() to the libbbc5 library. This function use system time (millisecond) for randomization and returns both fractional (1) and absolute (>1) values. This should also take care of the overflow errors we are seeing with the BaCon RND() function which show up as artifacts in the polygon demo. (Bitbucket updated) vovchik, Would you have time to recreate the polygon.bac demo using the new libbbc5.so library? I want to make sure that the BBC_RND is working and solves the artifact (overflow) issue. It's late here and if you don't have the time, I'll give it a shot tomorrow in C BASIC. It still bothers me you had to use type casting in the BASIC code to get your previous version to work.
|
|
|
Post by vovchik on Feb 10, 2014 12:11:11 GMT 1
Dear John,
Good news - NO ARTEFACTS! Here is the proof. Not clean yet - many unnecessary functions in PROTO etc., but working:
' Polygon demo using BBC basic (brandy) lib with SDL calls
' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL PRAGMA LDFLAGS SDL bbc5
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' EXTERNAL FUNCTIONS ' ***********************
PROTO init_screen, emulate_mode, emulate_origin, emulate_off PROTO emulate_gcol, emulate_off, emulate_draw, emulate_move, end_screen PROTO emulate_newmode, emulate_vdu, emulate_plot PROTO SDL_WM_SetCaption, SDL_PollEvent PROTO SDL_GL_SetAttribute ALIAS SDL_ATTRIBUTE PROTO printf ALIAS PRINTF PROTO BBC_TAB PROTO echo_on PROTO echo_off PROTO set_cursor PROTO BBC_VDU PROTO BBC_VDUSTR PROTO BBC_PRINTF PROTO BBC_NEWLINE PROTO BBC_VDUFN PROTO BBC_POS PROTO BBC_VPOS PROTO BBC_MODE PROTO BBC_MODESTR PROTO BBC_NEWMODE PROTO BBC_OFF PROTO BBC_ON PROTO BBC_MODEFN PROTO BBC_COLOURFN PROTO BBC_COLOURTINT PROTO BBC_MAPCOLOUR PROTO BBC_SETCOLOUR PROTO BBC_SETCOLNUM PROTO BBC_DEFCOLOUR PROTO BBC_GCOL PROTO BBC_GCOLRGB PROTO BBC_GCOLNUM PROTO BBC_TINT PROTO BBC_TINTFN PROTO BBC_PLOT PROTO BBC_POINTFN PROTO BBC_MOVE PROTO BBC_MOVEBY PROTO BBC_DRAW PROTO BBC_DRAWBY PROTO BBC_POINT PROTO BBC_POINTBY PROTO BBC_POINTTO PROTO BBC_LINE PROTO BBC_CIRCLE PROTO BBC_ELLIPSE PROTO BBC_DRAWRECT PROTO BBC_moverect PROTO BBC_FILL PROTO BBC_FILLBY PROTO BBC_ORIGIN PROTO BBC_WAIT PROTO find_cursor PROTO BBC_OPEN PROTO BBC_CLOSE PROTO SDL_WM_SetCaption ALIAS SDL_WINTITLE PROTO draw_line PROTO filled_triangle PROTO draw_ellipse PROTO filled_ellipse PROTO toggle_cursor PROTO switch_graphics PROTO vdu_cleartext PROTO BBC_WAITKEY PROTO BBC_GETKEY PROTO BBC_RND
' *********************** ' END EXTERNAL FUNCTIONS ' ***********************
' *********************** ' INITIALIZATION ' ***********************
' define var types DECLARE angle, radius TYPE double DECLARE xorigin, yorigin, i, l TYPE int DECLARE c, t, d, side, sides TYPE int DECLARE x[10] TYPE double DECLARE y[10] TYPE double ' initialize random number generator SEED NOW
' *********************** ' INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB BBC_WINDOW(int w, int h, int mode, int colours, STRING title$) ' ------------------ ' create main SDL display window BBC_OPEN() BBC_NEWMODE(w, h, colours, -1) SDL_WINTITLE(title$, 0) BBC_VDU(mode) END SUB
' ------------------ SUB ANTIALIAS() ' ------------------ SDL_ATTRIBUTE(SDL_GL_MULTISAMPLEBUFFERS, 1) SDL_ATTRIBUTE(SDL_GL_MULTISAMPLESAMPLES, 4) END SUB
' ------------------ SUB DRAW() ' ------------------ ' draw polygons FOR i = 1 TO 1000 xorigin = BBC_RND(1250) yorigin = BBC_RND(840) radius = BBC_RND(300) + 50 BBC_ORIGIN(xorigin, yorigin) sides = BBC_RND(8) + 2 BBC_MOVE(radius, 0) BBC_MOVE(10, 10) c = BBC_RND(64) + 1 t = (BBC_RND(4) - 1) << 6 'c = RANDOM(64) + 1 't = (RANDOM(4) - 1) << 6 BBC_GCOL(0, c, t) FOR side = 1 TO sides angle = (double)(((side - 1) * 2) * (PI / sides)) x[side] = (double)(radius * COS(angle)) y[side] = (double)(radius * SIN(angle)) BBC_MOVE(0, 0) BBC_PLOT(85, (int)x[side], (int)y[side]) NEXT side BBC_MOVE(0, 0) BBC_PLOT(85, (int)radius, 0) REPEAT d = BBC_RND(64) - 1 'd = ABS(RANDOM(64) - 1) UNTIL (d & 63) <> (c & 6) BBC_GCOL(0, (int)d, (int)t) FOR side = 1 TO sides FOR l = side TO sides BBC_MOVE((int)x[side], (int)y[side]) BBC_DRAW((int)x[l], (int)y[l]) NEXT l NEXT side NEXT i END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' create SDL window BBC_WINDOW(800, 600, 32, 256, "BBC-BACON Polygons (Hit <RETURN> or left click mouse to exit)") ANTIALIAS() ' draw polygons DRAW() ' wait for user input before closing END SUB
' ------------------ SUB KEY_WAIT() ' ------------------ LOCAL event TYPE SDL_Event WHILE TRUE DO WHILE BBC_GETKEY(&event) DO SELECT event.type CASE SDL_KEYUP ' If return is pressed, quit ' see http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlkey.html IF event.key.keysym.sym = SDLK_RETURN THEN echo_off() BBC_CLOSE() END 0 END IF IF event.key.keysym.sym = SDLK_RIGHT THEN PRINT "RIGHT" END IF IF event.key.keysym.sym = SDLK_LEFT THEN PRINT "LEFT" END IF IF event.key.keysym.sym = SDLK_UP THEN PRINT "UP" END IF IF event.key.keysym.sym = SDLK_DOWN THEN PRINT "DOWN" END IF CASE SDL_MOUSEMOTION PRINTF("Current mouse position is : %d,%d \n", event.motion.x,event.motion.y ) CASE SDL_MOUSEBUTTONDOWN ' If left mouse button is clicked, quit IF event.button.button == SDL_BUTTON_LEFT THEN PRINT "LEFT BUTTON" echo_off() BBC_CLOSE() END 0 END IF IF event.button.button == SDL_BUTTON_RIGHT THEN PRINT "RIGHT BUTTON" END IF IF event.button.button == SDL_BUTTON_MIDDLE THEN PRINT "MIDDLE BUTTON" END IF CASE SDL_QUIT END 0 END SELECT WEND SLEEP 200 WEND END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
' draw polygons MK_GUI() ' wait for <RETURN> to close window KEY_WAIT()
' *********************** ' END MAIN ' ***********************
With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 10, 2014 19:11:37 GMT 1
It didn't work for me. Note: Be aware of the '& amp ;' replacement for the '&' character when using the quoted formatted code option. I was able to get it working (not happy with colours yet) but no artifacts which is nice. I'm thinking of having two BBC_RND functions. Always returning a float may be undesirable. // C BASIC BBC - Polygon
#include <math.h> #include <SDL.h> #include "libbbc5.h" #include "cbasic.h"
#define PI 3.14159265358979323846
MAIN BEGIN_FUNCTION DIM AS float64 angle, radius, x[10], y[10]; DIM AS int32 c, t, d, side, sides, xorigin, yorigin, i, l; BBC_OPEN(); BBC_MODESTR(800, 600, 256, 0, 1, 1, -1); SDL_WM_SetCaption("C BASIC BBC5 - polygon", 0); BBC_VDU(26); DEF_FOR (i = 1 TO i <= 500 STEP INCR i) BEGIN_FOR xorigin = (int32)BBC_RND(1250); yorigin = (int32)BBC_RND(840); radius = (int32)BBC_RND(300) + 50; BBC_ORIGIN(xorigin, yorigin); sides = (int32)BBC_RND(8) + 2; BBC_MOVE(radius, 0); BBC_MOVE(10, 10); c = (int32)BBC_RND(64) - 1; t = (int32)BBC_RND(4) - 1 << 6; BBC_GCOL(0, c, t); DEF_FOR (side = 1 TO side <= sides STEP INCR side) BEGIN_FOR angle = (side -1) * 2 * PI / sides; x[side] = radius * cos(angle); y[side] = radius * sin(angle); BBC_MOVE(0, 0); BBC_PLOT(85, x[side], y[side]); NEXT BBC_MOVE(0, 0); BBC_PLOT(85, radius, 0); DO d = (int32)BBC_RND(64) - 1; WHILE ((d & 63) != (c & 6)); BBC_GCOL(0, d, t); DEF_FOR (side = 1 TO side <= sides STEP INCR side) BEGIN_FOR DEF_FOR (l = side TO l <= sides STEP INCR l) BEGIN_FOR BBC_MOVE(x[side], y[side]); BBC_DRAW(x[l], y[l]); NEXT NEXT NEXT BBC_WAITKEY(); BBC_CLOSE(); RETURN_FUNCTION(0); END_FUNCTION
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 11, 2014 1:12:51 GMT 1
I created a BBC_RAND function that handles fractional random values. This function reseeds if a -1 is passed. The BBC_RND function accepts a positive integer value of 2 or greater and returns an integer value. Here is the latest polygon code.
// C BASIC Polygon
#include <math.h> #include <SDL.h> #include "libbbc5.h" #include "cbasic.h"
#define PI 3.14159265358979323846
MAIN BEGIN_FUNCTION DIM AS float64 angle, radius, x[10], y[10]; DIM AS int32 c, t, d, side, sides, xorigin, yorigin, i, l; BBC_OPEN(); BBC_MODESTR(800, 600, 256, 0, 1, 1, -1); SDL_WM_SetCaption("C BASIC BBC5 - polygon", 0); BBC_VDU(26); DEF_FOR (i = 1 TO i <= 500 STEP INCR i) BEGIN_FOR xorigin = BBC_RND(1250); yorigin = BBC_RND(840); radius = BBC_RND(300) + 50; BBC_ORIGIN(xorigin, yorigin); sides = BBC_RND(8) + 2; BBC_MOVE(radius, 0); BBC_MOVE(10, 10); c = BBC_RND(64) - 1; t = BBC_RND(4) - 1 << 6; BBC_GCOL(0, c, t); DEF_FOR (side = 1 TO side <= sides STEP INCR side) BEGIN_FOR angle = (side -1) * 2 * PI / sides; x[side] = radius * cos(angle); y[side] = radius * sin(angle); BBC_MOVE(0, 0); BBC_PLOT(85, x[side], y[side]); NEXT BBC_MOVE(0, 0); BBC_PLOT(85, radius, 0); DO d = BBC_RND(64) - 1; WHILE ((d & 63) != (c & 6)); BBC_GCOL(0, d, t); DEF_FOR (side = 1 TO side <= sides STEP INCR side) BEGIN_FOR DEF_FOR (l = side TO l <= sides STEP INCR l) BEGIN_FOR BBC_MOVE(x[side], y[side]); BBC_DRAW(x[l], y[l]); NEXT NEXT NEXT BBC_WAITKEY(); BBC_CLOSE(); RETURN_FUNCTION(0); END_FUNCTION
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 11, 2014 2:14:42 GMT 1
I added in your casting to see if it would help. I don't think it makes a difference. I not sure if I'm seeing 256 colors as my SB version seems more colorful. // C BASIC Polygon
#include <math.h> #include <SDL.h> #include "libbbc5.h" #include "cbasic.h"
#define PI 3.14159265358979323846
MAIN BEGIN_FUNCTION DIM AS float64 angle, radius, x[10], y[10]; DIM AS int32 c, t, d, side, sides, xorigin, yorigin, i, l; BBC_OPEN(); BBC_MODESTR(800, 600, 256, 0, 1, 1, -1); SDL_WM_SetCaption("C BASIC BBC5 - polygon", 0); BBC_VDU(26); DEF_FOR (i = 1 TO i <= 100 STEP INCR i) BEGIN_FOR xorigin = BBC_RND(1250); yorigin = BBC_RND(840); radius = BBC_RND(300) + 50; BBC_ORIGIN(xorigin, yorigin); sides = BBC_RND(8) + 2; BBC_MOVE((int32)radius, 0); BBC_MOVE(10, 10); c = BBC_RND(64) - 1; t = BBC_RND(4) - 1 << 6; BBC_GCOL(0, (int32)c, (int32)t); DEF_FOR (side = 1 TO side <= sides STEP INCR side) BEGIN_FOR angle = (float64)(((side - 1) * 2) * (PI / sides)); x[side] = (float64)(radius * cos(angle)); y[side] = (float64)(radius * sin(angle)); BBC_MOVE(0, 0); BBC_PLOT(85, (int32)x[side], (int32)y[side]); NEXT BBC_MOVE(0, 0); BBC_PLOT(85, (int32)radius, 0); DO d = BBC_RND(64)- 1; WHILE ((d & 63) != (c & 6)); BBC_GCOL(0, (int32)d, (int32)t); DEF_FOR (side = 1 TO side <= sides STEP INCR side) BEGIN_FOR DEF_FOR (l = side TO l <= sides STEP INCR l) BEGIN_FOR BBC_MOVE((int32)x[side], (int32)y[side]); BBC_DRAW((int32)x[l], (int32)y[l]); NEXT NEXT NEXT BBC_WAITKEY(); BBC_CLOSE(); RETURN_FUNCTION(0); END_FUNCTION
|
|
|
Post by vovchik on Feb 11, 2014 2:38:41 GMT 1
Dear John, This works for me - but I am not certain of the colour depth. With kind regards, vovchik ' Polygon demo using BBC basic (brandy) lib with SDL calls
' *********************** ' COMPILER DIRECTIVES ' ***********************
PRAGMA INCLUDE SDL.h PRAGMA OPTIONS -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_OPENGL PRAGMA LDFLAGS SDL bbc5
' *********************** ' END COMPILER DIRECTIVES ' ***********************
' *********************** ' EXTERNAL FUNCTIONS ' ***********************
PROTO SDL_GL_SetAttribute ALIAS SDL_ATTRIBUTE PROTO BBC_VDU PROTO BBC_MODESTR PROTO BBC_GCOL PROTO BBC_PLOT PROTO BBC_MOVE PROTO BBC_DRAW PROTO BBC_ORIGIN PROTO BBC_OPEN PROTO BBC_CLOSE PROTO SDL_WM_SetCaption ALIAS SDL_WINTITLE PROTO BBC_WAITKEY PROTO BBC_GETKEY PROTO BBC_RND
' *********************** ' END EXTERNAL FUNCTIONS ' ***********************
' *********************** ' INITIALIZATION ' ***********************
DECLARE angle, radius TYPE double DECLARE x[10], y[10] TYPE double DECLARE xorigin, yorigin, i, l TYPE int DECLARE c, t, d, side, sides TYPE int
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB ANTIALIAS() ' ------------------ SDL_ATTRIBUTE(SDL_GL_MULTISAMPLEBUFFERS, 1) SDL_ATTRIBUTE(SDL_GL_MULTISAMPLESAMPLES, 4) END SUB
' ------------------ SUB MK_DRAWING() ' ------------------ BBC_OPEN() BBC_MODESTR(800, 600, 256, 0, 1, 1, -1) SDL_WINTITLE("C BASIC BBC5 - polygon", 0) BBC_VDU(26) ANTIALIAS() FOR i = 1 TO 500 xorigin = BBC_RND(1250) yorigin = BBC_RND(840) radius = BBC_RND(300) + 50 BBC_ORIGIN(xorigin, yorigin) sides = BBC_RND(8) + 2 BBC_MOVE(radius, 0) BBC_MOVE(10, 10) c = BBC_RND(64) - 1 t = BBC_RND(4) - 1 << 6 BBC_GCOL(0, c, t) FOR side = 1 TO sides angle = (double)(((side - 1) * 2) * (PI / sides)) x[side] = (double)(radius * COS(angle)) y[side] = (double)(radius * SIN(angle)) BBC_MOVE(0, 0) BBC_PLOT(85, (int)x[side], (int)y[side]) NEXT side BBC_MOVE(0, 0) BBC_PLOT(85, (int)radius, 0) REPEAT d = BBC_RND(64) - 1 UNTIL ((d & 63) != (c & 6)) BBC_GCOL(0, d, t) FOR side = 1 TO sides FOR l = side TO sides BBC_MOVE((int)x[side], (int)y[side]) BBC_DRAW((int)x[l], (int)y[l]) NEXT l NEXT side NEXT i END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_DRAWING() BBC_WAITKEY() BBC_CLOSE()
' *********************** ' END MAIN ' ***********************
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 11, 2014 2:54:31 GMT 1
Nice Job! Looks better than mine. IMO
|
|