|
Post by vovchik on Nov 3, 2015 16:14:16 GMT 1
Dear Alex, Yep, the square for the simple clock uses a 1 vbox x 1 hbox grid, which is drawn by glBegin(GL_LINES), so you are right about lines being used. Peter and I had been working on GRID at that time and I wanted to use it. With kind regards, vovchik
|
|
|
Post by alexfish on Nov 3, 2015 16:51:44 GMT 1
Hi Vovchik It's all good stuff.. I can also see the potential to get some 3d bits moving. although to clarify on term , Square or Rectangle drawing wise then perhaps could have SQUARE + CUBE_FACE thought would plot THIS Here anyway , I be very happy with the lib esp from a Raspberry PI aspect. BR Alex
|
|
|
Post by vovchik on Nov 3, 2015 17:07:33 GMT 1
Dear Alex, A little pseudo-3D here: INCLUDE canvas.bac DECLARE canvas_w, canvas_h TYPE int canvas_w = 400 canvas_h = 400
' ------------------ SUB BG_LINEAR(int w, int h, unsigned int r1, unsigned int g1, unsigned int b1, \ unsigned int r2, unsigned int g2, unsigned int b2, unsigned int max_col) ' ------------------ LOCAL yy TYPE int INK(r1, g1, b1, 210) CLS FOR yy = 0 TO h INK(r2, g2, b2, MOD(yy * (max_col * 1.0 / h * 1.0), max_col)) LINE(0, yy, w, yy) NEXT yy END SUB
' ------------------ SUB SHADOW_TEXT(STRING text$, int x, int y, unsigned int r1, unsigned int g1, \ unsigned int b1, unsigned int a1, unsigned int r2, unsigned int g2, \ unsigned int b2, unsigned int a2) ' ------------------ INK(r2, g2, b2, a2) TEXT(text$, x + 1, y + 1) INK(r1, g1, b1, a1) TEXT(text$, x, y) END SUB
' ------------------ SUB FAN() ' ------------------ ' little shaded fan-like thing LOCAL i, hue TYPE unsigned int SCALE(4) hue = 0 PENXY(200, 290) FOR i = 0 TO 100 INK(1, hue + 100, 1, 25) DRAW(15) DRAW(-15) TURNRIGHT(360.0/100.0) INCR hue NEXT i SCALE(1.4) END SUB
' ------------------ SUB Draw() ' ------------------ LOCAL rot1 = 0, rot2 = 0 TYPE static int BG_LINEAR(canvas_w/2, canvas_h, 184, 184, 184, 40, 40, 40, 255) PEN(2.1, 1) ROTATION(rot1) FAN() INK(255, 0, 0, 128) SHADOW_TEXT("Hello world!", 100, 100, 255, 0, 0, 128, 50, 50, 50, 200) ROTATION(rot2) INK(0, 255, 255, 128) SHADOW_TEXT("Hello world!", 100, 200, 0, 255, 255, 128, 50, 50, 50, 200) INCR rot1,2 DECR rot2,2 END SUB
WINDOW("Hello world!", canvas_w, canvas_h) LOADFONT("fonts/cursive.jhf") SCALE (1.4) PEN(3, TRUE) CALLBACK(30, Draw) WAITKEY
No cigar yet, but fun With kind regards, vovchik
|
|
|
Post by alexfish on Nov 3, 2015 23:32:04 GMT 1
Hi Vovchik may say No Cigar , yet looking at the libs there is potential. esp when looking at the ROTATE function . Noticed how U be setting up the drawing routines , not sure on U'r System , here on the Raspberry , there is a slight problem on window re-size think this could be helped with glutReshapeadding this to the waitkey ,' works much the same as the keyboardfunc, then point it to redraw or as in U'r case the drawing routines ... as in redraw . or perhaps & find method to keep the window one size, like the hug window BR Alex Added the import statement then called it directly after the create window , works , also this has vastly improved the window startup , No print through IE WINDOW("Test",800,600) glutReshapeFunc(Draw)
|
|
|
Post by alexfish on Nov 5, 2015 6:57:41 GMT 1
Hi Peter
Looking at the SQUARE and other functions size for size
here have tried the Square to have cx, cy and width, height, same scheme as the triangle as in base and height
SUB MY_SQUARE(cx, cy, xsize, ysize, fill)
CALL Draw_Prepare CALL Check_Scale(x-xrad, y-yrad, xrad, yrad) CALL Check_Rotation(x-xrad, y-yrad, xrad, yrad) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) ENDIF
glVertex2f(x-(xrad/2), y-(yrad/2)) glVertex2f(x+(xrad/2), y-(yrad/2)) glVertex2f(x+(xrad/2), y+(yrad/2)) glVertex2f(x-(xrad/2), y+(yrad/2))
glEnd
ENDSUB
demo_test
INCLUDE "canvas.bac"
WINDOW("Hello world",800,600) SYNC
INK(0,0,255,255)
MY_SQUARE(100,100, 100, 100, 1) ROTATION(45) INK(255,0,0,255)
MY_SQUARE(100,100, 100, 100, 0) INK(0,255,0,255)
MY_SQUARE(100,100, 50, 50, 1) ROTATION(15) INK(255,0,255,255)
MY_SQUARE(100,100, 100, 50, 0) INK(0,255,0,255) CIRCLE(100,100,50,50,0)
INK(255,255,255,255) CIRCLE(100,100,25,25,0)
INK(128,90,255,255) CIRCLE(100,100,25,25,0) ROTATION(45) TRIANGLE(100,100,100,100,0) SYNC
WAITKEY
BR Alex
|
|
|
Post by vovchik on Nov 5, 2015 11:12:28 GMT 1
Dear Alex, What do you get for placement with polygons? I have included an archive with two polygon tests, one with scaling and one without. With kind regards, vovchik Attachments:polygon1.bac.tar.gz (860 B)
|
|
|
Post by alexfish on Nov 5, 2015 16:54:02 GMT 1
Hi Vovchik Have had a look at the demo's + a quick recky of the polygon. Thoughts only at present . they are in PM. Some code using regular polygons , no fancy bits INCLUDE "canvas.bac" the code WINDOW("Polygons", 1200,1000) SYNC SCALE(1.5) INK(0, 0, 0, 255) GRID(0, 0, 1200, 1000, 100,100) PEN(4.5, 1) INK(255, 0, 0, 255)
POLYGON(601,500, 300, 3, FALSE) INK(0, 255, 0, 255) POLYGON(601,500, 300, 4, FALSE) INK(0, 0, 255, 255) POLYGON(601,500, 300, 6, FALSE) INK(0, 255, 255, 255) POLYGON(601,500, 300, 12, FALSE) PEN(1, 1) INK(255, 0, 0, 255) POLYGON(601,500, 300, 12, FALSE) POLYGON(601,500, 300, 60, FALSE) SYNC
WAITKEY() BR Alex A Zoomed View at a vertex . yet on regular poly this looks reasonable , yet will highlight the 1 pixel shift . re on the red poly's Attachments:
|
|
|
Post by vovchik on Nov 5, 2015 20:35:58 GMT 1
Dear Alex, Here is my pic of your prog. You are right, there seems to be some displacement. With kind regards, vovchik Attachments:
|
|
|
Post by vovchik on Nov 5, 2015 20:39:30 GMT 1
Dear all, On a slightly different subject (not displacement) , here is a canvas version of my scattershot prog, fixed up a bit to quit if a key is pressed between explosions and with faster (maybe) RGB transformations using bitwise shifts. With kind regards, vovchik
|
|
|
Post by alexfish on Nov 5, 2015 20:53:33 GMT 1
Thanks Vovchik.
thought some of what I was talking about + Bacon has no HYPOT(hypotenuse) function
So Users can try this : code is testing 3,4,5 Theory , as also in how to make 90 degrees etc etc including hypotenuse
FUNCTION distance(int x1,int y1,int x2,int y2) TYPE int
LOCAL dx=x1-x2,dy=y1-y2
RETURN SQR((dx*dx)+(dy*dy))
END FUNCTION
REM think right angle triangle & Hypotenuse
Rem looking for the hypotenuse of right angle triangle Base = 300 Height = 400 X = distance(0,0,300,400)
PRINT X
Can Also TRY float & double . see what happens when not multiple of 3 & 4
Can also be Written as a macro ;; DEF FN
DEF FN distance(x1,y1,x2,y2)=SQR(((x1-x2) * (x1-x2 ))+((y1-y2)*(y1-y2)))
|
|
|
Post by vovchik on Nov 5, 2015 22:05:30 GMT 1
Dear Alex, Yep, works fine and is very handy - if var X is declared as an double initially, then the macro version will deliver a double result. With kind regards, vovchik
|
|
|
Post by alexfish on Nov 6, 2015 0:31:12 GMT 1
Hi Vovchik made some progress just using the CIRCLE using step in the loop , may try it , see what U think but can see screen shot of MY_POLOGONS BR Alex Attachments:
|
|
|
Post by alexfish on Nov 7, 2015 3:08:19 GMT 1
Interlude::Interesting BP.Org ... Hereas can Qt. Sin(rad(x)) is approx 10% faster than Sin(x) Distance based on Pythag = 5% Slower than sin(rad), Computer wise. larger distances , a guess is as good as it gets .. and a homing pigeon needs not either.. amazing. worth a reading .. HereHappy days + BR Alex
|
|
|
Post by Pjot on Nov 8, 2015 17:11:17 GMT 1
Folks, For fun I ported the canvas to the GIF Draw backend. It mostly is meant to create animated screenshots of moving pictures. Some remarks: - The API is 100% compatible with the High Performance Canvas API. - Rotation applies to the visible part of the image only, and cannot merge parts. - For animations, use new keyword FRAMES to determine the amount of frames. Default 1 frame is created. - The GIF type does not handle alpha or alpha blending. The ported canvas can be found here. Example program: 'INCLUDE canvas.bac INCLUDE canvas-gd.bac
WINDOW("font_demo", 400, 400)
SCALE (1.5)
SUB Draw
LOCAL rot1 = 0, rot2 = 0 TYPE static int
INK(128,100,80,255) CLS
ROTATION(rot1) INK(255,128,255,128) TEXT("Hello world!", 100, 100)
ROTATION(rot2) INK(255,255,0,128) TEXT("BaCon is fun!", 100, 250)
INCR rot1, 2 DECR rot2, 2
ENDSUB
FRAMES(180) CALLBACK(20, Draw) WAITKEY
As you can see from this code, it's just a matter of changing 'canvas.bac' to 'canvas-gd.bac' and determine the amount of needed frames. The text in WINDOW is used to create the resulting GIF file. Clearly, a GIF image is not as perfect as OpenGL, but it can come handy on websites for example. Regards Peter
|
|
|
Post by Pjot on Nov 8, 2015 20:22:11 GMT 1
PS: Note that the GIF format does not support more than 255 colors per frame. Also, I found that different browser use different frame rates: Browser | Lowest value | canvas-gd value | Chrome | 0.02 | 20 | Firefox | 0.02 | 20 | Opera | 0.02 | 20 | Internet Explorer | 0.06 | 60 | Safari | 0.06 | 60 |
Each browser will round up to 0.10 (canvas-gd: 100) in case a value is used below the lowest limit. Regards Peter
|
|