|
Post by kennn on Dec 31, 2019 9:42:19 GMT -6
Hello,
Does this subroutine work on your computer? Thanks.
|
|
|
Post by n00b on Dec 31, 2019 14:16:49 GMT -6
This works just fine on every computer I have tested it on. I modified johnno56 demo to demonstrate how it works. This adds an extra canvas to johnno's original demo which is just used as a grey background. Canvas #1 is where the shape is drawn. Go down to line 118 to see where the SetCanvasAlpha code is being used. When the shape is finished drawing it will ask you to press 1 or 2 to see what low alpha and high alpha look like. '=========================================================================== '3D Surface Plot 'From "Microcomputer Graphics Techniques and Applications" by Donald Hearn 'Ported To PB by Dave Navarro (dave@powerbasic.com) '=========================================================================== 'Converted to sdlBAS, and colorized by Andres Amaya Jr '=========================================================================== 'Converted to RCBasic by Johnno56 - 27-Aug-2019 '=========================================================================== sw = 960 sh = 720 title$ = "3D Surface Plot" WindowOpen(1,title$,WINDOWPOS_CENTERED,WINDOWPOS_CENTERED,sw,sh,0) CanvasOpen(1,sw,sh,0,0,sw,sh,1) CanvasOpen(2,sw,sh,0,0,sw,sh,0) Canvas(2) SetColor(RGB(100,100,100)) BoxFill(0,0,sw,sh) Canvas(1) cx = int(sw / 2) cy = int(sh / 2) fx = cx - 30 fy = cy - 114 oldx = 0 oldy = 0 colours = 48 dim pal[colours] pal[0] = rgb(HexVal("00"), HexVal("00"), HexVal("FF")) pal[1] = rgb(HexVal("20"), HexVal("00"), HexVal("FF")) pal[2] = rgb(HexVal("40"), HexVal("00"), HexVal("FF")) pal[3] = rgb(HexVal("60"), HexVal("00"), HexVal("FF")) pal[4] = rgb(HexVal("80"), HexVal("00"), HexVal("FF")) pal[5] = rgb(HexVal("A0"), HexVal("00"), HexVal("FF")) pal[6] = rgb(HexVal("C0"), HexVal("00"), HexVal("FF")) pal[7] = rgb(HexVal("E0"), HexVal("00"), HexVal("FF")) pal[8] = rgb(HexVal("FF"), HexVal("00"), HexVal("FF")) pal[9] = rgb(HexVal("FF"), HexVal("00"), HexVal("E0")) pal[10] = rgb(HexVal("FF"), HexVal("00"), HexVal("C0")) pal[11] = rgb(HexVal("FF"), HexVal("00"), HexVal("A0")) pal[12] = rgb(HexVal("FF"), HexVal("00"), HexVal("80")) pal[13] = rgb(HexVal("FF"), HexVal("00"), HexVal("60")) pal[14] = rgb(HexVal("FF"), HexVal("00"), HexVal("40")) pal[15] = rgb(HexVal("FF"), HexVal("00"), HexVal("20")) pal[16] = rgb(HexVal("FF"), HexVal("00"), HexVal("00")) pal[17] = rgb(HexVal("FF"), HexVal("20"), HexVal("00")) pal[18] = rgb(HexVal("FF"), HexVal("40"), HexVal("00")) pal[19] = rgb(HexVal("FF"), HexVal("60"), HexVal("00")) pal[20] = rgb(HexVal("FF"), HexVal("80"), HexVal("00")) pal[21] = rgb(HexVal("FF"), HexVal("A0"), HexVal("00")) pal[22] = rgb(HexVal("FF"), HexVal("C0"), HexVal("00")) pal[23] = rgb(HexVal("FF"), HexVal("E0"), HexVal("00")) pal[24] = rgb(HexVal("FF"), HexVal("FF"), HexVal("00")) pal[25] = rgb(HexVal("E0"), HexVal("FF"), HexVal("00")) pal[26] = rgb(HexVal("C0"), HexVal("FF"), HexVal("00")) pal[27] = rgb(HexVal("A0"), HexVal("FF"), HexVal("00")) pal[28] = rgb(HexVal("80"), HexVal("FF"), HexVal("00")) pal[29] = rgb(HexVal("60"), HexVal("FF"), HexVal("00")) pal[30] = rgb(HexVal("40"), HexVal("FF"), HexVal("00")) pal[31] = rgb(HexVal("20"), HexVal("FF"), HexVal("00")) pal[32] = rgb(HexVal("00"), HexVal("FF"), HexVal("00")) pal[33] = rgb(HexVal("00"), HexVal("FF"), HexVal("20")) pal[34] = rgb(HexVal("00"), HexVal("FF"), HexVal("40")) pal[35] = rgb(HexVal("00"), HexVal("FF"), HexVal("60")) pal[36] = rgb(HexVal("00"), HexVal("FF"), HexVal("80")) pal[37] = rgb(HexVal("00"), HexVal("FF"), HexVal("A0")) pal[38] = rgb(HexVal("00"), HexVal("FF"), HexVal("C0")) pal[39] = rgb(HexVal("00"), HexVal("FF"), HexVal("E0")) pal[40] = rgb(HexVal("00"), HexVal("FF"), HexVal("FF")) pal[41] = rgb(HexVal("00"), HexVal("E0"), HexVal("FF")) pal[42] = rgb(HexVal("00"), HexVal("C0"), HexVal("FF")) pal[43] = rgb(HexVal("00"), HexVal("A0"), HexVal("FF")) pal[44] = rgb(HexVal("00"), HexVal("80"), HexVal("FF")) pal[45] = rgb(HexVal("00"), HexVal("60"), HexVal("FF")) pal[46] = rgb(HexVal("00"), HexVal("40"), HexVal("FF")) pal[47] = rgb(HexVal("00"), HexVal("20"), HexVal("FF")) rho = 45 scale = 1020 theta = 1 snt = Sin(Theta) cst = Cos(Theta) Phi = 1.0 snp = Sin(Phi) csp = Cos(Phi) tx = 450 ty = 485 'x & y translates ClearCanvas For x = -15 To 15 Step 0.125 flag = 0 x2 = x * x For y = -15 To 15 Step 0.125 xy2 = (x2 + y * y) / 20 z = 3.1 * Cos(xy2) xe = -x * snt + y * cst ye = -x * cst * csp - y * snt * csp + z * snp ze = -x * snp * cst - y * snt * snp - z * csp + Rho sx = Scale * xe / ze sy = Scale * ye / ze ix = Int(sx + tx) iy = sh - Int(sy + ty) colr = (Int(Sqrt((fx - ix) * (fx - ix) + 4.3 * (fy - iy) * (fy - iy)) / 15) + 7) Mod 48 If flag = 0 Then setColor(pal[colr]) Pset(ix, iy) flag = 1 oldx = ix oldy = iy Else setColor(pal[colr]) Line (oldx, oldy, ix, iy) oldx = ix oldy = iy End If Next update() next '------------- Set Canvas Alpha Demo --------------------- a = 255 SetColor(RGB(255,255,255)) Locate(0,0) PrintS("PRESS 1 FOR LOW ALPHA") PrintS("PRESS 2 FOR HIGH ALPHA") While Not Key(K_ESCAPE) If Key(K_1) Then a = 50 ElseIf Key(K_2) Then a = 255 End If SetCanvasAlpha(1, a) Update() Wend end
|
|
|
Post by johnno56 on Dec 31, 2019 14:42:50 GMT -6
Whoa! That's cool... Didn't know about 'that' effect... Cool...
|
|
|
Post by kennn on Dec 31, 2019 18:01:55 GMT -6
n00b,johnno56,
I am too foolish. Thanks.
|
|
|
Post by johnno56 on Dec 31, 2019 20:01:00 GMT -6
Foolish? I do not think so. Foolishness implies that one knows the right course of action and chooses another... If you did not know the correct command, then like me, it was simple ignorance... Now we both know... Cool...
|
|
|
Post by kennn on Dec 31, 2019 21:40:13 GMT -6
Foolish? I do not think so. Foolishness implies that one knows the right course of action and chooses another... If you did not know the correct command, then like me, it was simple ignorance... Now we both know... Cool... ok I want to ask one question. How to do the following operation? Thanks.
|
|
|
Post by johnno56 on Dec 31, 2019 23:06:29 GMT -6
x = sqrt(9)
x will return 3
|
|