|
Post by vovchik on Nov 8, 2015 20:41:32 GMT 1
Dear Peter,
Thanks for this. Although GIF doesn't know alpha gradations and has only indexed colors, there is transparency (defined as one of the 256). Do you know how this is done using canvas_gd? An easy solution might be setting the INK alpha to 0 for one of the colors.
With kind regards, vovchik
|
|
|
Post by Pjot on Nov 8, 2015 21:16:08 GMT 1
Hi vovchik, I saw your 'BG_LINEAR' function is based on the alpha value. Though GIF does not support alpha values, your technique still works by using RGB values. This is my modification in your pendulum program using yellow and red gradients (not exceeding 255 color definitions): ' ------------------ 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 y TYPE int FOR y = 0 TO h STEP 4 INK(r2, MOD(y * (max_col * 1.0 / h * 1.0), max_col), b2, 255) LINE(0, y, w, y) LINE(0, y+1, w, y+1) LINE(0, y+2, w, y+2) LINE(0, y+3, w, y+3) NEXT y END SUB
Regarding your question, we could do that of course. As you say, GIF supports only one color to be transparent. So each time a different color is set to be transparent, the one set previously will be back to normal. For now, the background color in each new frame is set to be transparent. Furthermore LibGD supports some kind of aliasing, but in a GIF it did not look so impressive... Please find below my adaptation to your pendulum. BR Peter
|
|
|
Post by vovchik on Nov 8, 2015 22:11:06 GMT 1
Dear Peter,
I am impressed that it works! Nicely done, although the regular canvas version is realtime and we have more color choice. Nevertheless, it is nice that we can do blending like that in GIFs and that it still looks good!
With kind regbards, vovchik
|
|
|
Post by Pjot on Nov 9, 2015 21:03:36 GMT 1
Thanks vovchik! I have adapted the canvas-gd context so it will set transparency for the color which has the alpha set to '0'. Also I looked into the aliasing option with LibGD, but there seems to be no difference in drawing with aliasing on or off in a GIF file. The option is there for PNG or other formats (though animation can only be done in GIF - the 'apng' format is not supported). See their manual for more information. So any other suggestion is welcome! BR Peter
|
|
|
Post by vovchik on Nov 12, 2015 15:35:20 GMT 1
Dear All, This is just a little demo of WOOSH text - a subroutine that generates this kind of text effect. Have fun. With kind regards, vovchik
|
|
|
Post by Pjot on Nov 12, 2015 20:55:50 GMT 1
Thanks vovchik, That's GROOVY indeed In the meantime, I have improved the GD version of the canvas further. Now it is possible to create an animation with transparent background. A little demo below. Regards Peter
|
|
|
Post by vovchik on Nov 16, 2015 18:37:59 GMT 1
Dear All, Here are a few more demos, much of the stuff based on code that was posted at forum.basicprogramming.org. Have fun... With kind regards, vovchik
|
|
|
Post by vovchik on Nov 17, 2015 22:25:13 GMT 1
|
|
|
Post by alexfish on Nov 18, 2015 10:34:55 GMT 1
Hi All here using Bacon Proto options to make a 3d Canvas with Perspective + lighting in the code have annotated possible bits which can be changed , on must also understand the relationship between the canvas dimensions to the Perspective . then , to how the Glut Geometry functions work. if that falls into place then possible on way to making your own Engine. hi-lighting these lines in the code BR Alex OPTION PARSE FALSE
PRAGMA INCLUDE <GL/glut.h>
REM also need to pastr -lGL -lGLU -lglut in the Bacongui gui Libraries or bacon cmd line ' -lGL -lGLU -lglut PRAGMA OPTIONS -lGL -lGLU -lglut
LOCAL xsize=600 , ysize=400
SUB init()
LOCAL mat_specular[] = { 1.0, 1.0, 1.0, 1.0 } TYPE float LOCAL mat_shininess[] = { 50.0 } TYPE float LOCAL light_position[] = { 1.0, 1.0, 0.0, 0.0 } TYPE float
glShadeModel (GL_SMOOTH)
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular) glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess) glLightfv(GL_LIGHT0, GL_POSITION, light_position)
glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_COLOR_MATERIAL)
ENDSUB
SUB display()
LOCAL viewport[4] TYPE int LOCAL aspect TYPE double glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_PROJECTION) glLoadIdentity()
glGetIntegerv(GL_VIEWPORT, viewport) aspect = (double)viewport[2] / (double)viewport[3] gluPerspective(50, aspect, 1, 100) /* void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); Parameters
fovy Specifies the field of view angle, in degrees, in the y direction.
aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
zNear Specifies the distance from the viewer to the near clipping plane (always positive).
zFar Specifies the distance from the viewer to the far clipping plane (always positive). */
/* 11.1 glutSolidSphere, glutWireSphere 11.2 glutSolidCube, glutWireCube 11.3 glutSolidCone, glutWireCone 11.4 glutSolidTorus, glutWireTorus 11.5 glutSolidDodecahedron, glutWireDodecahedron 11.6 glutSolidOctahedron, glutWireOctahedron 11.7 glutSolidTetrahedron, glutWireTetrahedron 11.8 glutSolidIcosahedron, glutWireIcosahedron 11.9 glutSolidTeapot, glutWireTeapot + wired or solid glutSolidTeapot(GLdouble size) void glutSolidIcosahedron(void); glutSolidTetrahedron(void) glutSolidOctahedron(void
void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings); void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings);
void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); void glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble radius, GLint slices, GLint stack */ REM mudula for translate function LOCAL size = 5 TYPE double REM mudula for glut geometry functions LOCAL bsize = 5 TYPE double
glMatrixMode(GL_MODELVIEW) glLoadIdentity()
REM move back a bit to bring bits into view REM can also transpose the x and y if want REM ----------------------------------------- glTranslatef( 0, 0, -35 )
REM ----------------------------------------- LOCAL angle = 0 TYPE static float
REM ----------------------------------------- glPushMatrix() glTranslatef(size,size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,0,0) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size,size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,0,0) glutSolidCube(bsize) glPopMatrix()
REM ------------------------------------------ glPushMatrix() glTranslatef(size*2,size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(0,255,0) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(0,size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(0,255,0) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size*2,size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(0,255,0) glutSolidCube(bsize) glPopMatrix()
REM ----------------------------------------- glPushMatrix() glTranslatef(size,0,0) glRotatef(angle, 0.1, 0.0, 0.0) glColor3ub(0,255,255) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size,0,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(0,255,255) glutSolidCube(bsize) glPopMatrix()
REM ----------------------------------------- glPushMatrix() glTranslatef(size*2,-size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(255,255,255) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(0,-size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(255,255,255) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size*2,-size,0) glRotatef(-angle, 0.1, 0.0, 0.0) glColor3ub(255,255,255) glutSolidCube(bsize) glPopMatrix()
REM ----------------------------------------- glPushMatrix() glTranslatef(size,-size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,255,0) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size,-size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,255,0) glutSolidCube(bsize) glPopMatrix()
glutSwapBuffers() INCR angle, 5.0f
ENDSUB
REM -------------------------------------------
SUB reshape(int w, int h) REM the callback glutReshapeFunc returns the size of the window REM make viewport same size as window to keep perspective glViewport(0, 0, w, h) ENDSUB
REM -------------------------------------------
SUB OnInitDisplay(int w, int h)
REM the callback glutDisplayFunc returns the size of the window REM make viewport same size as window glViewport(0, 0, w, h) REM clear the backing buffer to black glClearColor(0,0,0,1) REM swap the buffers , glu swap , not gl glutSwapBuffers()
ENDSUB
REM -------------------------------------------
SUB timer(int over)
glutPostRedisplay() glutTimerFunc(1, timer, 0) ENDSUB
REM -------------------------------------------
SUB Window(STRING title,int xsize , int ysize)
glutInitWindowSize(xsize,ysize) glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE) glutCreateWindow(title)
ENDSUB
REM Main -------------------------------------------
glutInit(&argc, argv); Window("Cubes",xsize,ysize) REM glutDisplayFunc(OnInitDisplay) glutDisplayFunc(display) glutReshapeFunc(reshape) glutTimerFunc(100, timer, 0) init()
glutMainLoop()
and a picture Attachments:
|
|
|
Post by vovchik on Nov 18, 2015 11:59:42 GMT 1
Dear Alex, Great and works - I had to add -lGL -lGLU -lglut to the command line and got a warning about a duplicated timer function, but it works! Very nice. With kind regards, vovchik
|
|
|
Post by alexfish on Nov 18, 2015 13:01:05 GMT 1
Thanks Vovchik
Have removed the duplicate timer function + updated cmd line
BR Alex
|
|
|
Post by vovchik on Nov 18, 2015 19:47:33 GMT 1
Dear All, If there were such a thing as "ADULTS ONLY" mathematics, this might qualify. Enjoy the animation. With kind regards, vovchik
|
|
|
Post by basica on Nov 18, 2015 23:07:13 GMT 1
All,
Thanks for all these great shows.
vovchik: I think you've posted what my intestines look like after too much "port".
alexfish: Fascinating "perspective and lighting". I had two errors but it finally compiled and ran with -
PRAGMA INCLUDE /usr/include/GL/glut.h (Full path) PRAGMA LDFLAGS GL GLU glutinsert code here
Regards, basica
|
|
|
Post by alexfish on Nov 19, 2015 14:45:57 GMT 1
Hi basica Yes interesting, + @ All , Just for fun Here is the same theme . but have to Imagine ? it be a robot doing acrobatics. BR Alex OPTION PARSE FALSE
PRAGMA INCLUDE <GL/glut.h>
REM in the Bacongui gui Libraries or bacon cmd line ' -l GL GLU glut
PRAGMA LDFLAGS GL GLU glut LOCAL xsize=600 , ysize=400
SUB init()
LOCAL mat_specular[] = { 1.0, 1.0, 1.0, 1.0 } TYPE float LOCAL mat_shininess[] = { 50.0 } TYPE float LOCAL light_position[] = { 1.0, 1.0, 1.0, 0.0 } TYPE float
glShadeModel (GL_SMOOTH)
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular) glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess) glLightfv(GL_LIGHT0, GL_POSITION, light_position)
glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_COLOR_MATERIAL)
ENDSUB LOCAL T# , U# , V# SUB display()
LOCAL viewport[4] TYPE int LOCAL aspect TYPE double
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_PROJECTION) glLoadIdentity()
glGetIntegerv(GL_VIEWPORT, viewport) aspect = (double)viewport[2] / (double)viewport[3] gluPerspective(50, aspect, 1, 600) /* void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); Parameters
fovy Specifies the field of view angle, in degrees, in the y direction.
aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
zNear Specifies the distance from the viewer to the near clipping plane (always positive).
zFar Specifies the distance from the viewer to the far clipping plane (always positive). */
/* 11.1 glutSolidSphere, glutWireSphere 11.2 glutSolidCube, glutWireCube 11.3 glutSolidCone, glutWireCone 11.4 glutSolidTorus, glutWireTorus 11.5 glutSolidDodecahedron, glutWireDodecahedron 11.6 glutSolidOctahedron, glutWireOctahedron 11.7 glutSolidTetrahedron, glutWireTetrahedron 11.8 glutSolidIcosahedron, glutWireIcosahedron 11.9 glutSolidTeapot, glutWireTeapot + wired or solid glutSolidTeapot(GLdouble size) void glutSolidIcosahedron(void); glutSolidTetrahedron(void) glutSolidOctahedron(void
void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings); void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings);
void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks); void glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);
void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); void glutWireSphere(GLdouble radius, GLint slices, GLint stack */ REM mudula for translate function LOCAL size = 12 TYPE double REM mudula for glut geometry functions LOCAL bsize = 12 TYPE double
glMatrixMode(GL_MODELVIEW) glLoadIdentity()
REM move back a bit to bring bits into view REM can also transpose the x and y if want REM ----------------------------------------- LOCAL angle = 0 TYPE static float INCR T# X# = SIN(RAD(T#))*35 V# = COS(RAD(T#))*15 glTranslatef( X#, V#, -300 ) glRotatef( angle , 1, 0, 1)
REM ----------------------------------------- glPushMatrix() glTranslatef(size,size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,0,0) glScaled(1,2,1) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size,size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,0,0) glScaled(1,2,1) glutSolidCube(bsize) glPopMatrix()
REM ------------------------------------------ glPushMatrix() glTranslatef(size*2,size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(0,255,0) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(0,size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(0,255,0) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size*2,size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(0,255,0) glutSolidCube(bsize) glPopMatrix()
REM ----------------------------------------- glPushMatrix() glTranslatef(size,0,0) glRotatef(angle, 0.1, 0.0, 0.0) glColor3ub(0,255,255) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size,0,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(0,255,255) glutSolidCube(bsize) glPopMatrix()
REM ----------------------------------------- glPushMatrix() glTranslatef(size*2,-size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(255,255,255) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(0,-size,0) glRotatef(-angle, 1.0, 0.0, 0.0) glColor3ub(255,255,255) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size*2,-size,0) glRotatef(-angle, 0.1, 0.0, 0.0) glColor3ub(255,255,255) glutSolidCube(bsize) glPopMatrix()
REM ----------------------------------------- glPushMatrix() glTranslatef(size,-size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,255,0) glScaled(1,5,1) glutSolidCube(bsize) glPopMatrix()
glPushMatrix() glTranslatef(-size,-size*2,0) glRotatef(angle, 1.0, 0.0, 0.0) glColor3ub(255,255,0) glScaled(1,-5,1) glutSolidCube(bsize) glPopMatrix()
glutSwapBuffers() INCR angle,1.5f
ENDSUB
REM -------------------------------------------
SUB reshape(int w, int h) REM the callback glutReshapeFunc returns the size of the window REM make viewport same size as window to keep perspective glViewport(0, 0, w, h) ENDSUB REM -------------------------------------------
REM -------------------------------------------
SUB OnInitDisplay(int w, int h)
REM the callback glutDisplayFunc returns the size of the window REM make viewport same size as window glViewport(0, 0, w, h) REM clear the backing buffer to black glClearColor(0,0,0,1) REM swap the buffers , glu swap , not gl glutSwapBuffers()
ENDSUB
REM -------------------------------------------
SUB timer(int over)
glutPostRedisplay() glutTimerFunc(1, timer, 0) ENDSUB
REM -------------------------------------------
SUB Window(STRING title,int xxsize , int yysize)
glutInitWindowSize(xxsize,yysize) glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE) glutCreateWindow(title)
ENDSUB
REM Main -------------------------------------------
glutInit(&argc, argv); Window("Cubes",xsize,ysize) REM glutDisplayFunc(OnInitDisplay) glutDisplayFunc(display) glutReshapeFunc(reshape) glutTimerFunc(100, timer, 0) init()
glutMainLoop()
Attachments:
|
|
|
Post by vovchik on Nov 19, 2015 15:01:05 GMT 1
Dear Alex, Fabulous - but the attached pic does not do justice to the real thing - which has great lighting and animation ... Thanks. I will learn something With kind regards, vovchik
|
|