|
Post by vovchik on Sept 28, 2015 11:48:43 GMT 1
Dear all, Here is one way to fade colours using HPC and the INK alpha argument (ported from one of my HUG canvas demos). I know it can be improved and would be pleased to see some suggestions. With kind regards, vovchik UPDATED: Added a new demo that uses a more efficient method to grab the named rgb from gdk_color_parse.
|
|
|
Post by vovchik on Sept 28, 2015 16:00:09 GMT 1
Dear all, Here is a little animated straw flower demo using HPC and turtle graphics. With kind regards, vovchik
|
|
|
Post by Pjot on Sept 29, 2015 2:43:49 GMT 1
Hi vovchik,
Thanks for all the demo's! They look nice and work as advertised.
BR Peter
|
|
|
Post by basica on Sept 30, 2015 17:28:53 GMT 1
vovchik, Thank you for posting those great animations. I especially like the "straw-flower" one... It's like having time-lapse photography without the camera. Regards, Basica
|
|
|
Post by vovchik on Sept 30, 2015 19:47:15 GMT 1
Dear basica, Thanks. I take it you finally got canvas running, which is great. Here is another little animation. It uses a modded turtle.bac - I removed the SYNC - and included all the necessary SYNCs in the actual demo program, so as to have control over the degree of animation. With kind regards, vovchik Attachments:
spirals.tar.gz (6.91 KB)
|
|
|
Post by basica on Sept 30, 2015 21:39:09 GMT 1
vovchik,
Yes thanks, I do have the canvas.bac running with PEN working by adding "DECLARE size TYPE float" and replacing "size#" with "size". Really quite odd.
I just tried the "spirals" one you posted, but only got a window with a color background.
Regards, basica
|
|
|
Post by Pjot on Oct 3, 2015 18:36:03 GMT 1
Folks, Another fun demo from the basicprogramming forum. BR Peter INCLUDE "canvas.bac"
CONST xmax=1200.0 CONST ymax=720.0
window("Aquarium", xmax, ymax)
LOCAL r, g, b, ra TYPE FLOATING r=0.0:g=0.0:b=0.0 CONST n=70
LOCAL x[n],y[n],l[n],dx[n],dy[n] TYPE FLOATING
FOR i=1 TO n x[i]=RANDOM(xmax) y[i]=RANDOM(ymax) l[i]=RANDOM(xmax*.05)+25 dx[i]=.0025*l[i]*l[i] NEXT
SUB Draw
FOR i=0 TO ymax INK(0,0,255-i/ymax*255,255) LINE(0,i,xmax,i) NEXT FOR i=1 TO n x[i]=x[i]-dx[i] IF x[i]+1.25*l[i]<0 THEN x[i]=xmax y[i]=y[i]+RANDOM(8)-4 INCR r, 0.2:INCR g, 0.005:INCR b, 0.010 IF r>.5 THEN r=.02 IF g>.5 THEN g=.005 IF b>.5 THEN b=.01 FOR ra=1 TO l[i] INK(127+127*SIN(r*ra),127+127*SIN(g*ra),127+127*SIN(b*ra), 255) LINE(x[i]+ra,y[i]-ra,x[i]+ra,y[i]+ra) NEXT FOR ra=5 TO .3*l[i] LINE(x[i]+l[i]+ra,y[i]-ra,x[i]+l[i]+ra,y[i]+ra) NEXT INK(0,0,0,255) CIRCLE(x[i]+.25*l[i],y[i],.1*l[i],.1*l[i],TRUE) INK(255,255,0,255) CIRCLE(x[i]+.25*l[i],y[i],.06*l[i],.06*l[i],FALSE) NEXT SYNC
END SUB
CALLBACK(10, Draw) WAITKEY
Attachments:
|
|
|
Post by Pjot on Oct 11, 2015 18:34:24 GMT 1
Folks, There was a really nice demo at the basicprogramming forum, which I ported to BaCon. The code below. Each run may take a 1 or 2 seconds but the results are different each time and very beautiful! Have fun! Peter ' VB6 code (c)2014 Mikle http://www.fbsl.net/phpbb2 ' FBSL port (c)2014 Mike Lobanovsky http://www.fbsl.net/phpbb2 ' BaCon port (c) 2015 Peter van Eerten http://www.basic-converter.org
INCLUDE canvas.bac
DECLARE Col[1024][768], CC[128][8], NZ[512][512], WB[1024][768], WX[1024][768], WY[1024][768] TYPE static int DECLARE SX, SY, FC, SX1, SY1 TYPE static double
CONST M_TWOPI = 2.0*PI
DEF FN GetRValue(x) = x & 0xFF DEF FN GetGValue(x) = (x>>8) & 0xFF DEF FN GetBValue(x) = (x>>16) & 0xFF
DEF FN RAND = (double)RND/MAXRANDOM
FUNCTION Lerp(int c1, int c2, double k) TYPE int
LOCAL d = 1.0 - k TYPE double
RETURN (int)((c1 & 0xFF)* k + (c2 & 0xFF) * d) \ | ((int)((c1 & 0xFF00)* k + (c2 & 0xFF00) * d) & 0xFF00) \ | ((int)((c1 & 0xFF0000)* k + (c2 & 0xFF0000) * d) & 0xFF0000)
END FUNCTION
FUNCTION BN(double x, double y) TYPE double
LOCAL ix, iy, dx, dy TYPE int LOCAL isx, isy TYPE double
ix = FLOOR(x): iy = FLOOR(y) dx = (ix + 1) & 511: dy = (iy + 1) & 511
SX = x - ix: SY = y - iy isx = 1.0 - SX: isy = 1.0 - SY
ix = ix & 511: iy = iy & 511
RETURN (double)(NZ[ix][iy] * isx * isy + NZ[dx][iy] * SX * isy + NZ[ix][dy] * isx* SY + NZ[dx][dy] * SX * SY)
END FUNCTION
FUNCTION BC(double x, double y) TYPE int
LOCAL ix, iy, c0, c1, c2, c3 TYPE int LOCAL ixy, isxy, isyx, xy TYPE double
ix = FLOOR(x): iy = FLOOR(y) SX = x - ix: SY = y - iy ixy = (1.0 - SX) * (1.0 - SY) isxy = SX * (1.0 - SY): isyx = SY * (1.0 - SX)
xy = SX * SY
c0 = CC[ix & 127][iy % 9] c1 = CC[(ix + 1) & 127][iy % 9] c2 = CC[ix & 127][(iy + 1) % 9] c3 = CC[(ix + 1) & 127][(iy + 1) % 9]
RETURN (c0 & 0xFF)* ixy + (c1 & 0xFF)* isxy + (c2 & 0xFF)* isyx + (c3 & 0xFF)* xy \ + ((int)((c0 & 0xFF00)* ixy + (c1 & 0xFF00)* isxy + (c2 & 0xFF00)* isyx + (c3 & 0xFF00)* xy) & 0xFF00) \ + ((int)((c0 & 0xFF0000)* ixy + (c1 & 0xFF0000)* isxy + (c2 & 0xFF0000)* isyx + (c3 & 0xFF0000)* xy) & 0xFF0000)
END FUNCTION
SUB Initialize
LOCAL x, y, d = 64, d2 = 128 TYPE int
SEED NOW
WHILE TRUE FOR y = 0 TO 511 STEP d2 FOR x = 0 TO 511 STEP d2 NZ[(x + d) & 511][y] = (NZ[x][y] + NZ[(x + d2) & 511][y])* 0.5 + d * (RAND - 0.5) NZ[x][(y + d) & 511] = (NZ[x][y] + NZ[x][(y + d2) & 511]) * 0.5 + d * (RAND - 0.5) NZ[(x + d) & 511][(y + d) & 511] = (NZ[x][y] + NZ[(x + d2) & 511][(y + d2) & 511] \ + NZ[x][(y + d2) & 511] + NZ[(x + d2) & 511][y]) * 0.25 + d * (RAND - 0.5) NEXT NEXT IF d = 1 THEN BREAK d = d>>1: d2 = d + d WEND
END SUB
SUB Colorize
LOCAL x, y, xx, yy, c, r, g, b TYPE int
FOR x = 0 TO 127 FOR y = 0 TO 7 r = 0: g = 0: b = 0 FOR yy = 0 TO 47 FOR xx = 0 TO 7 c = Col[xx + x * 8][yy + y * 48] INCR r, (c & 0xFF) INCR g, (c & 0xFF00) INCR b, ((c & 0xFF0000) >> 8) NEXT NEXT CC[x][y] = r / 384 + ((g / 384) & 0xFF00) + (((b / 384) & 0xFF00) << 8) NEXT CC[x][8] = CC[x][7] NEXT ENDSUB
SUB Sky
LOCAL x, y, c1, c2 TYPE int LOCAL k, s, sx1, sy1, dy TYPE double
SX = 100 + RAND * 824: SY = 192 + RAND * 157 SX1 = SX: SY1 = SY FOR y = 0 TO 383 sy1 = 100000.0 / (390.0 - y) FOR x = 0 TO 1023 sx1 = (x - 511.5) * sy1 * 0.0005 k = BN(sx1, sy1) - BN(sx1 * 0.14 + sy1 * 0.21, sy1 * 0.14 - sx1 * 0.21) IF k < -8.0 THEN k = 0.0 ELSE k = (k + 8.0) * 0.02 :'cloud density ENDIF IF k > 1.0 THEN k = 1.0 dy = y / 384.0 FC = 0x908000 + (SY1 + 500.0) * 0.2 :' haze tint c1 = Lerp(FC + 25, 0x906050, dy) c2 = Lerp(0x807080, 0xD0D0D0, dy) s = 30.0 / SQR((x - SX1) * (x - SX1) + (y - SY1) * (y - SY1)) :' sun size IF s > 1.0 THEN s = 1.0 c1 = Lerp(0xFFFFFF, c1, s) Col[x][y] = Lerp(c2, c1, k) NEXT NEXT
ENDSUB
SUB Water
LOCAL x, y TYPE int LOCAL x1, y1, k, kx, sx1, sy1, sx2, sy2 TYPE double
FOR y = 767 TO 384 STEP -1 k = (y - 383) * 0.5: kx = (900 - y) / 580.0 FOR x = 1023 TO 0 STEP -1 sy1 = 64000.0 / (y - 380) sx1 = (x - 511.5) * sy1 * 0.002 sy2 = sy1 * 0.34 - sx1 * 0.71 sx2 = sx1 * 0.34 + sy1 * 0.71 sy1 = sy2 * 0.34 - sx2 * 0.21 sx1 = sx2 * 0.34 + sy2 * 0.21 WB[x][y] = BN(sx1, sy1) - BN(sx2, sy2) WX[x][y] = (WB[x + 1][y] - WB[x][y]) * k * kx WY[x][y] = (WB[x][y + 1] - WB[x][y]) * k x1 = ABS(x + WX[x][y]) y1 = 768.0 - y + WY[x][y] IF y1 < 0.0 THEN y1 = 0.0 ELIF y1 > 383.0 THEN y1 = 383.0 ENDIF Col[x][y] = Lerp(BC(x1 / 8, y1 / 48), 0x251510, kx): 'water tint NEXT NEXT
ENDSUB
SUB Air
LOCAL x, y, c TYPE int LOCAL k1, k2, s TYPE double LOCAL col TYPE int
FOR y = 0 TO 767 k1 = POW((1.0 - ABS(383.5 - y) / 384.0), 5.0) FOR x = 0 TO 1023 IF y = SY1 THEN k2 = 0.25 ELSE k2 = ATN((x - SX1) / (y - SY1)) / M_TWOPI + 0.25 ENDIF IF y - SY1 < 0 THEN INCR k2, 0.5 k2 = BN(k2 * 512.0, 0.0) * 0.03 k2 = 0.2 - k2 * k2: IF k2 < 0.0 THEN k2 = 0.0 s = 30.0 / SQR((x - SX1) * (x - SX1) + (y - SY1) * (y - SY1)) IF s > 1.0 THEN s = 1.0 c = Lerp(0xFFFFFF, FC, k2 * (1.0 - s)) col = Lerp(c, Col[x][y], k1) INK(GetRValue(col), GetGValue(col), GetBValue(col), 255) PIXEL(x, y) NEXT NEXT
ENDSUB
WINDOW("Seascape", 1024, 768) CALL Initialize() CALL Sky() CALL Colorize() CALL Water() CALL Air() WAITKEY
Attachments:
|
|
|
Post by basica on Oct 11, 2015 21:44:15 GMT 1
Peter,
Wow, That is something. (A seascape in code and each run changes the light)
I had to make one small change to get it to run.... on line 91
r = 0 :g = 0:b = 0
This makes me wonder how one conceptualizes a picture into this kind of coding.
Thanks for this, basica (I guess it just takes a basketful of Sky, Air, Water, and Color, skillfully mixed)
|
|
|
Post by Pjot on Oct 12, 2015 12:21:37 GMT 1
Thanks basica, It would work with the latest beta 3.1.1, but your fix indeed is the correct way for 3.1. For the code itself, I only ported it to BaCon, and I do not understand much of it myself to be honest . The original code does not have a lot of documentation so a lot of it is guessing... BR Peter
|
|
|
Post by bigbass on Oct 12, 2015 15:59:02 GMT 1
|
|
|
Post by alexfish on Oct 23, 2015 20:22:32 GMT 1
Hi Peter & All Peter > thanks for the Standalone Canvas option, I am still Idling my time on the Rasberry .. Raspie can't do the new lib So thought i would put the cat amongst the pigeons Ha ha.. Code Wise , the algo is simple , but to get the effect per canvas is not back to some old stuff lib gfx , re GooCanvas the demo is called Torsion, the basics are the 3 and the 84 , the 84 can be divided by 2 to give a base of 42 the 42 is the answer to the Universe and everything (HGTG) REM using libgfx -- goocanvas LOCAL T,X,Y TYPE double
FOR T = PI/(3*84) TO PI*2 STEP PI/(3*84)
X = Cos(T)*200 Y = Sin(T)*100
Ellipse(Surface,X+300.0,Y+200.0,100,100,"stroke_color","blue","line-width",0.5) NEXT
Challenge :: See the Picture + variants of Have Fun Alex Attachments:
|
|
|
Post by vovchik on Nov 1, 2015 20:01:41 GMT 1
Dear all, A now for another blast from the past. Here is Plt2Bac, a little program that loads an HPGL PLT file, displays it, allows positioning and scaling and saves back as three runnable programs: HUG canvas, high-performance canvas as an array of vectors and high-performance canvas as LINE statements. For the high-performance canvas, if you want more detail, just change the pen size before PLOT in the generated source to something between 0.5 and 1.1, and, possibly, change the alpha in the ink statement to 40 or 50 (if you happen to have have a lot of fine, intersecting lines). Included in the archive is the Plt2Bac source, canvas.bac and hug.bac, in addition to some 90 HPGL plt files as examples. If you run into one of your own *.plt files that displays badly, run it through Inkscape, scale the page size to the drawing (Doc info under File) and save back as Autocad/HP plt file (near the end of the Inkscape list of file types). Have fun. With kind regards, vovchik PS. UPDATED - added SETENVIRON "LC_ALL", "C" at the top, so it should now work in all locales. That string is also now in the generated files. Just download the archive again to save yourself some editing. Attachments:
|
|
|
Post by Pjot on Nov 1, 2015 21:25:30 GMT 1
Thanks vovchik, Very cool!!! One problem though, on my computer the data generated uses a ',' instead of a '.' as a radix because of my Dutch locale settings. I had to do 'export LC_ALL=C' first, before executing your program. After that it works flawless. Please find my small Marquee below, hope you enjoy Spinoza as much as I do. BR Peter EDIT: If you add: SETENVIRON "LC_ALL", "C" as a first line (even before the include hug.bac) it all works. INCLUDE canvas.bac
'CONST FileHost$ = "www.gutenberg.org" CONST FileHost$ = "www.ibiblio.org"
'CONST FileText$ = "/files/3800/3800.txt" CONST FileText$ = "/pub/docs/books/gutenberg/3/8/0/3800/3800.txt"
CONST ScreenWidth = 640 CONST ScreenHeight = 700 CONST Factor = 0.6 CONST FontHeight = 36 CONST FontWidth = 16 CONST Lines = INT(ScreenHeight/(FontHeight*Factor))
WINDOW("Scrolling text", ScreenWidth, ScreenHeight) INK(0,0,0,255) CLS
SCALE(Factor) INK(100,128,255,255)
OPEN FileHost$ & ":80" FOR NETWORK AS mynet SEND "GET " & FileText$ & " HTTP/1.1\r\nHost: " & FileHost$ & "\r\n\r\n" TO mynet
info$ = "Downloading text from " & FileHost$
ypos = 10 REPEAT RECEIVE line$ FROM mynet input$ = input$ & line$ info$ = info$ & "." IF LEN(info$) >= 60 THEN INCR ypos, FontHeight info$ = "." ENDIF TEXT(info$, 10-LEN(info$)*8*(1.0-Factor), ypos) SYNC UNTIL ISFALSE(WAIT(mynet, 1000))
CLOSE NETWORK mynet
' Rip off HTTP header from data input$ = MID$(input$, INSTR(input$, CR$ & NL$ & CR$ & NL$)+4)
data$ = input$
PEN(1.0, TRUE)
SUB Draw
LOCAL scroll=0 TYPE static int LOCAL txt$
INK(0,0,0,255) CLS
INK(100,128,255,255) SCALE(Factor) MOVE(270, scroll)
txt$ = data$
FOR lines = 1 TO Lines endpos = INSTR(txt$, NL$) TEXT(MID$(txt$, 1, endpos), 10-LEN(MID$(txt$, 1, endpos))*8*(1.0-Factor), INT(lines*FontHeight*Factor)) txt$ = MID$(txt$, endpos+1) NEXT
INCR scroll
IF scroll = FontHeight THEN scroll = 0 data$ = MID$(data$, INSTR(data$, NL$)+1) IF LEN(data$) = 0 THEN data$ = input$ ENDIF
ENDSUB
CALLBACK(5, Draw) WAITKEY
Attachments:
|
|
|
Post by vovchik on Nov 1, 2015 21:36:57 GMT 1
Dear Peter, Thanks. I am glad it works with the export. I think I should build the bit into the program. And thanks for the Spinoza, whom I admire very much. I tried to run your scrolling source but get an error related to "MOVE". I don't have it in what I thought was the latest canvas. Could you post the latest? Thanks again. With kind regards, vovchik
|
|