|
Post by bigbass on Nov 13, 2013 16:28:03 GMT 1
Hey vovchik These math based demos are needed to demonstrate visually some laws .Students could have a feature to change the variables to visualize the effects It would be easy for a math teacher to first show the effects than explain the math involved I cant put my finger on it yet but these (math based) examples could be used as a teaching aid in schools! I can say from my personal experience I only understood complex math clearly when I was able to see how it could be applied to something in the real world for me the real world was studying electronics in electronics you can see how the math has a direct effect I would say about 80% of electronics is math based looking at nature you can see math in its purest form listening to music you can hear math some how leads to being enjoyable to our senses (I like to play the guitar too ) I remember well being able to input information in a formula and get the correct results and still not understand how that information could some how be useful to me when I finally saw something visually it instantly made sense Joe
|
|
|
Post by vovchik on Nov 13, 2013 23:10:35 GMT 1
Dear Joe, I am with you on this one, too. I also tend to "get it" once I see something abstract visualized. And animation is usually better than just plotting a function to make a point. I'll give this some serious thought.... With kind regards, vovchik
|
|
|
Post by alexfish on Nov 14, 2013 0:21:38 GMT 1
Hi @ Vovchik
have done a variation of Newton's Ball using goo canvas table to fake a grid , rather than use the Grid directly , animation seem to be smoother since no need to force a redraw of the grid
BR Alex
' ***************************************************** ' PROGRAM: newton_ball_gfx_2.bac ' PURPOSE: demo of bouncing ball (gravity) ' AUTHOR: vovchik (Puppy Linux forum) ' NOTES: ported example from some source ' DEPENDS: gcc, bacon, Alex's libgfx ' PLATFORM: Puppy Linux (actually, any *nix) ' Modded to use Table instead of grid ' DATE: 05-10-2013 ' *****************************************************
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac"
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
CONST gtk$ = GFXLIB("gtk") CONST goo$ = GFXLIB("goo") CONST rsvg$ = "librsvg-2.so.2" CONST version$ = "v.0.1a" SEED NOW DECLARE c, counter TYPE long int DECLARE canvas_w, canvas_h TYPE double DECLARE x, y, r, x_velocity, y_velocity, y_acceleration TYPE double canvas_w = 400 canvas_h = 400 counter = 0 x = 20 y = 200 r = 32 y_velocity = -1.0 x_velocity = 1.10 y_acceleration = .0098 ' define our graphic element as svg (circles and icon) ball$ = CONCAT$("<svg width='64' height='64' opacity='0.85'>" \ " <radialGradient fx='5%' fy='5%' id='rg' r='65%'>" \ " <stop offset='0%' stop-color='ivory'/>" \ " <stop offset='100%' stop-color='lime'/>" \ " </radialGradient>" \ " <circle cx='32' cy='32' r='30' stroke-width='2' " \ " stroke='#6a6a6a' fill='url(#rg)'/>" \ "</svg>") ' write out icon svg to disk for subsequent loading as taskbar/WM icon OPEN "/tmp/newton.svg" FOR WRITING AS svg WRITELN ball$ TO svg CLOSE FILE svg
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' IMPORTS ' ***********************
' gtk IMPORT "gtk_window_set_icon_from_file(long,char*,void*)" FROM gtk$ TYPE int IMPORT "gtk_widget_get_toplevel(long)" FROM gtk$ TYPE long ' rsvg IMPORT "rsvg_handle_close(long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_handle_get_pixbuf(long)" FROM rsvg$ TYPE long IMPORT "rsvg_handle_new()" FROM rsvg$ TYPE long IMPORT "rsvg_handle_write(long,char*,long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_init()" FROM rsvg$ TYPE void IMPORT "rsvg_term()" FROM rsvg$ TYPE void ' goo IMPORT "goo_canvas_grid_new(long,double,double,double,double,double,double,double,double,...)" FROM goo$ TYPE long IMPORT "goo_canvas_item_set_child_properties(long,long,...)" FROM goo$ TYPE void ' *********************** ' IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ FUNCTION SVG_BUFF(STRING new$) ' ------------------ ' create pixbuf from inline svg string LOCAL mysvg, mypixbuf rsvg_init() mysvg = rsvg_handle_new() svi = rsvg_handle_write(mysvg, new$, LEN(new$), 0) svi = rsvg_handle_close(mysvg, 0) mypixbuf = rsvg_handle_get_pixbuf(mysvg) rsvg_term() G_UNREF(mysvg) RETURN mypixbuf END FUNCTION
' ------------------ SUB SET_WINICON(long widget, STRING filename$) ' ------------------ ' make icon for Wm window and taskbar LOCAL x TYPE int x = gtk_window_set_icon_from_file(gtk_widget_get_toplevel(widget), filename$, NULL) END SUB
' ------------------ SUB QUIT_PROG() ' ------------------ QUIT END SUB
' ------------------ SUB CLEAR_DRAWING() ' ------------------ LOCAL i TYPE int PRINT "Clearing old drawing" 'PRINT "Drawing object" TEXT(labl, "<span color='firebrick'><b>Clearing canvas...</b></span>") SYNC IF counter > 0 THEN HIDE(c) END IF PRINT "Clearing completed" TEXT(labl, "<span color='firebrick'><b>Canvas cleared.</b></span>") SYNC SHOW(c) counter = 0 END SUB
' ------------------ SUB DRAW_BALL() ' ------------------ CLEAR_DRAWING() x = 20 y = 100 y_velocity = -1.0 x_velocity = 1.10 y_acceleration = .0098 TEXT(labl, "<span color='firebrick'><b>Drawing object.</b></span>") REPEAT ' change downward velocity according to acceleration y_velocity = y_velocity + y_acceleration ' calculate new position y = y + y_velocity x = x + x_velocity ' check for collisions IF y > (canvas_h - r) THEN y_velocity = -0.9 * y_velocity y = canvas_h - r x_velocity = x_velocity * 0.9 END IF IF x > (canvas_w - r) THEN x_velocity = -x_velocity x = canvas_w - r END IF IF x < 1 THEN x_velocity = -x_velocity x = 1 END IF ' move ball MOVE(c, x, y) SLEEP 4 'SHOW(grid) SYNC UNTIL (x_velocity * x_velocity) < 0.0001 END SUB
' ------------------ SUB DRAW_OBJECT() ' ------------------ ' Information for user CLEAR_DRAWING() PRINT "Drawing object" TEXT(labl, "<span color='firebrick'><b>Wait...</b></span>") SYNC DRAW_BALL() PRINT "Drawing object.." ' Indicate that drawing is ready PRINT "Done." TEXT(labl, "<span color='firebrick'><b>Done</b></span>") ENABLE(start_but) SYNC END SUB
' ------------------ SUB MK_GUI() ' ------------------ LOCAL i TYPE int ' Create GUI root = WINDOW("Newton Ball GFX - " & version$, canvas_w + 20, canvas_h + 55, 1.0) ' Get root of window win = GETROOT(root) SET_WINICON(root, "/tmp/newton.svg") fill_lin = LINEAR(0, 0, 0, canvas_h + 50) ' black at top ADD_HEX_STOP(fill_lin, 0.0, "#000000", 0.8) ADD_HEX_STOP(fill_lin, 0.2, "#1E1A16", 0.8) ' change colour of next one for tint ADD_HEX_STOP(fill_lin, 0.53, "#F00000", 0.8) ' black at bottom ADD_HEX_STOP(fill_lin, 0.9, "#1E1A16", 0.8) ADD_HEX_STOP(fill_lin, 0.95, "#000000", 0.8) bg = RECTANGLE(win, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, \ "line-width", 0.0, "fill_pattern", fill_lin, "stroke-color", "none", \ "antialias", 3, NULL) DRAW(win, bg, 0, 0, canvas_w + 20, canvas_h + 55) ' Make frame frame = FRAME(NULL) ATTACH (win, frame, 5, 5, canvas_w + 10, canvas_h + 10) PRINT "Frame created" ' Create canvas for drawing canvas = AREA(win, 10, 10, canvas_w, canvas_h) PRINT "Canvas created" ' Create buttons and callbacks start_but = BUTTON("Go") SETPROPERTY(start_but, "tooltip-text", " Draw object. ") ATTACH(win, start_but, 5, canvas_h + 20, 80, 30) CALLBACK (start_but, DRAW_OBJECT) DISABLE(start_but) labl = MARK("") SETPROPERTY(labl, "use-markup", TRUE) TEXT(labl, "<span color='firebrick'><b>GFX</b></span>") ATTACH(win, labl, ((canvas_w + 20)/2) - 200, canvas_h + 20, 400, 30) PRINT "Label created" quit_but = BUTTON("Quit") SETPROPERTY(quit_but, "tooltip-text", " Quit this program. ") ATTACH(win, quit_but, canvas_w - 65, canvas_h + 20, 80, 30) CALLBACK (quit_but, QUIT_PROG) PRINT "Buttons created" PRINT "Create grid"
table_1=G_TABLE(canvas,0,0) col$ = "#dadada" SETPROPERTY(table_1, "horz-grid-line-width", 5.0, "vert-grid-line-width", 5.0,"stroke-color",col$) sq_dim=48.0 FOR row = 0 TO 7 rect_item = RECTANGLE(table_1, 0,0, sq_dim, sq_dim-.3, "line-width", 0.0, 0) goo_canvas_item_set_child_properties(table_1,rect_item,"row",row,"column",0,NULL) NEXT FOR col = 1 TO 6 rect_item = RECTANGLE(table_1, 0,0, sq_dim, sq_dim-.3, "line-width", 0.0, 0) goo_canvas_item_set_child_properties(table_1,rect_item,"row",0,"column",col,NULL) NEXT
' create ball ball = SVG_BUFF(ball$) c = IMAGE(canvas, ball, (canvas_w/2) - (r/2), canvas_h - r, r, r) SETPROPERTY(c, "antialias", 3) PRINT "Ball created" ENABLE(start_but) SYNC END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by vovchik on Nov 14, 2013 9:50:08 GMT 1
Dear Alex,
Much better. I think the fake grid is the way to go. It would also make a useful generic function for the GFX lib.
Thanks...
With kind regards, vovchik
|
|
|
Post by vovchik on Dec 22, 2013 19:41:06 GMT 1
Dear all, Here is a animated demo of simple spirals. It is pretty smooth and will not kill your CPU. With kind regards, vovchik PS. Check out Alex's GFX documentation section for some nice, new skewing examples. Attachments:
spirals.tar.gz (1.04 KB)
|
|
|
Post by alexfish on Dec 23, 2013 5:05:01 GMT 1
Hi @ all As a round up before XMAS have put latest bacon beta and latest libgfx beta through some bench tests ;; Demo Bench test :: using latest BaCon Beta Test with Latest Bacon Beta >= 2.4.0.4 + latest libgfx beta dated DECEMBER 07 | 2013 did this one on a almighty powerful Intel Dualcore Atom 1.6Ghz :: What :: yes an intel atom + generic graphics If your system is up-to date then this bench test should smooth and milky + blitting without a glitch Have Fun Alex INCLUDE libgfx_import.bac
'@ Declares for User rotate on x y z axis DECLARE t, u, v, t2,u2,v2,vv , uu TYPE double '@ set an array for the cube it must have a dim of '7' DECLARE CUBE_1[7] TYPE long DECLARE CUBE_2[7] TYPE long ' TOG for Flag to enable and disable animation , since will be using TIMEOUT to automate the Animation TOG=0
'set up sub to rotate x y z axis SUB MY_ROTATE()
INCR t, 0.01 INCR u, 0.025 INCR v, 0.0132 DECR vv, 0.03 DECR uu, 0.03 END SUB DECLARE ss TYPE double
' ------------------ FUNCTION ANIMATE_CUBE() ' ------------------ IF TOG THEN
'@ SETCUBE(cube,x,y,size,x_axis,y_axis,z_axis,*) *= 0 for front of cube , 1 for back :: back= view inside the cube SETCUBE(CUBE_1, 315, 315, 140,140,140 ,t, u, v,0) '@ DRAWCUBE(cube) DRAWCUBE(CUBE_1) ' Rotate SETCUBE(CUBE_2, 315, 315, 80,80,80 ,t, uu, vv,0) DRAWCUBE(CUBE_2) MY_ROTATE()
END IF RETURN TRUE END FUNCTION
SUB SET_TOG() '@ using simple NOT will switch from 0 to 1 then 1 to 0 TOG = NOT(TOG) END SUB
'@ Window WINDOW("title",width,height,opacity) opacity range 0.1 to 1 root=WINDOW("GFX Cube bench test",600,600,1.0) BACKGROUND(root,"#BF00FF") ' get the root win = GETROOT(root) '@ get a cube with the array CUBE_1 , G_CUBE(parent,*cube[],colors in hex *6 required for each side,line-width) '@ make 2 cubes G_CUBE(win, CUBE_1, "#D18E48", "#C1976D", "#B65D67", "#8E7C81", "#AE6E40", "#7B4926", 0.0) G_CUBE(win, CUBE_2, "#D16E48", "#C1776D", "#B60D67", "#8E0C81", "#AE0E40", "#7B0926", 0.0) but=G_BUTTON(win,"animate",100,25) 'move the button into position MOVE(but,495,565)
G_BUTTON_SET(but,"button","color","#784E26") CALLBACK(but,SET_TOG) '@ give it a poke set time out to 10 TIMEOUT(10,ANIMATE_CUBE) DISPLAY
PiKy Attachments:
|
|
|
Post by alexfish on Jan 12, 2014 16:32:52 GMT 1
Hi vovchik & all
well after some disappoints which commenced in Nov last year , looks like have made some progress , so now working on finalising some bits in the libgfx extensions
here is a screen shot of a bit of progress , libgfx goo canvas with open gl ..
When :: hopefully beginning of FEB , depending on further testing after extensions are complete ..
BR Alex
|
|
|
Post by alexfish on Jan 15, 2014 8:19:59 GMT 1
Hi @ All
As to libgfx with gl and CPU over heads , just slightly more than standard IE it will not kill your CPU , so can compare with gfx cube demo
Screen shot of GFX Goo Canvas GL. with system monitor . this test was done on a Intel 1.6gh dual core Atom with generic graphics.
BR Alex
|
|
|
Post by alexfish on Jan 17, 2014 0:41:42 GMT 1
Hi @ Vovchik this is some of what trying to explain in the PM . + how things are progress with the extentions .. here I am attempting , well not as much attemtp but have succeed in getting a gl object directly into a cairo surface as goo , there are some wuirky results but the static draw + swap buffers work . but there is a downer at present . bear in mind some parts of the extentions + test was done only an hour ago So what are we seeing . the GFX window = GOO CANVAS + GOO CANVAS ITEMS G_BUTTONS , GTK WIDGETS BUTTONS, GL SOLID SQUARE THE WHITE ONE, GOO CANVAS SOLID SQUARE THE BLUE ONE This is the original test code + a picky at the end BR Alex the demo test code INCLUDE libgfx.bac INCLUDE libgfx_ext2.bac
INIT_GL
FUNCTION WINDOW_GFX_GL(STRING title$ ,int width ,int height,double opacity) LOCAL gtkwin , canvas gtkwin = gtk_window_new(GTK_WINDOW_TOPLEVEL) gtk_window_set_resizable(gtkwin, 0) gtk_window_set_position(gtkwin, GTK_WIN_POS_CENTER) gtk_widget_set_size_request(gtkwin,width,height) gtk_window_set_title(gtkwin, title$) gtk_window_set_opacity(gtkwin,(double)opacity) gtk_widget_show_all(gtkwin)
g_object_set_data (gtkwin, "win-state", "0") g_signal_connect_data(gtkwin, "delete-event", exit, 0, 0, 0)
canvas = goo_canvas_new()
glcfg = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB|GDK_GL_MODE_DOUBLE|GDK_GL_MODE_DEPTH) isset=gtk_widget_set_gl_capability(canvas, glcfg, 0, 1, GDK_GL_RGBA_TYPE) PRINT " isset : ",isset g_object_set_data (canvas, "type", "goo-canvas") g_object_set_data (canvas, "function", "window") g_object_set_data (canvas, "win-id", STR$(gtkwin)) g_signal_connect_data(gtkwin, "key-press-event", hug_key_press, 0, 0, 0) goo_canvas_set_bounds(canvas,0,0,(double)width,(double)height) goo_canvas_scroll_to(canvas,0,0) gtk_container_add(gtkwin,canvas) gtk_widget_show_all(canvas) window(STR$(canvas))=gtkwin
RETURN canvas END FUNCTION
SUB SQUARE_GL (NUMBER widget , STRING hug_color$, int hug_x, int hug_y, int hug_xsize, int hug_ysize, int hug_fill)
LOCAL pix, context, ebox, glcontext, gldraw
glcontext = gtk_widget_get_gl_context(widget) gldraw = gtk_widget_get_gl_window(widget) gdk_gl_drawable_gl_begin(gldraw, glcontext)
glMatrixMode(GL_PROJECTION) glLoadIdentity glOrtho(0,500, 500, 0, 0, 1) glMatrixMode(GL_MODELVIEW) glLoadIdentity glTranslatef(0.375, 0.375, 0)
IF LEN(hug_color$) = 7 THEN glColor3ub(DEC(MID$(hug_color$, 2, 2)), DEC(MID$(hug_color$, 4, 2)), DEC(MID$(hug_color$, 6, 2)) ) ELSE glColor3ub(0, 0, 0) END IF
IF NOT(hug_fill) THEN glBegin(GL_LINE_LOOP) glVertex2i(hug_x, hug_y) glVertex2i(hug_x+hug_xsize, hug_y) glVertex2i(hug_x+hug_xsize, hug_y+hug_ysize) glVertex2i(hug_x, hug_y+hug_ysize) glEnd ELSE glBegin(GL_POLYGON) glVertex2i(hug_x, hug_y) glVertex2i(hug_x+hug_xsize, hug_y) glVertex2i(hug_x+hug_xsize, hug_y+hug_ysize) glVertex2i(hug_x, hug_y+hug_ysize) glEnd END IF gdk_gl_drawable_swap_buffers(gldraw) gdk_gl_drawable_gl_end(gldraw) END SUB
SUB dosq SQUARE_GL(root,"#FFFFF0",300,300,50,50,1) '@ test show some original as in the go-obects do not show, this is been looked at '@ however passing over the area with mouse they appear again.. '@ add some more buttons to see is all works after the GL draw '@ a G_BUTON as in goo_canvas object g_but=G_BUTTON(win,"Test G_BUTTON",200,30) SQUARE(win,"blue",100,100,50,50,1) ' gtk button but2=BUTTON(" another button") ATTACH(win,but2,10,10,-1,-1) END SUB
root=WINDOW_GFX_GL("GFX Test gfx_extentions",500,500,1.0) BACKGROUND(root,"black") win=GETROOT(root)
but=BUTTON("test") ATTACH(win,but,20,200,100,50) CALLBACK(but,dosq) g_but=G_BUTTON(win,"Test G_BUTTON",200,30) MOVE(g_but,200,400) DISPLAY
Attachments:
|
|
|
Post by alexfish on Jan 20, 2014 5:02:45 GMT 1
Hi @ All LIBGFX GL update :: method of one window to provide GTK + CAIRO + OPEN GL Method to establish that all buffers remain intact complete + first stage testing of open gl 3d animation with cairo + gtk widgets overlay complete. Screenshot shows the main window with GL animation , + gtk button , cairo circle , cairo square , and cairo self defined widget as in G_BUTTON and a Sprite to boot , also at bottom is another canvas with a g_button. for those that may have tried this before will know that GL will strip the cairo masking esp note the the shape of the g_button , if mask is not preserved the the button will look square mask preservation now establish. If can ask a question Cairo is easier and simpler than GL ... esp from a 2d perspective..YES , funny thing is , Vovchik and I managed to get a 3d cube out of svg format + cairo format. also note from the screen shot , left shows the intial screen and right the animation sequences , + shows all is preserved. BR Alex Attachments:
|
|