Post by johnno56 on Aug 27, 2019 7:03:42 GMT -6
Here is an old classic... Totally useless... But easy on the eyes...
Sorry about the lengthy palette conversion. Too tired to code a Hex to RGB routine so I used the HexInt() command instead... I know, bone lazy....
'===========================================================================
'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$,0,0,sw,sh,0)
CanvasOpen(1,sw,sh,0,0,sw,sh,0)
cx = int(sw / 2)
cy = int(sh / 2)
fx = cx - 30
fy = cy - 114
oldx = 0
oldy = 0
colours = 48
dim pal[colours]
' Original pallette
'
'pal[0] = 0x0000FF : pal[1] = 0x2000FF : pal[2] = 0x4000FF : pal[3] = 0x6000FF
'pal[4] = 0x8000FF : pal[5] = 0xA000FF : pal[6] = 0xC000FF : pal[7] = 0xE000FF
'pal[8] = 0xFF00FF : pal[9] = 0xFF00E0 : pal[10] = 0xFF00C0 : pal[11] = 0xFF00A0
'pal[12] = 0xFF0080 : pal[13] = 0xFF0060 : pal[14] = 0xFF0040 : pal[15] = 0xFF0020
'pal[16] = 0xFF0000 : pal[17] = 0xFF2000 : pal[18] = 0xFF4000 : pal[19] = 0xFF6000
'pal[20] = 0xFF8000 : pal[21] = 0xFFA000 : pal[22] = 0xFFC000 : pal[23] = 0xFFE000
'pal[24] = 0xFFFF00 : pal[25] = 0xE0FF00 : pal[26] = 0xC0FF00 : pal[27] = 0xA0FF00
'pal[28] = 0x80FF00 : pal[29] = 0x60FF00 : pal[30] = 0x40FF00 : pal[31] = 0x20FF00
'pal[32] = 0x00FF00 : pal[33] = 0x00FF20 : pal[34] = 0x00FF40 : pal[35] = 0x00FF60
'pal[36] = 0x00FF80 : pal[37] = 0x00FFA0 : pal[38] = 0x00FFC0 : pal[39] = 0x00FFE0
'pal[40] = 0x00FFFF : pal[41] = 0x00E0FF : pal[42] = 0x00C0FF : pal[43] = 0x00A0FF
'pal[44] = 0x0080FF : pal[45] = 0x0060FF : pal[46] = 0x0040FF : pal[47] = 0x0020FF
pal[0] = rgb(HexInt("00"), HexInt("00"), HexInt("FF"))
pal[1] = rgb(HexInt("20"), HexInt("00"), HexInt("FF"))
pal[2] = rgb(HexInt("40"), HexInt("00"), HexInt("FF"))
pal[3] = rgb(HexInt("60"), HexInt("00"), HexInt("FF"))
pal[4] = rgb(HexInt("80"), HexInt("00"), HexInt("FF"))
pal[5] = rgb(HexInt("A0"), HexInt("00"), HexInt("FF"))
pal[6] = rgb(HexInt("C0"), HexInt("00"), HexInt("FF"))
pal[7] = rgb(HexInt("E0"), HexInt("00"), HexInt("FF"))
pal[8] = rgb(HexInt("FF"), HexInt("00"), HexInt("FF"))
pal[9] = rgb(HexInt("FF"), HexInt("00"), HexInt("E0"))
pal[10] = rgb(HexInt("FF"), HexInt("00"), HexInt("C0"))
pal[11] = rgb(HexInt("FF"), HexInt("00"), HexInt("A0"))
pal[12] = rgb(HexInt("FF"), HexInt("00"), HexInt("80"))
pal[13] = rgb(HexInt("FF"), HexInt("00"), HexInt("60"))
pal[14] = rgb(HexInt("FF"), HexInt("00"), HexInt("40"))
pal[15] = rgb(HexInt("FF"), HexInt("00"), HexInt("20"))
pal[16] = rgb(HexInt("FF"), HexInt("00"), HexInt("00"))
pal[17] = rgb(HexInt("FF"), HexInt("20"), HexInt("00"))
pal[18] = rgb(HexInt("FF"), HexInt("40"), HexInt("00"))
pal[19] = rgb(HexInt("FF"), HexInt("60"), HexInt("00"))
pal[20] = rgb(HexInt("FF"), HexInt("80"), HexInt("00"))
pal[21] = rgb(HexInt("FF"), HexInt("A0"), HexInt("00"))
pal[22] = rgb(HexInt("FF"), HexInt("C0"), HexInt("00"))
pal[23] = rgb(HexInt("FF"), HexInt("E0"), HexInt("00"))
pal[24] = rgb(HexInt("FF"), HexInt("FF"), HexInt("00"))
pal[25] = rgb(HexInt("E0"), HexInt("FF"), HexInt("00"))
pal[26] = rgb(HexInt("C0"), HexInt("FF"), HexInt("00"))
pal[27] = rgb(HexInt("A0"), HexInt("FF"), HexInt("00"))
pal[28] = rgb(HexInt("80"), HexInt("FF"), HexInt("00"))
pal[29] = rgb(HexInt("60"), HexInt("FF"), HexInt("00"))
pal[30] = rgb(HexInt("40"), HexInt("FF"), HexInt("00"))
pal[31] = rgb(HexInt("20"), HexInt("FF"), HexInt("00"))
pal[32] = rgb(HexInt("00"), HexInt("FF"), HexInt("00"))
pal[33] = rgb(HexInt("00"), HexInt("FF"), HexInt("20"))
pal[34] = rgb(HexInt("00"), HexInt("FF"), HexInt("40"))
pal[35] = rgb(HexInt("00"), HexInt("FF"), HexInt("60"))
pal[36] = rgb(HexInt("00"), HexInt("FF"), HexInt("80"))
pal[37] = rgb(HexInt("00"), HexInt("FF"), HexInt("A0"))
pal[38] = rgb(HexInt("00"), HexInt("FF"), HexInt("C0"))
pal[39] = rgb(HexInt("00"), HexInt("FF"), HexInt("E0"))
pal[40] = rgb(HexInt("00"), HexInt("FF"), HexInt("FF"))
pal[41] = rgb(HexInt("00"), HexInt("E0"), HexInt("FF"))
pal[42] = rgb(HexInt("00"), HexInt("C0"), HexInt("FF"))
pal[43] = rgb(HexInt("00"), HexInt("A0"), HexInt("FF"))
pal[44] = rgb(HexInt("00"), HexInt("80"), HexInt("FF"))
pal[45] = rgb(HexInt("00"), HexInt("60"), HexInt("FF"))
pal[46] = rgb(HexInt("00"), HexInt("40"), HexInt("FF"))
pal[47] = rgb(HexInt("00"), HexInt("20"), HexInt("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
wait(3000)
end
Sorry about the lengthy palette conversion. Too tired to code a Hex to RGB routine so I used the HexInt() command instead... I know, bone lazy....