Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/Draw-a-sphere/FreeBASIC/draw-a-sphere-1.basic
Normal file
48
Task/Draw-a-sphere/FreeBASIC/draw-a-sphere-1.basic
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
' "\" = a integer division (CPU)
|
||||
' "/" = a floating point division (FPU)
|
||||
' the compiler takes care of the conversion between floating point and integer
|
||||
' compile with: FBC -s console "filename.bas" or FBC -s GUI "filename.bas"
|
||||
' filename is whatever name you give it, .bas is mandatory
|
||||
|
||||
' Sphere using XPL0 code from rosetacode sphere page
|
||||
' Altered freebasic version to compile in default mode
|
||||
' version 17-06-2015
|
||||
' compile with: fbc -s console or fbc -s gui
|
||||
#Define W 640
|
||||
#Define H 480
|
||||
|
||||
ScreenRes W, H, 32 ' set 640x480x32 graphics mode, 32 bits color mode
|
||||
WindowTitle "32 bpp Cyan Sphere FreeBASIC"
|
||||
|
||||
' wait until keypress
|
||||
' Color(RGB(255,255,255),RGB(0,0,0)) ' default white foreground, black background
|
||||
Locate 50,2
|
||||
Print "Enter any key to start"
|
||||
Sleep
|
||||
|
||||
Dim As UInteger R = 100, R2 = R * R ' radius, in pixels; radius squared
|
||||
Dim As UInteger X0 = W \ 2, Y0 = H \ 2 ' coordinates of center of screen
|
||||
Dim As Integer X, Y, C, D2 ' coords, color, distance from center squared
|
||||
|
||||
For Y = -R To R ' for all the coordinates near the circle
|
||||
For X = -R To R ' which is under the sphere
|
||||
D2 = X * X + Y * Y
|
||||
If D2 <= R2 Then ' coordinate is inside circle under sphere
|
||||
' height of point on surface of sphere above X,Y
|
||||
C = Sqr(R2 - D2) - ( X + Y) / 2 + 130 ' color is proportional; offset X and Y, and
|
||||
|
||||
Color C Shl 8 + C ' = color RGB(0, C, C)
|
||||
' green + blue = cyan
|
||||
PSet(X + X0, Y + Y0)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
' wait until keypress
|
||||
Locate 50,2
|
||||
Color(RGB(255,255,255),RGB(0,0,0)) ' foreground color is changed
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
36
Task/Draw-a-sphere/FreeBASIC/draw-a-sphere-2.basic
Normal file
36
Task/Draw-a-sphere/FreeBASIC/draw-a-sphere-2.basic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
'Sphere for FreeBASIC May 2015
|
||||
'spherefb4.bas
|
||||
'Sphere using XPL0 code from rosetacode sphere page
|
||||
'
|
||||
screenres 640,480,32 '\set 640x480x32 graphics mode
|
||||
windowtitle "32 bpp Blue Sphere FreeBASIC"
|
||||
'
|
||||
' wait until keypress
|
||||
locate 50,2
|
||||
color(rgb(255,255,255),rgb(0,0,0))
|
||||
Print "Enter any key to start"
|
||||
sleep
|
||||
R=100 : R2=R*R '\radius, in pixels; radius squared
|
||||
X0=640/2 : Y0=480/2 '\coordinates of center of screen
|
||||
dim as integer X, Y, Z, C, D2 '\coords, color, distance from center squared
|
||||
'
|
||||
for Y= -R to +R '\for all the coordinates near the circle
|
||||
for X = -R to +R '\ which is under the sphere
|
||||
D2 = X*X + Y*Y '
|
||||
C = 0 '\default color is black
|
||||
if D2 <= R2 then '\coordinate is inside circle under sphere
|
||||
Z = sqr(R2-D2) '\height of point on surface of sphere above X,Y
|
||||
C = Z-(X+Y)/2+130 ' \color is proportional; offset X and Y, and
|
||||
endif
|
||||
color c ' \ shift color to upper limit of its range
|
||||
'\green + blue = cyan orginal line don't understand
|
||||
Pset(X+X0, Y+Y0)
|
||||
next x
|
||||
next y
|
||||
'
|
||||
' wait until keypress
|
||||
locate 50,2
|
||||
color(rgb(255,255,255),rgb(0,0,0))
|
||||
Print "Enter any key to exit "
|
||||
sleep
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue