heres some code i bashed up really quickly this avo its just a port of your code that hopefully will let you get to grips with tiny.
now what id like to see is the lightning moving acrross the screen not to slowly and mabey flashing which you can do to the lines and also the background using the setrgb function then when youve got that sorted well see about blurring the lines.
'THE MAIN DIFFRENCE IN USING TINYPTC I CAN THINK OF IS THAT YOU GET NO GRAPHICS FUNCTIONS
'ALL YOU GET IS A 1D FRAME BUFFER IE INSTED OF BUFFER(0 TO 640, 0 TO 480) YOU GET BUFFER(0 TO 640*480)
'NOW TO PLOT A POINT AT SAY 10,100 YOU NEED AN AGORITHM HER IT IS Y*SCR_WIDTH+X SO THE LINE OF CODE
'WOULD BE BUFFER(100*640+10)=COLOR_VALUE THATS BASICALLY THE FUNDEMENTALLS TO IT NOW TO DRAW DIFFRENT
'SHAPES AND EFFECTS YOU USE THAT FORMULA WITH YOUR OWN CODE AND VWALLA
defint a-z
'$include: 'tinyptc.bi'
dim shared SCR_WIDTH as integer
dim shared SCR_HEIGHT as integer
dim shared SCR_SIZE as integer
'HERE I JUST DECLARE THE FUNCTIONS IM GOINGTO USE
declare function flip_buffer()
declare function clear_buffer()
declare function setrgb(byval index as double,byval red as double,byval green as double,byval blue as double)
declare function my_circle(byval x as double, byval y as double, byval r as double)
declare function my_line(byval x1 as double,byval y1 as double,byval x2 as double,byval y2 as double)
declare function open_window(byval xres as double,byval yres as double)
'i use option dynamic on the buffer array so i can resize it in the open window
'function to the size of the screen
'$DYNAMIC
dim shared buffer(0) as integer
dim shared forground_pallette_color as integer
dim shared background_pallette_color as integer
'these two lines just set the background to black and forground to white by default
forground_pallette_color = rgb( 255 , 255 , 255 )
background_pallette_color = rgb( 0 , 0 , 0 )
'here we open the ptc window with my own function thats not really needed but i find
'its a bit cleaner
open_window(640,480)
dim a as integer
dim r as integer
dim r2 as integer
dim i as integer
dim o as integer
randomize
'heres our main loop
do
r = INT(RND(25)*75)+1
r2 = INT(RND(25)*75)+1
i=15
o = int(rnd(1)*4)
if o = 0 then r2 =- r2
if o = 2 then r=-r
'HERES THE MAIN DIFFRENCE FROM MY TINY CODE TO THE FB CODE
'SETRGB SETS EITHER THE BACKGROUND COLOR OR FORGROUND COLOR AS SO
'SETRGB INDEX(1 OR 0) 1 = FORGROUND 0 = BACKGROUND , RED(0 TO 255) , GREEN(0 TO 255) , BLUE(0 TO 255)
setrgb 1,0,0,255
'MY CIRCLE DIFFRERS IN THAT ALL YOU NEED SEING AS YOUVE JUST SET THE COLOR IS
'MY CIRCLE X1,Y1,RAD
my_circle 0, 240 , 6
my_circle 639,240 , 6
'AGAIN THE SAME APPLIES TO MY LINE
'MY LINE X1,Y1,X2,Y2
my_line 0 , 240 , 100+r , 200+r2
my_line 100+r , 200+r2 , 225+r , 295+r2
my_line 225+r , 295+r2 , 265+r , 220+r2
my_line 265+r , 220+r2 , 305+r , 315+r2
my_line 305+r , 315+r2 , 450+r , 150+r2
my_line 450+r , 150+r2 , 550+r , 300+r2
my_line 550+r , 300+r2 , 585+r , 200+r2
my_line 585+r , 200+r2 , 639 , 240
'NOW TO SIMULATE DOUBLE BUFFERING WY PUSH THE BUFFER ARRAY UP TO THE ACTUALLY SCREEN WITH FLIP_BUFFER
flip_buffer
'THEN CLEAR IT READY FOR THE NEXT FRAME
clear_buffer
loop until( inkey$ = chr$(27) )
'a bit of house keeping
'empty the keboard buffer
while INKEY$ <> "": wend
'after code execution you have to close ptc
ptc_close
'and then clear the buffer
erase buffer
function my_circle(byval x as double, byval y as double, byval r as double)
dim r2 as double
dim z as double
dim w as double
if r<0 then exit function
r2 = (r*r)
for z=-r to r
w=sqr(r2-z*z)
my_line x-w,z+y,x+w,z+y
next
return 0
end function
''''''''''''''''''''''''''''''''''''''''''''''''''
' my_line named so because line was already taken
' Bresenham's infamous line algorithm
''''''''''''''''''''''''''''''''''''''''''''''''''
function my_line(byval x1 as double ,byval y1 as double ,byval x2 as double ,byval y2 as double)
dim i, deltax, deltay, numpixels as integer
dim d, dinc1, dinc2 as integer
dim x, xinc1, xinc2 as integer
dim y, yinc1, yinc2 as integer
'sort points
if x1>x2 then
tmp = x1
x1 = x2
x2 = tmp
endif
if y1<0 then
tmp = y1
y1 = y2
y2 = tmp
endif
'a spot of clipping
if x1<0 then x1 = 0
if x2>SCR_WIDTH then x2 = SCR_WIDTH - 1
if y1<0 then y1 = 0
if y2>SCR_WIDTH then y2 = SCR_HEIGHT - 1
'calculate deltaX and deltaY
deltax = abs(int(x2) - int(x1))
deltay = abs(int(y2) - int(y1))
'initialize
if(deltax >= deltay) then
'If x is independent variable
numpixels = deltax + 1
d = (2 * deltay) - deltax
dinc1 = deltay shl 1
dinc2 = (deltay - deltax) shl 1
xinc1 = 1
xinc2 = 1
yinc1 = 0
yinc2 = 1
else
'if y is independent variable
numpixels = deltay + 1
d = ( 2 * deltax ) - deltay
dinc1 = deltax shl 1
dinc2 = ( deltax - deltay ) shl 1
xinc1 = 0
xinc2 = 1
yinc1 = 1
yinc2 = 1
endif
'move the right direction
if ( int(x1) > int(x2) ) then
xinc1 = -xinc1
xinc2 = -xinc2
endif
if ( int(y1) > int(y2) ) then
yinc1 = -yinc1
yinc2 = -yinc2
endif
x = int(x1)
y = int(y1)
'draw the pixels
for i = 1 to numpixels
buffer( y*SCR_WIDTH+x ) = forground_pallette_color
if ( d < 0 ) then
d = d + dinc1
x = x + xinc1
y = y + yinc1
else
d = d + dinc2
x = x + xinc2
y = y + yinc2
endif
next
return 0
end function
'this function sets your background or forground color to what ever you specify
function setrgb(byval index as double,byval red as double,byval green as double,byval blue as double)
if index = 0 then background_pallette_color = rgb( red , green , blue )
if index = 1 then forground_pallette_color = rgb( red , green , blue )
return 0
end function
'this function will open a tinyptc window what ever valid size you specify
function open_window(byval xres as double, byval yres as double)
SCR_WIDTH=xres
SCR_HEIGHT=yres
SCR_SIZE=xres*yres
redim buffer( 0 to SCR_SIZE - 1) as integer
ptc_open( "ELECTRICITY", SCR_WIDTH, SCR_HEIGHT )
return 0
end function
'this pushes the back buffer up to the display through tinyptc
function flip_buffer()
ptc_update @buffer(0)
return 0
end function
' this function clears our screen or what i like to think of the back buffer
function clear_buffer()
for x=0 to SCR_SIZE-1 'scr_size is 640*480 because remember tiny uses 1d arrays
buffer(x) = background_pallette_color 'flushes all the elements in our screen refrence array i.e sets the color of each screen pixel to the color specifyed by setrgb
next
return 0
end function
<edited a small typo that stoped the background changing color>