AllBASIC Forum
BASIC Developer & Support Resources => Translators => C BASIC => Topic started by: Mike Lobanovsky on December 10, 2013, 01:27:46 PM
-
John,
Full sources for TinyPTC by Gaffer can be found at SourceForge (http://sourceforge.net/projects/tinyptc/files/). That's a complete package including an SDL solution. I'm not a member at the O2 Basic forum nor do I plan to be one, so this hint here may help you proceed with your Julia Rings project there.
The fractal animation is very spectacular and neat indeed. Thanks for the nice find.
-
Thanks Mike!
That should get me back up an running again. I haven't seen any other submissions so the fractal top gun prize still stands. ;D
Update
Got it working and it's runs great. I wonder if this is the first ever 64 bit version?
(http://files.allbasic.info/C_BASIC/cbjuliarings.png)
http://files.allbasic.info/C_BASIC/juliarings.swf
/*
The Lord of the Julia Rings
The Fellowship of the Julia Rings
Relsoft
Rel.Betterwebber.com
C BASIC version by JRS 12/9/2013
*/
#include <math.h>
#include <tinyptc.h>
#include "cbasic.h"
#define SCR_WIDTH 320 * 1
#define SCR_HEIGHT 240 * 1
#define SCR_SIZE SCR_WIDTH*SCR_HEIGHT
#define PI 3.141593
#define MAXITER 20
#define MAXSIZE 4
DIM AS static int vpage[SCR_SIZE];
DIM AS static float lx[SCR_WIDTH];
DIM AS static float ly[SCR_WIDTH];
MAIN
BEGIN_FUNCTION
DIM AS int px , py, i, pixel, red , grn , blu, tmp, i_last;
DIM AS float p, q, xmin, xmax, ymin, ymax, theta, deltax , deltay, x, y, xsquare, ysquare, ytemp, ty;
DIM AS float cmag, cmagsq, zmag, drad, drad_L, drad_H, ztot;
DIM AS int PTR p_buffer;
DIM AS int PTR p_bufferl;
DIM AS unsigned int frame;
xmin = -2.0;
xmax = 2.0;
ymin = -1.5;
ymax = 1.5;
deltax = (xmax - xmin) / (float)(SCR_WIDTH - 1);
deltay = (ymax - ymin) / (float)(SCR_HEIGHT - 1);
FOR (i = 0 TO i < SCR_WIDTH STEP INCR i)
BEGIN_FOR
lx[i] = xmin + i * deltax;
NEXT
FOR (i = 0 TO i < SCR_HEIGHT STEP INCR i)
BEGIN_FOR
ly[i] = ymax - i * deltay;
NEXT
IF (NOT ptc_open("C BASIC - Julia Rings",SCR_WIDTH,SCR_HEIGHT)) THEN_DO RETURN_FUNCTION(1);
frame = 0;
WHILE (1)
BEGIN_WHILE
p_buffer = vpage;
p_bufferl = AT vpage[SCR_SIZE-1];
frame = (frame + 1) & 0x7fffffff;
theta = frame * PI / 180.0f;
p = cos(theta) * sin(theta * .7);
q = sin(theta) + sin(theta);
p = p * .6;
q = q * .6;
cmag = sqrt(p *p + q* q);
cmagsq = (p *p + q* q);
drad = 0.04;
drad_L = (cmag - drad);
drad_L = drad_L * drad_L;
drad_H = (cmag + drad);
drad_H = drad_H * drad_H;
FOR (py = 0 TO py < (SCR_HEIGHT >> 1) STEP INCR py)
BEGIN_FOR
ty = ly[py];
FOR (px = 0 TO px < SCR_WIDTH STEP INCR px)
BEGIN_FOR
x = lx[px];
y = ty;
xsquare = 0;
ysquare = 0;
ztot =0;
i = 0;
WHILE (i < MAXITER AND (xsquare + ysquare) < MAXSIZE)
BEGIN_WHILE
xsquare = x * x;
ysquare = y * y;
ytemp = x * y * 2;
x = xsquare - ysquare + p;
y = ytemp + q;
zmag = (x * x + y * y);
IF (zmag < drad_H AND zmag > drad_L AND i > 0) THEN
ztot = ztot + ( 1 - (fabs(zmag - cmagsq) / drad));
i_last = i;
END_IF
INCR i;
IF (zmag > 4.0) THEN_DO EXIT_WHILE
WEND
IF (ztot > 0) THEN
i = (int)(sqrt(ztot) * 500);
ELSE
i = 0;
END_IF
IF (i < 256) THEN
red = i;
ELSE
red = 255;
END_IF
IF (i < 512 AND i > 255) THEN
grn = i - 256;
ELSE_IF (i >= 512) THEN
grn = 255;
ELSE
grn = 0;
END_IF
IF (i <= 768 AND i > 511) THEN
blu = i - 512;
ELSE_IF (i >= 768) THEN
blu = 255;
ELSE
blu = 0;
END_IF
tmp = (int)((red + grn + blu) * 0.33);
tmp = tmp & 0xFF;
red = (int)((red + grn + tmp) * 0.33);
red = red & 0xFF;
grn = (int)((grn + blu + tmp) * 0.33);
grn = grn & 0xFF;
blu = (int)((blu + red + tmp) * 0.33);
blu = blu & 0xFF;
SELECT_CASE (i_last MOD 3)
BEGIN_SELECT
CASE 1:
tmp = red;
red = grn;
grn = blu;
blu = tmp;
END_CASE
CASE 2:
tmp = red;
blu = grn;
red = blu;
grn = tmp;
END_CASE
END_SELECT
pixel = red << 16 | grn << 8 | blu;
PTR p_buffer = pixel;
PTR p_bufferl = pixel;
INCR p_buffer;
DECR p_bufferl;
NEXT
NEXT
ptc_update(vpage);
WEND
RETURN_FUNCTION(0);
END_FUNCTION
-
Nice job John,
But I'm afraid there was something like that done in QB64.
OTOH the following is certainly the first one done in FBSL:
(http://www.fbsl.net/phpbb2/download/file.php?id=1813)
and the source and executable are here (http://www.fbsl.net/phpbb2/download/file.php?id=1814) in case anybody is interested.
-
I tried yours under Wine and it ran smoothly and produce gorgeous fractals. The C BASIC version seems to be running too fast to appreciate the fractals being generated. I think allowing the screen to be resized and adjust speed would be two nice improvements. Full screen works for me under Ubuntu.
FBSL
http://files.allbasic.info/FBSL/juliarings_fbsl.swf
-
Thanks John,
The main window is resizable in Windows also by dragging any corner or side so I guess it should work the same in Wine too. And yes, the original implementation relies on a tight events loop and overloads the CPU. That's why I decided to move it to interpreted BASIC to slow down the phase change a bit.
Alternatively, a hi-res timer adjustable within 30 to 60FPS may be used to control the animation speed. The use of timer will also bring down the CPU load to about 2 to 5 per cent.
-
There was no extra effort to do this right with the C BASIC version. You did a nice job with the FBSL version and in my mind wins the top gun prize. :)
As Mike is leaving the podium after accepting his prize, a last minute development snatched (http://www.oxygenbasic.org/forum/index.php?topic=889.msg7650#msg7650) the first place honors and Mike ended up taking second prize. A fair fight none the less.
-
Yes John,
Charles' OpenGL is certainly a killer though I'd suggest using "glCopyTexSubImage2D" to update the texture instead of re-creating it from scratch in every frame. This would bring down the number of OpenGL state changes dramatically and increase the FPS rate accordingly.
Nonetheless his first prize is clearly a well-deserved decision. :)
-
I think you and Charles did a great job of enhancing the Julia Rings by Relsoft example and I thank both of you for the effort.
-
I always hated that spasmodic white blotch on my screen. Now enjoy this hors concours submission of pure GDI beauty with extra coloration, random placement, and more pleasing resolution and speed. Fixes are minimal and can be easily ported anywhere.
(http://www.fbsl.net/phpbb2/images/smilies/icon_ml_noel.gif)