Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - sf-in-sf

#1
Hi! i am back on XP since my win7 machine died, and win7 became expensive. Back with a lovely game I would like to check on an android tablet.
When I compile for android I get:

_______________________________________
*** Configuration: ANDROID ***
precompiling:
GPC - GLBasic Precompiler V.10.037 SN:95ed84a0 - 3D, NET
Wordcount:8 commands
compile+link:
Android=E:\GLBasic_v14\FOO\distribute\Android
success
_______________________________________
*** Finished ***
Elapsed: 21.8 sec. Time: 21:48
Build: 1 succeeded.


What is going on? I read and applied all 3 pages of the forum to no avail.
I never see a Q: drive, my "E:\GLBasic_v14\FOO\distribute\Android" never contains a /bin nor a *.apk.
Strangely this win XP self-rooted in E:\ when installing. Is it a problem?
ant is installed and replies properly "xml is missing". (see the difference between a black ant and a green robot.)
adb is working too, does recognise the tablet.
I have set the SYSTEM variables ANDROID_SWT, ANDROIDSDK, ANT_HOME, JAVA_HOME (E:\Java\jdk1.6.0_29).
What can be wrong now?
XP has no E:\users\... folder do i need to make one?
During the making of everything, which batch files are called? -so I can manually check that each (batch script) call and location is correct?
Thank you!
#2
Off Topic / Cookery
2015-Nov-04
Between coding and coding, what is better than cooking some nice food to revigorate your tired brain?
This post is to invite you to show off your best kept cookery secrets. Is it a problem? It shouldn't, this forum is not about cooking  =D
Thanks every one!

Now guess what is my favorite cafe in Berlin? Wohnzimmer! (= living room, Helmholtzplatz).
#3
Hi! I am available to code "anything" -as long as you know what you want. Gaming, maths, physics, 3D are welcome. Please use a personal message to contact me. English, German, French are o.k.
sf-in-sf
#4
IDE/Syntax / IDE + code
2015-Oct-12
Hi there!

A)
As a Basic programmer I still want a REM command. It has the same effect as // to start a line, but it's a good old b.a.s.i.c. style. Please, a bit of respect for the elders when doing some "retro" stuff.
B)
For the purpose of code clarity, I wish a command to temporarily change the code's background color, for a particular small section. So it becomes easy to spot the zone when scrolling some long code up and down. It could be named REM_BGCOL. It accepts a color like 0x003300 or rgb(0,51,0), and a DEFAULT value to go back to the standard color. It doesn't work inside an INLINE paragraph. It only talks to the IDE and is always skipped by the compiler.
C)
When some weird behaviour occurs I often wish to have an conditional stop/break/pause/debug function. It's an extension of the DEBUG function, where the breakpoint is triggered by a condition -e.g. some abnormal values, or why not a "catch error" line.
Thank you in advance!
#5
IDE/Syntax / users' themes
2015-Jun-16
Is there a way to share our IDE appearance own themes -fonts and colors? So we could see what others do to make life easier to read on the screen. It's about the user's experience. Please suggest something.
#6
Tools / command request
2015-Jun-16
Hi!
It's cool to have FILEREQUEST$ available but it's not enough. It lacks a title for the window, in order to make clear what is the requester for, when you need multiple requesters to locate various things. A title should say, for example, if you wanna read or write/give-a-new-filename...
Unfortunately, I found no FOLDERREQUEST$ (tell me if I am wrong). I need it to input where all the pictures of an album are located. Or, where sorted textures live together. Is there any way around that problem?
#7
I wanted to see the sky...  :happy: it took me a few hours. Now I can die in peace.
I don't guarantee it's 100% right, but it works. Image size must be 2^n+1. This fractal generator is the base for anything like terrains: you will have to re-map colors to heights of the map/image. Those textures can be mapped later to low-poly surfaces, for fast 3D.
   Limitations: a) how to make images larger than the screen? even with CREATESCREEN() I don't get it. b) MEM2SPRITE() looks fast but a similar function is needed in order to accept directly a 2D array[][], and possibly setup the image size automatically.
   What else? ...  Licence? use and modify at will, but don't sell it without my consent. Credits: please mention my artist's name: F.P. Brixey
   Some post-stretching helps further (see pictures).
Here is a useful reference: http://www.gameprogrammer.com/fractal.html
Now go and be creative! -oh, and share your best groundbreaking images here. Thank you.
CloudGen.gbas:
Code (glbasic) Select
// --------------------------------- //
// Project: CloudGen
// Start: Tuesday, March 17, 2015
// IDE Version: 12.308


// SETCURRENTDIR("Media") // go to media files

CONSTANT N%= 9 //  image size = 2^N
CONSTANT startval=0xf000
CONSTANT damping=0.72277 //high value-> high contrast. lo ->no fine tesseling.
// min. value should be 0.5 i.e. 50%
GLOBAL shift=0.03611 // i.e. % of displacement. Low values produce haze.

GLOBAL s2%=twoPn(N)+1 , xx%=twoPn(N)
GLOBAL im_dat%[]; //DIM im_dat[s2*s2] // 1D only!
GLOBAL tmp%[]   ; DIM tmp[s2][s2];

GLOBAL range%=twoPn(N-1)

//set start values of 4 corners. Subdivide the square later, and reign.
tmp[0 ][0 ]=startval
tmp[0 ][xx]=startval
tmp[xx][0 ]=startval
tmp[xx][xx]=startval

GOSUB fill

GOSUB mem2s

SHOWSCREEN ; MOUSEWAIT ; END ;


fn.gbas:
Code (glbasic) Select
// --------------------------------- //
// Project: CloudGen
// Start: Tuesday, March 17, 2015
// IDE Version: 12.308



FUNCTION twoPn: n%
RETURN ASL(0x1,n)
ENDFUNCTION

FUNCTION setminmax: BYREF a, mi, ma
IF a<mi THEN a=mi
IF a>ma THEN a=ma
ENDFUNCTION

FUNCTION frnd:
?IFDEF PHASE1+
STATIC a=0.41,b
IF RND(1)
b= a*(RND(2000)-1000.0)*0.001
RETURN b
ELSE
RETURN 0.0
ENDIF
?ELSE
RETURN 0.0
?ENDIF
ENDFUNCTION

SUB fill:

// GLOBAL s2%=twoPn(N)+1
// DIM tmp[s2][s2];
// GLOBAL range%=twoPn(N-1) //start value.
// CONSTANT rough=0.5 ; GLOBAL shift=0.4

// Say the output values are 32bits.
// 123
// 456
// 789 Supplied: 1379
//      Goal:    2 456 8

?IF 0
STATIC i%,j%,s5%,ste%
STATIC nb%=1

REPEAT
ste=twoPn(N-nb+1)
ste=twoPn(N-nb+1)
// INC div; ste=(s2-1)/div

FOR i=1 TO nb
FOR j=1 TO nb
setheight(tmp[i*ste][j*ste],tmp[(i+1)*ste][(j+1)*ste]) //5
NEXT; NEXT;

INC nb
UNTIL (N-nb+1)<0
?ENDIF

//////////////////////////////

ini:
LOCAL incr%=twoPn(N), i%, i2%
LOCAL j%,j2% //  xx%=twoPn(N)
LOCAL cnt%=0

REPEAT
i=0
REPEAT
// DEBUG incr ; DEBUG " "
i2=i+incr

j=0
REPEAT
//DEBUG j ; DEBUG "_" ; DEBUG incr ; DEBUG "  ";
j2=j+incr
tmp[(i+i2)*0.5][ j        ]=setheight(tmp[i][j],tmp[i2][j])
tmp[ i        ][(j+j2)*0.5]=setheight(tmp[i][j],tmp[i][j2])

tmp[(i+i2)*0.5][ j2       ]=setheight(tmp[i][j2],tmp[i2][j2])
tmp[ i2       ][(j+j2)*0.5]=setheight(tmp[i2][j],tmp[i2][j2])
IF RND(100)>33 //let's mix the 2
tmp[i+incr*0.5][j+incr*0.5]=setheight(tmp[i][j],tmp[i2][j2]) //produces diagonals.
ELSE
tmp[i+incr*0.5][j+incr*0.5]=setheight(tmp[i+incr*0.5][j],tmp[i+incr*0.5][j2]) //no effect?
ENDIF
j=j2 ; INC j2,incr
UNTIL j2>xx


i=i2 ; INC i2,incr
UNTIL i2>xx
// ASR(incr,1) //  x0.5 ASR not working!!!
incr=incr*0.5
shift=shift*damping

//(debugging safety, sorry) INC cnt; IF cnt>144 THEN END
UNTIL incr < 2
//DEBUG "fill finished.   "
ENDSUB

SUB mem2s:
LOCAL a,col
//DEBUG MEM2SPRITE(......)    --> 1 or 0.
?IF 0 // long method... because 1 dimpush[] per pixel. not good.
//this section is excluded from pgm.
FOR i%=0 TO xx; FOR j%=0 TO xx;
IF tmp[i][j]>startval //0x10000
DIMPUSH im_dat[], 0xff007700//tmp[i][j] //orientation correct?
ELSE
DIMPUSH im_dat[], 0xaaffffff
ENDIF
NEXT; NEXT;

IF MEM2SPRITE(im_dat[],0,s2,s2) THEN DEBUG "MEM2S' is o.k. "// :( Same size! 1D array only!
?ENDIF

//\/\/\/\/\/\/\/\/\/\/\/ faster:



FOR i%=0 TO xx; FOR j%=0 TO xx;

a=((tmp[i][j])/startval +(0.2-1.0))/0.4 -1.0; setminmax(a,-0.99,-0.001)
//ALPHAMODE a/2550
//col=a*RGB(200,5,8) + (1.0-a)*RGB(250,250,250)
ALPHAMODE 0
col=0xbb3333
SETPIXEL i,j, col  //no, use a single DRAWRECT at the start.
ALPHAMODE a
col=0xeeeeee
SETPIXEL i,j, col //

NEXT; NEXT;

//MEM2SPRITE() could be faster, but accepts only 1D arrays.
ENDSUB

FUNCTION setheight: a,b
//STATIC k
//k=RND(3636)
IF RND(1)
//RETURN (a+b)*0.5*(1+shift*100/RND(100)) // wow!
RETURN (a+b)*0.5*(1+shift*(1.0+RND(1)*0.5))
ELSE
RETURN (a+b)*0.5*(1-shift)
ENDIF
// or make up your own law of displacement. Be creative.
ENDFUNCTION

#8
I realized it was easier to program 3D shapes (thank you so much Gernot) than using an unknown super-whizz-bang-3D-modeller software. The aftermath of a failed project shows the basic concepts for a CAD modeller. This approach is not the most graphical one, but anything is allowed if you want to program any kind of anything, like a very special procedural deformer, or probabilistic shapes like the natural trees !....
Use, re-use, ab-use, improve, or artistically decimate at will!

main:
Code (glbasic) Select

// --------------------------------- //
// Project: CADpipes_A
// Start: Saturday, November 08, 2014
// IDE Version: 10.283



//notes: Maybe it would make sense to create arrays of 3Dobjects
// in order to group them, (group or "layer")
// so we can quickly choose whether to draw or ommit a whole array/group.
// It depends what you do...
// Draw a group/layer with "FOREACH ob in group_array[]".

//colors are 0xBBGGRR in hex.
//arrows -> move the camera.
// +/- -> zoom
// 1/3,4/6,7/9 -> move model +/- on x,y,z axes.

// to do: every obj in a different color for clarity, then
// all of them in main color for final view. (probably all vertices in white, then use X_SETTEXTURE.)
// 3 guide planes / rasters in xy yz xz would be useful, switchable with "g".


LIMITFPS 25
CONSTANT rseg%=60//20
CONSTANT r_3=1.2
GLOBAL mcol%=0xaaffaa, scrx,scry
GLOBAL mousefree%, mx,my,b1,b2,t$
GLOBAL cam_d=75, cam_phi=6, cam_theta=20, cam_px=0,cam_py=0,cam_pz=0
GLOBAL model_px, model_py, model_pz
GOSUB make_bg


//make all pieces:
make_pipe_A(1,r_3,-1,1,mcol)//small, inside the S's
make_pipe_A(2,r_3,-5,5,0xbbbbbb)
make_pipe_A(3,r_3,0,100,0xe07777)//0x99ff33)

make_shoulder_A(20,r_3,30,90,10,mcol)
make_shoulder_A(24,r_3,30,180,10,mcol)
//make_disc(201,5,360,8,0xff5500)
//make_closed_cylinder(101,5,300,30,1,-1,0x00ffff)
//---------------------------------


//  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
main:
X_MAKE2D ; DRAWSPRITE 1,0,0
X_MAKE3D 1,1024,35

X_CAMERA cam_d*COS(cam_phi)*COS(cam_theta),cam_d*SIN(cam_theta),cam_d*SIN(cam_phi)*COS(cam_theta), cam_px,cam_py,cam_pz
X_AMBIENT_LT 0,0x66bb66
X_SPOT_LT 1,0xccffff,4,2,1,  0,0,0,360

X_DRAWAXES cam_px, cam_py,cam_pz //0,0,0
GOSUB draw_all
SHOWSCREEN
HIBERNATE

//arrows -> move the camera, theta and phi.
//keypad -> 5 = recenter all, else move model's x,y,z.
// 1,4,7 <=> x,y,z and East<=> increase, West <=> decrease.
//Axes: RGB <=> xyz. Easy!
IF KEY(74) THEN INC cam_d,2
IF KEY(78) THEN DEC cam_d,2
setminmax(cam_d, 2, 300)
IF KEY(203) THEN INC cam_phi,2
IF KEY(205) THEN DEC cam_phi,2

IF KEY(200) THEN INC cam_theta,2
IF KEY(208) THEN DEC cam_theta,2
setminmax(cam_theta, -84,84)

IF KEY(79) THEN INC model_px,5 //kp1
IF KEY(81) THEN DEC model_px,5 //3
IF KEY(75) THEN INC model_py,5 //4
IF KEY(77) THEN DEC model_py,5 //6
IF KEY(71) THEN INC model_pz,5 //7
IF KEY(73) THEN DEC model_pz,5 //9
IF KEY(76) // kp "5" = "help, I'm lost"
cam_px=0 ; cam_py=0 ; cam_pz=0 //unused, always 0, weird movements otherwise.
model_px=0 ; model_py=0 ; model_pz=0
ENDIF
IF KEY(48) THEN GOSUB make_bg
//note: the inc/dec should follow the zoom values,as an option.

GOTO main
//   //////////////////////////////////////////////////////////



fn.gbas
Code (glbasic) Select
// --------------------------------- //
// Project: CADpipes_A
// Start: Saturday, November 08, 2014
// IDE Version: 10.283




//*****************************
// obj  1+ --> pipes          *
// obj 20+ --> shoulders      *
//*****************************

FUNCTION make_pipe_A: obnum%, r, l1,l2,col//straight pipe
//LOCAL rseg%=120,
//LOCAL r= 0.33, l1=-2.0, l2=2.0
STATIC ka, kb
X_OBJSTART obnum//1
FOR i=0 TO rseg-1
ka=360*i/rseg ; kb=360*(i+1)/rseg
X_OBJADDVERTEX r*COS(ka),r*SIN(ka),l1, 0,0,col
X_OBJADDVERTEX r*COS(ka),r*SIN(ka),l2, 0,0,col

X_OBJADDVERTEX r*COS(kb),r*SIN(kb),l1, 0,0,col
X_OBJADDVERTEX r*COS(kb),r*SIN(kb),l2, 0,0,col
X_OBJNEWGROUP
NEXT

X_OBJEND
ENDFUNCTION

FUNCTION make_shoulder_A: obnum%,r,sh_seg%,sh_an,sh_r,col  //rounded corner
// works like a deformer. Here the pipe segments' Nb are always rseg!
// bow's length <- shoulder's r and angle. easy.
STATIC ka, kb, ka2,kb2, x1,y1, x2,y2, x3,y3,z3, x4,y4,z4, x5,y5,z5, x6,y6,z6
X_OBJSTART obnum
FOR i=0 TO rseg-1
ka=360*i/rseg ; kb=360*(i+1)/rseg
x1=r*COS(ka)+sh_r ; y1=r*SIN(ka)
x2=r*COS(kb)+sh_r ; y2=r*SIN(kb)

FOR j=0 TO sh_seg-1
ka2=sh_an*j/sh_seg ; kb2=sh_an*(j+1)/sh_seg
x3=x1*COS(ka2)
x5=x1*COS(kb2)
x4=x2*COS(ka2)
x6=x2*COS(kb2)
y3=y1 ; y5=y1 ; y4=y2 ; y6=y2

z3=x1*SIN(ka2)
z5=x1*SIN(kb2)
z4=x2*SIN(ka2)
z6=x2*SIN(kb2)

X_OBJADDVERTEX x3,y3,z3, 0,0,col
X_OBJADDVERTEX x5,y5,z5, 0,0,col
X_OBJADDVERTEX x4,y4,z4, 0,0,col
X_OBJADDVERTEX x6,y6,z6, 0,0,col
X_OBJNEWGROUP
NEXT ; NEXT

X_OBJEND
ENDFUNCTION //ENDSUB worked!


?IF 0 //not compiled, now unused:
// 2D is 200+
FUNCTION make_disc: obnum%, r,an,sectors,col%
STATIC ka, kb
X_OBJSTART obnum //200+
FOR i=0 TO sectors-1
ka=an*i/sectors ; kb=an*(i+1)/sectors
X_OBJADDVERTEX r*COS(ka),r*SIN(ka),0,  0,0, col
X_OBJADDVERTEX 0,0,0,  0,0, col
X_OBJADDVERTEX r*COS(kb),r*SIN(kb),0,  0,0, col
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION
FUNCTION make_closed_cylinder: obnum%, r,an,sectors,thickup,thickdown,col%
STATIC ka, kb
X_OBJSTART obnum //200+
FOR i=0 TO sectors-1
ka=an*i/sectors ; kb=an*(i+1)/sectors
X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickup,  0,0, col
X_OBJADDVERTEX 0,0,thickup,  0,0, col
X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickup,  0,0, col
X_OBJNEWGROUP//stripe mode only.
X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickdown,  0,0, col
X_OBJADDVERTEX 0,0,thickdown,  0,0, col
X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickdown,  0,0, col
X_OBJNEWGROUP//stripe mode only.

X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickup,  0,0, col
X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickup,  0,0, col
X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickdown,  0,0, col
X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickdown,  0,0, col
X_OBJNEWGROUP//(edge)
NEXT
X_OBJEND
ENDFUNCTION
?ENDIF //unused functions

FUNCTION setminmax: BYREF a, mi, ma
IF a<mi THEN a=mi
IF a>ma THEN a=ma
ENDFUNCTION


gosubb.gbas
Code (glbasic) Select
// --------------------------------- //
// Project: CADpipes_A
// Start: Saturday, November 08, 2014
// IDE Version: 10.283


SUB draw_all:
X_MOVEMENT -model_px, -model_py, -model_pz ; X_PUSHMATRIX
//top wave:----------------
FOR i=0 TO 2
X_MOVEMENT 40*i,0,0 ; X_PUSHMATRIX
GOSUB draw_S1
X_POPMATRIX
NEXT
//  (end segment)
X_MOVEMENT 100,0,0 ; X_ROTATION 180, 0,1,0
X_DRAWOBJ 24,0
X_MOVEMENT 0,0,0

//mid wave
X_MOVEMENT 0,0,30 ; X_PUSHMATRIX
GOSUB draw_S2
X_POPMATRIX

//bottom wave
X_MOVEMENT 0,0,60 ; X_PUSHMATRIX
GOSUB draw_S2
X_POPMATRIX

//montants hauts / Frame bar:

X_MOVEMENT -30,0,0 ; X_DRAWOBJ 3,0

X_POPMATRIX
ENDSUB

SUB draw_S1:
X_MOVEMENT -20,0,0 ; X_ROTATION 180, 0,1,0
X_DRAWOBJ 24,0
X_MOVEMENT 0,0,2 ; X_DRAWOBJ 24,0

X_MOVEMENT 10,0,1 ; X_DRAWOBJ 1,0
X_MOVEMENT -10,0,1 ; X_DRAWOBJ 1,0
ENDSUB

SUB draw_S2:

FOR i%=1 TO 3
X_MOVEMENT i*40-40,0,0
X_DRAWOBJ 24,0
X_MOVEMENT i*40-50,0,-1 ; X_DRAWOBJ 1,0
X_MOVEMENT i*40-30,0,-1 ; X_DRAWOBJ 1,0
NEXT
FOR i%=1 TO 2
X_MOVEMENT i*40-20,0,-2 ; X_ROTATION 180, 0,1,0
X_DRAWOBJ 24,0
NEXT

//2 end 90 elbows:
X_MOVEMENT -20,0,-2 ; X_ROTATION 90,0,1,0 ; X_DRAWOBJ 20,0
X_MOVEMENT 100,0,-2 ; X_ROTATION 180,0,1,0 ; X_DRAWOBJ 20,0
// 2 end straights:
X_MOVEMENT -25,0,-12 ; X_ROTATION 90,0,1,0 ; X_DRAWOBJ 2,0
X_MOVEMENT 105,0,-12 ; X_ROTATION 90,0,1,0 ; X_DRAWOBJ 2,0
ENDSUB


SUB make_bg:
GETSCREENSIZE scrx,scry
CREATESCREEN 1,1,scrx,scry ; USESCREEN 1
LOCAL c%
FOR i=0 TO scrx STEP (scrx/12.0)
IF RND(100)>33
c=0x010101*(55+RND(190))
ELSE
c=bOR(RND(0xffffff),ASL(0xff,8*RND(2))) //not dull, 1 chanel is full on.
ENDIF
DRAWRECT i,0, scrx,scry,c
NEXT

USESCREEN -1
ENDSUB


#9
==== EDIT =====
   Finally my obfuscator works -a long, difficult job. It keeps the GLb commands and translates the rest into confusing generic "values", in selectable styles. The media files are automatically copied and renamed with fancy-names which are re-used in the source files accordingly. It worked with my 2505-commands game project, spanned on 10 *.gbas files, and about 50 media files. {Get it on the android market: flip7. By the way the first version costs 1$ and any advice is welcome about monetizing the app in a better way}.
  Back to the obfuscator: the generated code is meaningless : functions, variables, media files, are meaningless, random, looking all similar and confusing. But the program still works like before.
  • Supported features : multi-files, all GLb commands, media copy + renaming, intact 0x..... numbers, mark some words as keep-unchanged, automatic comment removal, choose/make your own style for generated words. Preprocessor code still works.
  • Not supported so far : INLINE'd code.
       Drop me a message if you are interested. You can get the customizable source code for a small price. Licence  :rtfm:  use and modify freely, you only. Don't distribute or sell anything in any way without my agreement. Please contact me for any unspecified case.
#10
This example shows zooming in 2D with 2 fingers on android. Gernot's example must be changed for android: I get 16 detected mice permanently, but never more than 4 pointers. "Pinch" is about looking at fingers behaviour, and can control the 3D camera as well. Pointers location and number are shown on screen. Works on Archos tablet 10.1 G9. Have fun and tell us your story.
Code (glbasic) Select
// --------------------------------- //
// Project: pinch00
// Start: Tuesday, April 15, 2014
// IDE Version: 10.283
// SETCURRENTDIR("Media") // go to media files

SYSTEMPOINTER TRUE
CONSTANT rectNb%=33 // up to you
GLOBAL scrx%,scry%, zoom=1.0, cx,cy
GLOBAL sqx[],sqy[],sqw[],sqh[],sqcol%[]
GLOBAL mx%, my%,b1%,b2%
DIM sqx[rectNb+1] ; DIM sqy[rectNb+1] ; DIM sqw[rectNb+1] ; DIM sqh[rectNb+1] ; DIM sqcol[rectNb+1]
FOR i% =0 TO rectNb
sqx[i]=RND(900)*0.001 ; sqy[i]=RND(900)*0.001
sqw[i]=0.05 +0.001*RND(155) ; sqh[i]=0.05 +0.001*RND(155)
sqcol[i]=RGB(255/(1+RND(4)),255/(1+RND(4)),255/(1+RND(4)))
NEXT

GETSCREENSIZE scrx,scry ; cx=scrx*0.5 ; cy=scry*0.5

//********************
WHILE TRUE
GOSUB redraw
?IFDEF WIN32
GOSUB kees //windows only. No double glazing.
?ENDIF
GOSUB mousedetect
SHOWSCREEN
WEND
//********************

END

SUB redraw:
FOR i%=0 TO rectNb
DRAWRECT scrx*(0.5+(sqx[i]-0.5)*zoom),scry*(0.5+(sqy[i]-0.5)*zoom), _
scrx*zoom*sqw[i], scry*zoom*sqh[i],sqcol[i]
NEXT
ENDSUB

?IFDEF WIN32
SUB kees:
STATIC k$
k$=INKEY$()
SELECT k$
CASE "," // <<
zoom=zoom*0.99
CASE "." // >>
zoom=zoom*1.01
ENDSELECT
ENDSUB
?ENDIF

SUB mousedetect:
STATIC newmousecount%, zoomMem, mem //mouse distance
STATIC mouseAmount%
newmousecount=GETMOUSECOUNT() ; mouseAmount=0
//draw pointers
FOR i%=0 TO newmousecount-1
//0->15 on android, all the time.
      SETACTIVEMOUSE i
      MOUSESTATE mx, my, b1, b2
      IF (b1+b2)
      drawmouse(i) ; INC mouseAmount
      ENDIF
      PRINT newmousecount, 10,200
      // always =16 on android, Archos tablet G9 10.1
NEXT
//fingers' gym (best with 2 fingers...)
SELECT mouseAmount //how many fingers on screen?
//CASE 1 // glide
//
CASE 2 //zoom. Implement rotation here.
// could change camera position and FOV in 3D.

IF mem=0.0 //fresh fingers
mem=getdistance()
zoomMem=zoom //store the start values.
ELSE // pinch that spot, enjoy the magic
zoom=zoomMem*getdistance()/mem
ENDIF
//CASE 3 //special config. Usable.
//CASE 4 //Usable too. Wave a white flag.
DEFAULT
mem=0.0 // fingers off
ENDSELECT
ENDSUB

FUNCTION drawmouse: n%
STATIC p%
FOR i%=0 TO n
p=55+i+i+i
DRAWLINE mx-p,my-p,mx+p, my-p, 0xffff00
DRAWLINE mx-p,my+p,mx+p, my+p, 0xff99ff
DRAWLINE mx-p,my-p,mx-p, my+p, 0xff99ff
DRAWLINE mx+p,my-p,mx+p, my+p, 0xffff00
NEXT
ENDFUNCTION

FUNCTION getdistance:
STATIC mx1%,mx2%,my1%,my2%,bb%,bbb%,d
SETACTIVEMOUSE 0
MOUSESTATE mx1,my1,bb,bbb
SETACTIVEMOUSE 1
MOUSESTATE mx2,my2,bb,bbb
d=SQR((mx1-mx2)*(mx1-mx2) +(my1-my2)*(my1-my2))
PRINT "                       ", 30,30
PRINT d,30,30
RETURN d
ENDFUNCTION
#11
[-]  I'd like to set myself the background color of some portions of the code, for better readability.
[-]  The "find" (ctr-f) tool needs an option to search directly through all *.gbas files of the project, when you have many of them.
[-]  Sometimes it's useful to add a comment in the middle of a long line. How about implementing something like /-shortcomment-/ ?
#12
3D / 3D transparency
2013-Oct-30
Hi!
I need an X_ALPHAMODE, or an X_OBJADDVERVERTEX with RGBA colors. Any idea?
Not easy I guess. GL ES for android makes it even worse...

Code (glbasic) Select
// --------------------------------- //
// Project: test-3D-transparency
// Start: Wednesday, October 30, 2013
// IDE Version: 10.283


SETCURRENTDIR("Media") // go to media files

CONSTANT MK3D1%=1, MK3D2=256, MK3D3=80 // zfar down to 16 is still o.k. for this example!
LOADSPRITE "smallpicture.png",1
DRAWSPRITE 1, 3,3

X_OBJSTART 0
X_OBJADDVERTEX -1.0,-1.0,0.0,  0.0,1.0, 0xffffff //SW
X_OBJADDVERTEX -1.0, 1.0,0.0,  0.0,0.0, 0xffffff //NW
X_OBJADDVERTEX 1.0 ,-1.0,0.0,  1.0,1.0, 0xffffff //SE
X_OBJADDVERTEX 1.0 ,1.0 ,0.0,  1.0,0.0, 0xffffff //NE
// Note: is there no way to enter an alpha color?
// As soon as you use a color different from 0xffffff
// the ALPHAMODE stops working, stopping transparency.

// Problem: I must choose either vertex colors or transparency,
// but I need both.
X_OBJEND

X_MAKE3D MK3D1, MK3D2, MK3D3//1,256,80
X_CAMERA 0,0,3,  0,0,0
X_SETTEXTURE 1,-1
ALPHAMODE -0.33

FOR i%= -4 TO 0
X_MOVEMENT 0,0,i
X_DRAWOBJ 0,0
NEXT

SHOWSCREEN
MOUSEWAIT
END
#13
I'm glad it works. It saves a COS() and SIN() calculation. It's an emulation of 2 integrating op-amps in a loop producing a sin and a cos signal. The integration factor -frequency dependent- is not compensated yet. Before asking many questions please study the analog computer, or the theory of servos and feedback stability. It's a great tool to produce nice or unexpected movements. Wish you fun and creative experimenting. Please share your examples.
Code (glbasic) Select
// --------------------------------- //
// Project: sinosc1
// Start: Saturday, September 14, 2013
// IDE Version: 10.283
//Emulates the analog computer, with 2 integrators and a loop.

SETSCREEN 800,200,0
CONSTANT cx%=400, theta=0.115 //time constant
// signal 1 and signal 2: (initial state)
GLOBAL s1=0,s2=33, _s1,_s2
WHILE TRUE
integrate()
DRAWRECT cx+s1, 12, 20,60, RGB(255,155,0)
DRAWRECT cx+s2, 94, 20,60, RGB(0,255,255)
FOR i%=0 TO 800 STEP 40
DRAWLINE i,166, i,200,0xffffff
NEXT
SHOWSCREEN
WEND

FUNCTION integrate:
_s1=s1 ; _s2=s2
s2=s2-theta *_s1*0.8
s1=s1-theta *(-_s2)

IF s2>220 THEN s2=220+(s2-220)*0.92 // knee-clip the 1st op-amp.
IF s2<-220 THEN s2=-220+(s2+220)*0.92 //necessary but not too hard please.

ENDFUNCTION

Offtopic: here is an interesting test; imagine the blue and red bars are mounted at the edge of rotating disc. When you see the disc in motion, does it turn to the right or the left?
#14
Hi!
I managed to debug my android tablet (archos 10.1 g9) thanks to "ddms" command line on xubuntu linux. (dalvik debug monitor service. Should work in console on windows too, once you have adb.)
Bug: after 8 resizings using "USESCREEN 2" and POLYVECTOR those corresponding sprites disappear from the screen. It happens after about 20 times in the emulator, and never on windose. I'm surprised that only the sprites disappear. The rest drawn with POLYVECTOR keeps running o.k. I thought DRAWSPRITE was less consuming... Then the debugger repeats "glBindRenderbufferExt failed 8cdd". If you look at http://code.google.com/p/monkey-ext/source/browse/monkey/modules/opengl/gles20_src.txt?r=34f0e133a20e2fc86e0060b0f962c1c6aace282d you will see that 0x8cdd means
QuoteConst GL_FRAMEBUFFER_UNSUPPORTED
.
Thank you for any suggestion.

UPDATE:
   ddms seems to only work on linux.
hint for beginners: *) install adb etc... *) in a console type: "adb devices". (if you don't see the device it isn't installed yet.) *) "adb usb"  *)"ddms". *) then watch the debug window to see what the device or emulator does.
Linux newbies? get a "live cd" of xubuntu or lubuntu and burn the *.iso on a cd with "isoburn". Set the bios to boot on the cd before the hd. in 5 minutes it's up and running, without hd installation.

UPDATE / SOLVED.
I found that my resize routine calls a GENSPRITE() everytime. By repeating this, I end up busting the sprite memory, so the new sprites are empty and invisible. This is where it can be dangerous to develop on an oversized machine with plenty of ram: the problem doesn't show up. Then I find GENSPRITE() dangerous too. It's o.k. to load sprites at the beginning of a program, but if you use it regularly you should remember to de-allocate the previous sprites. Perhaps >> LOADSPRITE "",  old_sprite_num works? I haven't tried.
Finally I don't understand the error message. What's the relationship with busting the sprite (or ram?) memory ?
Finally I'd like to recommend the test of running the app in the emulator with small memory size, in order to spot this kind of problem: MEMORY LEAKS
#15
Here is an example of encapsulted functions inside a TYPE. Keep in mind they are supposed to be the external "public buttons" of your objects.
It works like that.
I didn't get the green "this" to work -both in GLb and C- but appearently "self" would be the right word. I will try it.
Code (glbasic) Select

// --------------------------------- //
// Project: encaps_function
// Start: Thursday, August 22, 2013
// IDE Version: 10.283 // just updated

// The green "this" remains a mystery to me,
// but the program works like that:
TYPE sq
size%=100;
dir%=1;
//dummy%=0
FUNCTION changesize: // a member function, "encapsulated".
INLINE //Now use the different C syntax:

if (dir>0)
{INC(size); //should be this.size?
if (size>222)
{size=200; dir=0;}
}
else
{DEC( size);
if (size<77)
{size=88 ; dir=2;}
}
// ENDIF // not in C.
ENDINLINE

ENDFUNCTION
FUNCTION draw:
INLINE
DRAWRECT( 33,33,size,size, 0xffbb99);
ENDINLINE
ENDFUNCTION
ENDTYPE

LOCAL s AS sq  //instanciation
WHILE TRUE
// call member functions of the object:
s.changesize()
s.draw()
// i.e. push the external buttons of
// the closed object.
SHOWSCREEN
WEND

// P.S. a typical example of such member functions are
// "accessors", used to get or set the encapsulated values
// of the object from the outside.
#16
Tutorials / mainloop()
2013-Jul-24
Hi!
Here is an attempt at running a "mainloop" for all objects at once, like in python. Interesting for gaming or GUI design. Objects of different types get created and deleted dynamically. It's also a solution to get an abstract class functionnality in GLb, without C++.
Have good fun!
Code (glbasic) Select
// --------------------------------- //
// Project: TYPE_1 (pure abstract classes in C++ failed)
// Start: Saturday, July 20, 2013
// IDE Version: 10.244


// --------------------------------- //
// Project: TYPE_2
// Start: Tuesday, July 16, 2013
// IDE Version: 10.244


// SETCURRENTDIR("Media") // go to media files
SETSCREEN 500,500,0
SYSTEMPOINTER FALSE
//LIMITFPS 30

GLOBAL oblist%[] AS ob // like a pure abstract class, an array of various objects.
//GLOBAL collist%[] ; DIMDATA collist%[],0xcc66ff,0x00bb55, 0x0055ff,0xcc7777, 0x777777
TYPE ob
shape$ ="sq" // is the TYPE of each object, in fact.
// used later in a "switch" to apply the correct drawing function,
// like a function member of each object in C++.
color% = 0x666666 //default color
val1=0 ; val2=0 ; val3=0 // generic, use varies depending on the type of object.
px ; py ; vx ; vy
// weapons% =0
intelligence% = 4 // (bonus included, haha)
dizziness% =1
bounces%=4 // max. bounces allowed, the deletion criterium.
ENDTYPE

start:
FOR bzzz% = 1 TO 440 ; new_ob() ; NEXT // create n objects
GLOBAL t0%, t% , stamp%
LOCAL ciao%
t0=GETTIMERALL() ; t=t0+2000

mainloop://____run_all_objects_at_once__________________._____________________
WHILE TRUE
FOREACH z IN oblist[]
ciao=animate(z)
IF ciao >0 THEN DELETE z // [death]
//DELETE must be inside a loop, otherwise you need to know
// the (int) position of object z inside the array oblist[]. How do you get that?
// Please post me the answer if you know it.
NEXT
PRINT LEN(oblist[]), 5,5
SHOWSCREEN
stamp=GETTIMERALL() // MUST be GLOBAL apparently, too tricky otherwise.
IF stamp >t
t=t+500+RND(700) //1789+RND(1984)
new_ob()  // [birth]
// DRAWRECT 10,10,222,222, RGB(255,255,0) // visualize creation time
ENDIF
WEND
//______________________________________________________._____________________


FUNCTION new_ob:
LOCAL z AS ob // new, inherits default values
// z.color = collist[RND(4)]
z.color = bOR(RND(0xffffff), ASL(0x000000f0,8*RND(2)))
// avoiding dark or unsaturated colors.

IF RND(1) // if shape is sq
z.px =250.0 ; z.py =250.0
z.vx =rnddr2() ; z.vy =rnddr2()
z.val1=6+RND(30) ; z.val2=6+RND(30)
// more t.b.c.
ELSE
z.px =250.0 ; z.py =250.0
z.vx =rnddr2() ; z.vy =rnddr2()
z.shape$="tri" ; z.val1=RND(84)-42
ENDIF
DIMPUSH oblist[], z
ENDFUNCTION
FUNCTION animate: z AS ob

INLINE
//moves, common, C-style:
z.px +=z.vx ; z.py+=z.vy;
if(z.px <50)
{z.vx =rnddr(); z.vy=rnddr2()  ; z.px=50;   z.bounces-=1 ; if (z.bounces <1) {return(7);}}
if(z.py <50)
{z.vy =rnddr(); z.vx=rnddr2()  ; z.py=50;   z.bounces-=1 ; if (z.bounces <1) {return(7);}}
if(z.px >450)
{z.vx = -rnddr(); z.vy=rnddr2(); z.px =450; z.bounces-=1 ; if (z.bounces <1) {return(7);}}
if(z.py >450)
{z.vy = -rnddr(); z.vx=rnddr2(); z.py=450;  z.bounces-=1 ; if (z.bounces <1) {return(7);}}

ENDINLINE

//switch to apply the right function:
IF z.shape$ = "sq" // "according to the type" like an abstract class.
DRAWRECT z.px,z.py,z.val1,z.val2,z.color
ELSEIF z.shape$="tri"
STARTPOLY -1,1 //no texture, iMode=tri
POLYVECTOR z.px, z.py-z.val1,   0,0, z.color
POLYVECTOR z.px+10, z.py,       0,0, z.color
POLYVECTOR z.px-10, z.py,       0,0, z.color
ENDPOLY
ELSE
// another default type of object.
ENDIF // ...should be usable to make a custom GUI.

RETURN 0 // i.e. "don't delete this element"
ENDFUNCTION
FUNCTION rnddr:
RETURN (RND(3000)+5)/1000.0
ENDFUNCTION
FUNCTION rnddr2:
IF (RND(1)) ; RETURN rnddr()
ELSE
RETURN -rnddr()
ENDIF
ENDFUNCTION

#17
Hi! Here is a rough template to draw all sorts of stars, flowers, etc. Try, look, tweak, have fun!
Nightly EDIT:
drawthistle (outcommented) is an invitation to experiment. I'm surprised that 2 different functions for x and y still works. For non-integer multiples of beta, the thistle doesn't loop on itself in the worse case -nothing terrible.
Sorry, I haven't tried MEM2SPRITE yet, in the hope the plotting goes faster. Please let me know if anyone gets good results.
Code (glbasic) Select
// --------------------------------- //
// Project: cog_A1
// Start: Tuesday, May 07, 2013
// IDE Version: 10.244

// SETCURRENTDIR("Media") // go to media files

SYSTEMPOINTER TRUE
GLOBAL scrx%=666, scry%=666 //your custom size please.
// For PC use menu;project;options;
GETSCREENSIZE scrx, scry
SETSCREEN scrx,scry,0
CREATESCREEN 1,1,scrx,scry
// the drawing surface.
GLOBAL cnt%

//****************************************************
WHILE TRUE
//press F12 to view long lines of code.
LOCAL alpha=(RND(1999)/1000.0 -1.0)+0.00000003
// additive when >0
// interpolated when <0, ='mix' ='cross-fade'
// ...in my opinion.
LOCAL color%=RGB(128*RND(2)-1,128*RND(2)-1,128*RND(2)-1)
LOCAL smoothedge = 2.0 +13*RND(3)
LOCAL thickness=14*RND(3) // (0 means filled shape)

drawstars_a(RND(scrx), RND(scry), 4+RND(300), thickness, color, alpha, smoothedge,5+RND(7), 0.01+RND(44)*0.01)

USESCREEN -1
ALPHAMODE -1
DRAWSPRITE 1,0,0
SHOWSCREEN
INC cnt,1
IF cnt >7
cnt=0
SEEDRND (GETTIMERALL()) //shuffle the cards.
ENDIF

//FOR more clarity:
DEBUG alpha ; DEBUG "\n"
// please activate the 'bug' icon
// SLEEP 2012 // additional time

// SLEEP 800 +RND(3333)
//SLEEP 787// Merry dream, liner!
WEND
//****************************************************


FUNCTION drawstars_a: cx,cy,r,thick,col%,a,smoo,freq%,amp
// adjust the params to make a cog, a flower, some rounded n-gons, a star...
// with some luck I even got an accurate David's star. (freq=6 I guess).
USESCREEN 1
IF smoo <0 THEN smoo =0
LOCAL halfsmoo =smoo*0.5
LOCAL th =thick*0.5
LOCAL ra  = (r+halfsmoo+th)
LOCAL ra2  = (r+halfsmoo+th)*(r+halfsmoo+th) //outermost
LOCAL rb2  = (r+th)*(r+th) //
LOCAL rc2  = (r-th)*(r-th) //
LOCAL rd2  = (r-th-halfsmoo)*(r-th-halfsmoo) //innermost
LOCAL rd  = (r-th-halfsmoo)

LOCAL d2,d1,x,y,beta,sinbeta,cosbeta
LOCAL r2 =r*r
LOCAL w_out =ra-(r+th) +0.000001//r2_ -r2
LOCAL w_in  =(r-th)-rd +0.000001

FOR xxx=0 TO scrx
FOR yyy=0 TO scry
x=xxx ; y=yyy

d2=(x-cx)*(x-cx) +(y-cy)*(y-cy) //*2.0

IF d2>0
d1=SQR(d2)
cosbeta=(x-cx)/d1
sinbeta=(y-cy)/d1

IF cosbeta >= 0
beta=ASIN(sinbeta) // +90 -> -90
ELSE
beta=180-ASIN(sinbeta)
ENDIF
// IF x=300 ; DEBUG beta ; DEBUG "   \n" ; ENDIF

// Draw star:
x=cx +((x-cx)*(1+amp*SIN(freq*beta)))
y=cy +((y-cy)*(1+amp*SIN(freq*beta))) // wavy lens effect
//or Draw thistle:
//x=cx +((x-cx)*(1+amp*0.5*(SIN(freq*beta)+SIN(freq*beta*2))))
//y=cy +((y-cy)*(1+amp*0.5*(SIN(freq*beta)+SIN(freq*beta*5.42167)+SIN(freq*beta*1.5))))

d2=(x-cx)*(x-cx) +(y-cy)*(y-cy) //again, after lens.
ENDIF


IF d2 <= r2 //internal
IF thick>0
IF d2 >= rc2
//plot it plain.
ALPHAMODE a
SETPIXEL xxx,yyy,col
ELSEIF d2 <=  rd2
// ignore it
ELSE
// interpolate, blend it.
ALPHAMODE (SQR(d2) -rd)*a/w_in
SETPIXEL xxx,yyy,col
ENDIF
ELSE // thick<=0, fill the shape.
ALPHAMODE a
SETPIXEL xxx,yyy,col
ENDIF
ELSE //external

IF d2 < rb2
//plot it plain.
ALPHAMODE a
SETPIXEL xxx,yyy,col
ELSEIF d2 >=  ra2
// ignore it
ELSE
// interpolate, blend it.
ALPHAMODE (ra -SQR(d2))*a/w_out
SETPIXEL xxx,yyy,col
ENDIF
ENDIF
NEXT
NEXT
ENDFUNCTION

// P.S. On the day the atom is a cube I will start believing in the square pixel.
#18
Read, use, enjoy! (I haven't tried your version yet, Gernot, you've been quicker than me.)
I'm surprised that the plotting with alpha seems to take much longer than the calculations and area scanning.
Any idea to improve that?

Code (glbasic) Select
// --------------------------------- //
// Project: ellipse1
// Start: Saturday, March 16, 2013
// IDE Version: 10.244


// SETCURRENTDIR("Media") // go to media files
// --------------------------------- //
// Project: circle1
// Start: Sunday, February 03, 2013
// IDE Version: 10.244


// SETCURRENTDIR("Media") // go to media files
GLOBAL scrx%=666, scry%=666 //your custom size.
// For PC use menu;project;options;
GETSCREENSIZE scrx, scry
SETSCREEN scrx,scry,0    // Size matters.
CREATESCREEN 1,1,scrx,scry
// the drawing surface.
GLOBAL cnt%
CONSTANT framing=0.12 // i.e. 12%
//****************************************************
WHILE TRUE
//press F12 to view long lines of code.
LOCAL alpha=(RND(1999)/1000.0 -1.0)+0.00000003
// additive when >0
// interpolated when <0, ='mix' ='cross-fade'
// ...in my opinion.
LOCAL color%=RGB(128*RND(2)-1,128*RND(2)-1,128*RND(2)-1)
LOCAL smoothedge = 2.2 +13*RND(3)
LOCAL thickness=3*RND(9) // (0 means filled ellipse, in 2nd Fn).
// USESCREEN 1

//define the x,y of the 2 centers:
GLOBAL c1x%=scrx*framing+RND(scrx*(1-framing-framing))
GLOBAL c2x%=scrx*framing+RND(scrx*(1-framing-framing))
GLOBAL c1y%=scry*framing+RND(scry*(1-framing-framing))
GLOBAL c2y%=scry*framing+RND(scry*(1-framing-framing))
GLOBAL rr_=SQR((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y))*(1.03+RND(800)*0.001)
// rr_ is the length of the string stretched between the 2 centers.
// As you draw, keep the string tentioned with the pen.
// Try at home with 2 pins on a piece of cardboard.

IF TRUE //RND(1) >0
// Choose which Fn:
// drawellipse1(c1x,c1y,c2x,c2y,SQR((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y))*(1.03+RND(800)*0.001),color, alpha)//, smoothedge)
drawellipse2(c1x,c1y,c2x,c2y,rr_, thickness,color, alpha, smoothedge)
ENDIF

//USEASBMP // optional
USESCREEN -1
ALPHAMODE -1
DRAWSPRITE 1,0,0
SHOWSCREEN
INC cnt,1
IF cnt >4
cnt=0
SEEDRND (GETTIMERALL()) //shuffle the cards.
ENDIF

//FOR more clarity:
//DEBUG alpha ; DEBUG "\n"
// please activate the 'bug' icon
// SLEEP 2012 // additional time

SLEEP 999
WEND
//****************************************************



// On the day the atom is a cube I will believe in the square pixel.


//__________________________________________________________________________________

FUNCTION drawellipse1:c1x%,c1y%,c2x%,c2y%,r%,col%,a //raw, filled shape, fast Fn no smoothing.

LOCAL r2% = r*r //?
LOCAL bx1%,bx2%,by1%,by2%
IF r <SQR((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y)) THEN RETURN 0
//impossible to draw, string is too short.
USESCREEN 1

IF c1x >=c2x
bx2 = c2x +r //(approx.)
bx1 = c1x -r
ELSE
bx2 = c1x +r
bx1 = c2x -r
ENDIF
IF c1y >=c2y
by2 = c2y +r
by1 = c1y -r
ELSE
by2 = c1y +r
by1 = c2y -r
ENDIF
ALPHAMODE a
FOR x%=bx1 TO bx2
FOR y%=by1 TO by2

IF SQR((x-c1x)*(x-c1x) +(y-c1y)*(y-c1y)) +SQR((x-c2x)*(x-c2x) +(y-c2y)*(y-c2y)) <= r THEN SETPIXEL x,y,col
NEXT
NEXT
RETURN 1
ENDFUNCTION


FUNCTION drawellipse2:c1x%,c1y%,c2x%,c2y%,r,thick,col%,a,smoo //raw shape

IF r <SQR((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y)) THEN RETURN 0
//impossible to draw, string is too short.

IF smoo <0 THEN smoo =0
smoo=smoo*1.8 // approx.correction
LOCAL halfsmoo =smoo*0.5
LOCAL th =thick*0.5
LOCAL smoooo =smoo+smoo
LOCAL rs1 =r+smoooo
LOCAL ra  = (r+halfsmoo+th)
LOCAL rb  = (r+th) //
LOCAL rc  = (r-th) //
LOCAL rd  = (r-th-halfsmoo)

LOCAL d,d2
LOCAL r2 =r*r
LOCAL w_out =ra-(r+th) +0.000001//r2_ -r2
LOCAL w_in  =(r-th)-rd +0.000001
LOCAL w_out_plain =rs1-(r) +0.000001
LOCAL bx1%,by1%,bx2%,by2%
USESCREEN 1


IF c1x >=c2x
bx2 = c2x +r +th +smoooo //(approx.)
bx1 = c1x -r -th -smoooo
ELSE
bx2 = c1x +r +th+smoooo
bx1 = c2x -r -th-smoooo
ENDIF
IF c1y >=c2y
by2 = c2y +r +th+smoooo//(approx.)
by1 = c1y -r -th-smoooo
ELSE
by2 = c1y +r +th+smoooo
by1 = c2y -r -th-smoooo
ENDIF

FOR x%=bx1 TO bx2
FOR y%=by1 TO by2
//FOR x%=0 TO scrx
//FOR y%=0 TO scry
LOCAL d=SQR((x-c1x)*(x-c1x) +(y-c1y)*(y-c1y)) +SQR((x-c2x)*(x-c2x) +(y-c2y)*(y-c2y))
IF thick=0 // elliptic disc
IF d <= r
ALPHAMODE a
SETPIXEL x,y,col //print it plain
ELSEIF d <= rs1 // then interpolate the alpha.
ALPHAMODE (rs1-d)*a/smoooo
SETPIXEL x,y,col

ENDIF
ELSE // outlined ellipse
IF d <= r //internal

IF d >= rc
//plot it plain.
ALPHAMODE a
SETPIXEL x,y,col
ELSEIF d <=  rd
// ignore it
ELSE
// interpolate, blend it.
ALPHAMODE (d -rd)*a/w_in
SETPIXEL x,y,col
ENDIF
ELSE //external

IF d < rb
//plot it plain.
ALPHAMODE a
SETPIXEL x,y,col
ELSEIF d >=  ra
// ignore it
ELSE
// interpolate, blend it.
ALPHAMODE (ra -d)*a/w_out
SETPIXEL x,y,col
ENDIF
ENDIF
ENDIF

NEXT
NEXT
RETURN 1 // Smooth operation hopefully
ENDFUNCTION

// P.S. On the day the atom is a cube I will believe in the square pixel.
#19

Hi everyone!
This program will nicely dither your images, for mobile apps. Enjoy!
It works in the free demo version of pure basic, a nice IDE though not suited for mobile devices.
Please read and season to taste.

Code (glbasic) Select
; Dither to RGB565 by Artist F.P.Brixey
;Please note: source file must be 32bit PNG with alpha.
;No alpha chanel produces a black image.
;If so, please process your source image:
;GIMP->Layer->transparency->add alpha chanel

InitSprite() : InitKeyboard()
Procedure.c rand_()
    ;write here your favorite hand-crafted chaos generator
  a.c= Random(1)
  a= Random(787) ; (let's shuffle!)
  a=(Random(9955) & $00ff)
  ProcedureReturn a ; type is char, unsigned byte please.
EndProcedure

Procedure.c from8to6(n.c) ; c is char, unsigned byte.
  ; We want to chop and dither the 2 LSB
  ;ProcedureReturn (n & $00fc) ; for special effects?
  n2.c= n & ($00ff-$0003)
  If n2 <$00fc And n & $0003 > rand_() & $0003
    n2=n2+$0004
  EndIf
  ProcedureReturn n2
EndProcedure

Procedure.c from8to5(n.c)
  ; We want to chop and dither the 3 LSB
  ; You get the traditional careless banding by adding here:
  ;ProcedureReturn (n & $00f8) ; for special effects?
  n2.c= n & ($00ff-$0007)
  If n2 <$00f8 And n & $0007 > rand_() & $0007
    n2=n2+$0008
  EndIf
  ProcedureReturn n2
EndProcedure

Procedure show(ima)
scrnum=OpenScreen(1024,768,32,"")
StartDrawing(ScreenOutput())
DrawAlphaImage(ImageID(ima),0,0)
;Box(20,20,40,20,RGB(122,122,255))
StopDrawing()
FlipBuffers()
Repeat
  Delay(80) : ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen() ; was a quick check
EndProcedure

sourcename$=OpenFileRequester("Open a source image (PNG format)","","*.*", 0)
UsePNGImageDecoder()
imnum_src=LoadImage(#PB_Any,sourcename$)
; BMP is default (leave the last argument empty). for other formats, use
;UseJPEGImageDecoder() UseJPEG2000ImageDecoder() UsePNGImageDecoder()
;UseTIFFImageDecoder() UseTGAImageDecoder()

imW=ImageWidth(imnum_src)
imH=ImageHeight(imnum_src)
If imnum_src =0 : MessageRequester ("Problem","Image is not loaded.") : End
EndIf

;show(imnum_src) ; Press escape
imnum_target = CreateImage(#PB_Any,imW,imH,32)

For j=0 To imH-1
  For i=0 To imW-1
    StartDrawing(ImageOutput(imnum_src))
    DrawingMode(#PB_2DDrawing_AllChannels)
    Rp=Red(Point(i,j))
    Gp=Green(Point(i,j))
    Bp=Blue(Point(i,j))
    Ap=Alpha(Point(i,j))
    ; alpha remains unchanged. Up to you.
    StopDrawing()
   
    rr=from8to5(Rp)
    gg=from8to6(Gp)
    bb=from8to5(Bp)
   
    StartDrawing(ImageOutput(imnum_target))
    DrawingMode(#PB_2DDrawing_AllChannels)   
    Plot(i,j,RGBA(rr,gg,bb,Ap)) ; with undithered alpha.
    StopDrawing()
  Next
Next


target$=sourcename$+"_dith565.png" ; change it freely.
; possibly: saveimagerequester(...

UsePNGImageEncoder()
s_i=SaveImage(imnum_target,target$, #PB_ImagePlugin_PNG,0,32) ;
    ;file format is still 32 bits RGBA.

If s_i <>0
  i=MessageRequester("Right", "Image was saved o.k.",#PB_MessageRequester_Ok )
Else
  i=MessageRequester("Sorry", "Image is not saved.",#PB_MessageRequester_Ok )
  End
EndIf

;show(imnum_target) ;now check the result. Reclaim your freedom by pressing 'escape'.
End

#20
Hope it works o.k. for you too like this.

//1) clean project, "trash" icon.
//2) remove all types of icons IN project folder.
//3) IF you want the white frame, put there an "icon.png"
//   IF you don't want it put there the same image,
//   with name "androidicon.png"
//   The image must be PNG format, 72x72.
//   [PNG is great FOR transparency AND other things]
//4) Rebuild FOR android, AND voila.

If trouble or doubt, try building the project twice.