|
Post by alexfish on Nov 25, 2015 15:13:56 GMT 1
Hi Vovchik
found a bug'sy in the demo code , looks like getting over the odds from 0 to 360 . should be 359
found that one when playing with some points
BR Alex
updated with some points..
INCLUDE canvas.bac
DECLARE canvas_w, canvas_h canvas_w = 800 canvas_h = 600
SUB MY_ALGO2 (x, y, start_deg, end_deg, xsize, ysize, sides, fill)
LOCAL i , cnt=0 LOCAL xt#, yt#,startX#,startY#,endX#,endY#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = start_deg TO end_deg STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) IF cnt = 0 THEN startX# = xt# startY# = yt# END IF endX# = xt# endY# = yt# INCR cnt NEXT glVertex2f(x+endX#,y+startY#) glEnd
ENDSUB
SUB MY_ALGO1 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
SUB MY_ALGO3 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
glBegin(GL_POINTS)
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
WINDOW("Circles & Segments et'all Kitchen Sink ", canvas_w, canvas_h)
SYNC INK(0, 0, 0, 230) CLS SYNC PEN(10,1)
FOR t = 1 TO 150 INK( RANDOM(255), RANDOM(255), RANDOM(255), 255) MY_ALGO3 (450, 250, t, t, 36, 0) NEXT
FOR t = 1 TO 50 INK( RANDOM(255), RANDOM(255), RANDOM(255),20) MY_ALGO3 (250, 250, t, t, 36, 0) NEXT
INK( 255,255,255,10)
FOR t = 1 TO 50
MY_ALGO3 (450, 250, t, t, 36, 0) NEXT INK( 255,255,255,25) MY_ALGO1(canvas_w/2, canvas_h/2, (canvas_w/2)-10, (canvas_h/2)-10, 4, 0)
SYNC
WAITKEY
Just had a thought if dealing with integers and circular bits , one could use the %
IE can make ref to the 360 like below
LET I = 359 % 360 PRINT I
LET I = 360 % 360 PRINT I
|
|
|
Post by vovchik on Nov 25, 2015 16:03:12 GMT 1
Dear Alex, Great looking kitchen sink. And you are right about "%". Works! With kind regards, vovchik
|
|
|
Post by alexfish on Nov 25, 2015 17:03:37 GMT 1
Hi Vovchik Some Radial Blur BR Alex INCLUDE canvas.bac
DECLARE canvas_w, canvas_h canvas_w = 800 canvas_h = 600
SUB MY_ALGO2 (x, y, start_deg, end_deg, xsize, ysize, sides, fill)
LOCAL i , cnt=0 LOCAL xt#, yt#,startX#,startY#,endX#,endY#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = start_deg TO end_deg STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) IF cnt = 0 THEN startX# = xt# startY# = yt# END IF endX# = xt# endY# = yt# INCR cnt NEXT glVertex2f(x+endX#,y+startY#) glEnd
ENDSUB
SUB MY_ALGO1 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
SUB MY_ALGO3 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
glBegin(GL_POINTS)
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
WINDOW("Circles & Segments et'all Kitchen Sink ", canvas_w, canvas_h)
SYNC INK(0, 0, 0, 180) CLS SYNC
INK(255, 0, 0, 255) MY_ALGO1 ((canvas_w/2)+10, 200, 60, 60, 60, 1) INK( 255,255,255,10) SCALE(1.5) PEN(4,1) FOR t = 1 TO 360
MY_ALGO3 (canvas_w/2, 180, t, t, 90, 0) NEXT FOR t = 1 TO 20
MY_ALGO3 (canvas_w/2, 180, t, t, 90, 0) NEXT
SYNC
WAITKEY Attachments:
|
|
|
Post by vovchik on Nov 25, 2015 17:45:42 GMT 1
Dear Alex,
Beautiful orb - I like it:) And economical coding, too.
With kind regards, vovchik
|
|
|
Post by Pjot on Nov 25, 2015 20:09:03 GMT 1
Hi Alex, Looks good! Not only your screenshot but also your code. Short and clear BR Peter
|
|
|
Post by alexfish on Nov 25, 2015 22:11:53 GMT 1
Thanks Peter These work well on the Raspberry pi , IE render speeds via glut. simple they are, yet can produce nice renders . @ ALL , this is the last in the series , need to find Robby Robot , as mentioned He be Lost in Space . Where ? Some where below .. code provided as last in the series , BR Alex INCLUDE canvas.bac
DECLARE canvas_w, canvas_h canvas_w = 800 canvas_h = 600
SUB MY_ALGO2 (x, y, start_deg, end_deg, xsize, ysize, sides, fill)
LOCAL i , cnt=0 LOCAL xt#, yt#,startX#,startY#,endX#,endY#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = start_deg TO end_deg STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) IF cnt = 0 THEN startX# = xt# startY# = yt# END IF endX# = xt# endY# = yt# INCR cnt NEXT glVertex2f(x+endX#,y+startY#) glEnd
ENDSUB
SUB MY_ALGO1 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
IF fill THEN glBegin(GL_POLYGON) ELSE glBegin(GL_LINE_LOOP) END IF
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
SUB MY_ALGO3 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
glBegin(GL_POINTS)
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
WINDOW("Circles & Segments et'all Kitchen Sink ", canvas_w, canvas_h)
SYNC INK(0, 5, 70, 255) CLS SYNC
INK(180,50, 255, 255) REM MY_ALGO1 ((canvas_w/2)+10, 200, 60, 60, 60, 0) INK( 255,255,255,10) SCALE(1.5) PEN(2,1)
FOR t = 1 TO 20
MY_ALGO3 (canvas_w/2, canvas_h/2, t, t, 90, 0) NEXT INK( 255/2,255/2,255,30) FOR t = 1 TO 400
MY_ALGO3 (canvas_w/2,(canvas_h/2)+5, t, t, 90, 0) NEXT FOR t = 1 TO 400
MY_ALGO3 (canvas_w/2,(canvas_h/2)-5, t, t, 90, 0) NEXT REM PEN(2,1) FOR t = 1 TO 400
MY_ALGO3 ((canvas_w/2)+5,(canvas_h/2), t, t, 90, 0) NEXT FOR t = 1 TO 400
MY_ALGO3 ((canvas_w/2)-5,(canvas_h/2), t, t, 90, 0) NEXT
FOR t = 1 TO canvas_w
MY_ALGO3 ((canvas_w/4),(canvas_h/4), t, t, 90, 0) NEXT
FOR t = 1 TO canvas_w
REM MY_ALGO3 ((canvas_w/4)*3,(canvas_h/4), t, t, 90, 0) NEXT FOR t = 1 TO canvas_w
MY_ALGO3 ((canvas_w/4)*3,(canvas_h/4)*3, t, t, 90, 0) NEXT
FOR t = 1 TO canvas_w
REM MY_ALGO3 ((canvas_w/4),(canvas_h/4)*3, t, t, 90, 0) NEXT SYNC
WAITKEY
Attachments:
|
|
|
Post by alexfish on Nov 26, 2015 7:28:05 GMT 1
Hi Vovchik
Was wondering how to get a results of % 360 back as a float or double
Came up with a simple Macro ,
BR Alex
REM My deg accept int % back as float
DEF FN GL_DEG(arg1) = arg1 % 360
LOCAL X# LOCAL Z = 234 REM X# = 234 % 360 LET X# = GL_DEG(Z)
PRINT X#
X# = 3.789
PRINT X#
Or can expand the code like so to accept two values
DEF FN MY_FUNC(arg1,arg2) = arg1 % arg2
LOCAL X# LOCAL Z = 400 REM X# = 234 % 360 X# = MY_FUNC(Z,360)
PRINT X#
|
|
|
Post by vovchik on Nov 26, 2015 22:42:26 GMT 1
Dear Alex, Thanks... Very convenient. Here is a brute-force fade-in, fade-out routine that could certainly be improved. At least it works... With kind regards, vovchik Attachments:fade-in-out.bac.tar.gz (1.18 KB)
|
|
|
Post by alexfish on Nov 26, 2015 23:32:04 GMT 1
Dear Alex, Thanks... Very convenient. Here is a brute-force fade-in, fade-out routine that could certainly be improved. At least it works... With kind regards, vovchik Well it be working Vovchik . I ain't gona sit up all night waiting for the SECONDS(NOW) to pass have change it to HOURS(NOW) may only apply for the Raspy. MM! while u be waiting , not sure how long the wait may be though ? and so will Robby The Robot ! see below, scene should change every second , I think says he Have Fun + BR tick tock, tic tock INCLUDE canvas.bac
DECLARE canvas_w, canvas_h canvas_w = 800 canvas_h = 600
SUB MY_ALGO3 (x, y, xsize, ysize, sides, fill)
LOCAL i LOCAL xt#, yt#
CALL Draw_Prepare CALL Check_Scale(x-xsize, y-ysize, xsize, ysize) CALL Check_Rotation(x-xsize, y-ysize, xsize, ysize) CALL Check_Move()
glBegin(GL_POINTS)
FOR i = 0 TO 359 STEP 360/sides xt# = xsize*COS(RAD(i)) yt# = ysize*SIN(RAD(i)) glVertex2f(x+xt#, y+yt#) NEXT
glEnd
ENDSUB
LOCAL xcol , xposi FUNCTION Draw_it() INK(5, 0, 0, 255) CLS REM MY_ALGO1 ((canvas_w/2)+10, 200, 60, 60, 60, 0) INK( 255,255,255,10) SCALE(1.5) PEN(2,1)
FOR t = 1 TO 20
MY_ALGO3 (canvas_w/2, canvas_h/2, t, t, 90, 0) NEXT LET xcol = (xcol+10) % 255
INK( xcol,xcol,255,30) FOR t = 1 TO 400
MY_ALGO3 (canvas_w/2,(canvas_h/2)+5, t, t, 90, 0) NEXT FOR t = 1 TO 400
MY_ALGO3 (canvas_w/2,(canvas_h/2)-5, t, t, 90, 0) NEXT REM PEN(2,1) FOR t = 1 TO 400
MY_ALGO3 ((canvas_w/2)+5,(canvas_h/2), t, t, 90, 0) NEXT FOR t = 1 TO 400
MY_ALGO3 ((canvas_w/2)-5,(canvas_h/2), t, t, 90, 0) NEXT
FOR t = 1 TO canvas_w
MY_ALGO3 ((canvas_w/4),(canvas_h/4), t, t, 90, 0) NEXT
FOR t = 1 TO canvas_w
REM MY_ALGO3 ((canvas_w/4)*3,(canvas_h/4), t, t, 90, 0) NEXT xposi = RANDOM(canvas_w/4)*3 FOR t = 1 TO canvas_w
MY_ALGO3 (xposi,xposi, t, t, 90, 0) NEXT
FOR t = 1 TO canvas_w
REM MY_ALGO3 ((canvas_w/4),(canvas_h/4)*3, t, t, 90, 0) NEXT SYNC RETURN TRUE END FUNCTION WINDOW("Circles & Segments et'all Kitchen Sink ", canvas_w, canvas_h)
SYNC INK(5, 0, 0, 255) CLS SYNC
CALLBACK(1,Draw_it) WAITKEY
|
|
|
Post by vovchik on Nov 27, 2015 11:08:16 GMT 1
Dear Alex (and all), Very nice. Here is, perhaps, a more efficient way to fade the entire canvas compared to my earlier attempt - accomplished by manipulating the colours of of the canvas pixel array directly. It seems much faster. And, the same method could, in theory, be used to place bitmaps (images) on selected areas of the canvas. With kind regards, vovchik
|
|
|
Post by alexfish on Nov 27, 2015 18:21:08 GMT 1
Hi Vovchik
have tested the above , RE frame timing to area's , per loop 1 to 250 for the glDrawPixels. on the Raspberry it works as expected Glut wise.
Nice fading . In any direction, doubt if that could be improved on.
BR Alex
Argh .. GDK PIXBUFF> + the Loader . maybe worth a try . esp the loader directly converts svg strings to the buffer so could get some nice effects cairo wise... etc
|
|
|
Post by alexfish on Nov 27, 2015 18:35:17 GMT 1
|
|
|
Post by vovchik on Nov 27, 2015 19:28:31 GMT 1
Dear Alex, Yes, my thoughts exactly - Marilyn and gdk loader pixbufs and shifting of origin in animation strips. Will be looking at that. There is our pixbuf friend gdk_pixbuf_get_pixels (a long unsigned char string filled as 4-byte groups for rgba). We just have to map that thing into the array used by glReadPixels and we have it. With kind regards, vovchik
|
|
|
Post by vovchik on Nov 27, 2015 21:06:31 GMT 1
Dear Alex, Almost a cigar now with regard to SVGs. Here are three SVGs being displayed by OPENGL. At the moment I am not writing directly to the GL canvas array, but will do that soon, unless you want to. It works in principle and in reality! Test2 in the archive actually does positioning. With kind regards, vovchik
|
|
|
Post by vovchik on Nov 27, 2015 23:10:37 GMT 1
Dear Alex, And we can do the same with pngs (in this case, inline and inline + file), and any other formats that our gdk pixbuf loader accepts. With kind regards, vovchik
|
|