langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
2
Task/Draw-a-sphere/Openscad/draw-a-sphere.scad
Normal file
2
Task/Draw-a-sphere/Openscad/draw-a-sphere.scad
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// This will produce a sphere of radius 5
|
||||
sphere(5);
|
||||
15
Task/Draw-a-sphere/POV-Ray/draw-a-sphere.pov-ray
Normal file
15
Task/Draw-a-sphere/POV-Ray/draw-a-sphere.pov-ray
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
camera { location <0.0 , .8 ,-3.0> look_at 0}
|
||||
|
||||
light_source{< 3,3,-3> color rgb 1}
|
||||
|
||||
sky_sphere { pigment{ gradient <0,1,0> color_map {[0 color rgb <.2,.1,0>][.5 color rgb 1]} scale 2}}
|
||||
|
||||
plane {y,-2 pigment { hexagon color rgb .7 color rgb .5 color rgb .6 }}
|
||||
|
||||
sphere { 0,1
|
||||
texture {
|
||||
pigment{ color rgbft <.8,1,1,.4,.4> }
|
||||
finish { phong 1 reflection {0.40 metallic 0.5} }
|
||||
}
|
||||
interior { ior 1.5}
|
||||
}
|
||||
35
Task/Draw-a-sphere/Perl-6/draw-a-sphere.pl6
Normal file
35
Task/Draw-a-sphere/Perl-6/draw-a-sphere.pl6
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
my $x = my $y = 255;
|
||||
$x +|= 1; # must be odd
|
||||
|
||||
my @light = normalize([ 3, 2, -5 ]);
|
||||
|
||||
my $depth = 255;
|
||||
|
||||
sub MAIN ($outfile = 'sphere-perl6.pgm') {
|
||||
my $out = open( $outfile, :w, :bin ) or die "$!\n";
|
||||
$out.say("P5\n$x $y\n$depth"); # .pgm header
|
||||
$out.print( draw_sphere( ($x-1)/2, .9, .2)».chrs );
|
||||
$out.close;
|
||||
}
|
||||
|
||||
sub normalize (@vec) { return @vec »/» ([+] @vec Z* @vec).sqrt }
|
||||
|
||||
sub dot (@x, @y) { return -([+] @x Z* @y) max 0 }
|
||||
|
||||
sub draw_sphere ( $rad, $k, $ambient ) {
|
||||
my @pixels;
|
||||
my $r2 = $rad * $rad;
|
||||
my @range = -$rad .. $rad;
|
||||
for @range X @range -> $x, $y {
|
||||
if (my $x2 = $x * $x) + (my $y2 = $y * $y) < $r2 {
|
||||
my @vector = normalize([$x, $y, ($r2 - $x2 - $y2).sqrt]);
|
||||
my $intensity = dot(@light, @vector) ** $k + $ambient;
|
||||
my $pixel = (0 max ($intensity * $depth).Int) min $depth;
|
||||
@pixels.push($pixel);
|
||||
}
|
||||
else {
|
||||
@pixels.push(0);
|
||||
}
|
||||
}
|
||||
return @pixels;
|
||||
}
|
||||
23
Task/Draw-a-sphere/PostScript/draw-a-sphere.ps
Normal file
23
Task/Draw-a-sphere/PostScript/draw-a-sphere.ps
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
%!PS-Adobe-3.0
|
||||
%%BoundingBox 0 0 300 300
|
||||
|
||||
150 150 translate 0 0 130 0 360 arc
|
||||
|
||||
/Pattern setcolorspace
|
||||
<< /PatternType 2
|
||||
/Shading <<
|
||||
/ShadingType 3
|
||||
/ColorSpace /DeviceRGB
|
||||
/Coords [-60 60 0 0 0 100]
|
||||
/Function <<
|
||||
/FunctionType 2
|
||||
/Domain [0 1]
|
||||
/C0 [1 1 1]
|
||||
/C1 [0 0 0]
|
||||
/N 2
|
||||
>>
|
||||
>>
|
||||
>> matrix makepattern setcolor fill
|
||||
|
||||
showpage
|
||||
%%EOF
|
||||
251
Task/Draw-a-sphere/PureBasic/draw-a-sphere.purebasic
Normal file
251
Task/Draw-a-sphere/PureBasic/draw-a-sphere.purebasic
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
; Original by Comtois @ 28/03/06
|
||||
;
|
||||
; Updated/Formated by Fluid Byte @ March.24,2009
|
||||
;
|
||||
; http://www.purebasic.fr/english/viewtopic.php?p=281258#p281258
|
||||
|
||||
Declare CreateSphere(M,P)
|
||||
Declare UpdateMesh()
|
||||
|
||||
#_SIZEVERT = 36
|
||||
#_SIZETRIS = 6
|
||||
#FULLSCREEN = 0
|
||||
|
||||
Structure VECTOR
|
||||
X.f
|
||||
Y.f
|
||||
Z.f
|
||||
EndStructure
|
||||
|
||||
Structure VERTEX
|
||||
X.f
|
||||
Y.f
|
||||
Z.f
|
||||
NX.f
|
||||
NY.f
|
||||
NZ.f
|
||||
Color.l
|
||||
U.f
|
||||
V.f
|
||||
EndStructure
|
||||
|
||||
Structure TRIANGLE
|
||||
V1.w
|
||||
V2.w
|
||||
V3.w
|
||||
EndStructure
|
||||
|
||||
Macro CALC_NORMALS
|
||||
*PtrV\NX = *PtrV\X
|
||||
*PtrV\NY = *PtrV\Y
|
||||
*PtrV\NZ = *PtrV\Z
|
||||
EndMacro
|
||||
|
||||
Global *VBuffer, *IBuffer
|
||||
Global Meridian = 50, Parallele = 50, PasLength = 4, Length
|
||||
|
||||
Define EventID, i, NbSommet, CameraMode, Angle.f, Pas.f = 0.5
|
||||
|
||||
InitEngine3D() : InitSprite() : InitKeyboard()
|
||||
|
||||
Add3DArchive(GetTemporaryDirectory(),#PB_3DArchive_FileSystem)
|
||||
Add3DArchive(#PB_Compiler_Home + "Examples\Sources\Data\",#PB_3DArchive_FileSystem)
|
||||
|
||||
If #FULLSCREEN
|
||||
OpenScreen(800,600,32,"Sphere 3D")
|
||||
Else
|
||||
OpenWindow(0,0,0,800,600,"Sphere 3D",#PB_Window_SystemMenu | 1)
|
||||
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)
|
||||
EndIf
|
||||
|
||||
;-Texture
|
||||
CreateImage(0,128,128)
|
||||
StartDrawing(ImageOutput(0))
|
||||
For i = 0 To 127 Step 4
|
||||
Box(0,i,ImageWidth(0),2,RGB(255,255,255))
|
||||
Box(0,i + 2,ImageWidth(0),2,RGB(0,0,155))
|
||||
Next i
|
||||
StopDrawing()
|
||||
SaveImage(0,GetTemporaryDirectory() + "temp.bmp") : FreeImage(0)
|
||||
|
||||
;-Material
|
||||
CreateMaterial(0,LoadTexture(0,"temp.bmp"))
|
||||
RotateMaterial(0,0.1,#PB_Material_Animated)
|
||||
|
||||
;-Mesh
|
||||
CreateSphere(Meridian,Parallele)
|
||||
|
||||
;-Entity
|
||||
CreateEntity(0,MeshID(0),MaterialID(0))
|
||||
ScaleEntity(0,60,60,60)
|
||||
|
||||
;-Camera
|
||||
CreateCamera(0,0,0,100,100)
|
||||
MoveCamera(0,0,0,-200)
|
||||
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))
|
||||
|
||||
;-Light
|
||||
AmbientColor(RGB(105, 105, 105))
|
||||
CreateLight(0, RGB(255, 255, 55), EntityX(0) + 150, EntityY(0) , EntityZ(0))
|
||||
CreateLight(1, RGB( 55, 255, 255), EntityX(0) - 150, EntityY(0) , EntityZ(0))
|
||||
CreateLight(2, RGB( 55, 55, 255), EntityX(0) , EntityY(0) + 150, EntityZ(0))
|
||||
CreateLight(3, RGB(255, 55, 255), EntityX(0) , EntityY(0) - 150, EntityZ(0))
|
||||
|
||||
; ----------------------------------------------------------------------------------------------------
|
||||
; MAINLOOP
|
||||
; ----------------------------------------------------------------------------------------------------
|
||||
|
||||
Repeat
|
||||
If #FULLSCREEN = 0
|
||||
Repeat
|
||||
EventID = WindowEvent()
|
||||
|
||||
Select EventID
|
||||
Case #PB_Event_CloseWindow : End
|
||||
EndSelect
|
||||
Until EventID = 0
|
||||
EndIf
|
||||
|
||||
Angle + Pas
|
||||
RotateEntity(0, Angle, Angle,Angle)
|
||||
|
||||
If PasLength > 0 : UpdateMesh() : EndIf
|
||||
|
||||
If ExamineKeyboard()
|
||||
If KeyboardReleased(#PB_Key_F1)
|
||||
CameraMode = 1 - CameraMode
|
||||
CameraRenderMode(0, CameraMode)
|
||||
EndIf
|
||||
EndIf
|
||||
|
||||
RenderWorld()
|
||||
FlipBuffers()
|
||||
Until KeyboardPushed(#PB_Key_Escape)
|
||||
|
||||
; ----------------------------------------------------------------------------------------------------
|
||||
; FUNCTIONS
|
||||
; ----------------------------------------------------------------------------------------------------
|
||||
|
||||
Procedure CreateSphere(M,P)
|
||||
; M = Meridian
|
||||
; P = Parallele
|
||||
; The radius is 1. Front to remove it later, it's just for the demo.
|
||||
|
||||
If M < 3 Or P < 2 : ProcedureReturn 0 : EndIf
|
||||
|
||||
Protected Normale.VECTOR, NbSommet, i, j, Theta.f, cTheta.f, sTheta.f
|
||||
Protected Alpha.f, cAlpha.f, sAlpha.f, *PtrV.VERTEX, *PtrF.TRIANGLE, NbTriangle
|
||||
|
||||
NbSommet = 2 + ((M + 1) * P)
|
||||
*VBuffer = AllocateMemory(#_SIZEVERT * Nbsommet)
|
||||
|
||||
For i = 0 To M
|
||||
Theta = i * #PI * 2.0 / M
|
||||
cTheta = Cos(theta)
|
||||
sTheta = Sin(theta)
|
||||
|
||||
For j = 1 To P
|
||||
Alpha = j * #PI / (P + 1)
|
||||
cAlpha = Cos(Alpha)
|
||||
sAlpha = Sin(Alpha)
|
||||
*PtrV = *VBuffer + #_SIZEVERT * ((i * P) + (j - 1))
|
||||
*PtrV\X = sAlpha * cTheta
|
||||
*PtrV\Y = sAlpha * sTheta
|
||||
*PtrV\Z = cAlpha
|
||||
*PtrV\U = Theta / (2.0 * #PI)
|
||||
*PtrV\V = Alpha / #PI
|
||||
CALC_NORMALS
|
||||
Next j
|
||||
Next i
|
||||
|
||||
; Southpole
|
||||
*PtrV = *VBuffer + #_SIZEVERT * ((M + 1) * P)
|
||||
*PtrV\X = 0
|
||||
*PtrV\Y = 0
|
||||
*PtrV\Z = -1
|
||||
*PtrV\U = 0
|
||||
*PtrV\V = 0
|
||||
CALC_NORMALS
|
||||
|
||||
; Northpole
|
||||
*PtrV + #_SIZEVERT
|
||||
*PtrV\X = 0
|
||||
*PtrV\Y = 0
|
||||
*PtrV\Z = 1
|
||||
*PtrV\U = 0
|
||||
*PtrV\V = 0
|
||||
CALC_NORMALS
|
||||
|
||||
; Les facettes
|
||||
NbTriangle = 4 * M * P
|
||||
*IBuffer = AllocateMemory(#_SIZETRIS * NbTriangle)
|
||||
*PtrF = *IBuffer
|
||||
|
||||
For i = 0 To M - 1
|
||||
For j = 1 To P - 1
|
||||
*PtrF\V1 = ((i + 1) * P) + j
|
||||
*PtrF\V2 = ((i + 1) * P) + (j - 1)
|
||||
*PtrF\V3 = (i * P) + (j - 1)
|
||||
*PtrF + #_SIZETRIS
|
||||
*PtrF\V3 = ((i + 1) * P) + j ;Recto
|
||||
*PtrF\V2 = ((i + 1) * P) + (j - 1) ;Recto
|
||||
*PtrF\V1 = (i * P) + (j - 1) ;Recto
|
||||
*PtrF + #_SIZETRIS
|
||||
*PtrF\V1 = i * P + j
|
||||
*PtrF\V2 = ((i + 1) * P) + j
|
||||
*PtrF\V3 = (i * P) + (j - 1)
|
||||
*PtrF + #_SIZETRIS
|
||||
*PtrF\V3 = i * P + j ;Recto
|
||||
*PtrF\V2 = ((i + 1) * P) + j ;Recto
|
||||
*PtrF\V1 = (i * P) + (j - 1) ;Recto
|
||||
*PtrF + #_SIZETRIS
|
||||
Next j
|
||||
Next i
|
||||
|
||||
; The Poles
|
||||
For i = 0 To M - 1
|
||||
*PtrF\V3 = (M + 1) * P + 1
|
||||
*PtrF\V2 = (i + 1) * P
|
||||
*PtrF\V1 = i * P
|
||||
*PtrF + #_SIZETRIS
|
||||
*PtrF\V1 = (M + 1) * P + 1 ;Recto
|
||||
*PtrF\V2 = (i + 1) * P ;Recto
|
||||
*PtrF\V3 = i * P ;Recto
|
||||
*PtrF + #_SIZETRIS
|
||||
Next i
|
||||
|
||||
For i = 0 To M - 1
|
||||
*PtrF\V3 = (M + 1) * P
|
||||
*PtrF\V2 = i * P + (P - 1)
|
||||
*PtrF\V1 = (i + 1) * P + (P - 1)
|
||||
*PtrF + #_SIZETRIS
|
||||
*PtrF\V1 = (M + 1) * P ;Recto
|
||||
*PtrF\V2 = i * P + (P - 1) ;Recto
|
||||
*PtrF\V3 = (i + 1) * P + (P - 1) ;Recto
|
||||
*PtrF + #_SIZETRIS
|
||||
Next i
|
||||
|
||||
If CreateMesh(0,100)
|
||||
Protected Flag = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color
|
||||
SetMeshData(0,Flag,*VBuffer,NbSommet)
|
||||
SetMeshData(0,#PB_Mesh_Face,*IBuffer,NbTriangle)
|
||||
ProcedureReturn 1
|
||||
EndIf
|
||||
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
|
||||
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
Procedure UpdateMesh()
|
||||
Protected NbTriangle = 4 * Meridian * Parallele
|
||||
|
||||
Length + PasLength
|
||||
|
||||
If Length >= NbTriangle
|
||||
PasLength = 0
|
||||
Length = Nbtriangle
|
||||
EndIf
|
||||
|
||||
SetMeshData(0,#PB_Mesh_Face,*IBuffer,Length)
|
||||
EndProcedure
|
||||
4
Task/Draw-a-sphere/Run-BASIC/draw-a-sphere.run
Normal file
4
Task/Draw-a-sphere/Run-BASIC/draw-a-sphere.run
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
graphic #g, 300, 300 'create a graphic object
|
||||
#g place(100,100) 'place the drawing pen at 100,100
|
||||
#g circle(75) 'make a circle with radius 75
|
||||
render #g 'show it
|
||||
18
Task/Draw-a-sphere/XPL0/draw-a-sphere.xpl0
Normal file
18
Task/Draw-a-sphere/XPL0/draw-a-sphere.xpl0
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
def R=100, R2=R*R; \radius, in pixels; radius squared
|
||||
def X0=640/2, Y0=480/2; \coordinates of center of screen
|
||||
int X, Y, Z, C, D2; \coords, color, distance from center squared
|
||||
[SetVid($112); \set 640x480x24 graphics mode
|
||||
for Y:= -R to +R do \for all the coordinates near the circle
|
||||
for X:= -R to +R do \ 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:= sqrt(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
|
||||
]; \ shift color to upper limit of its range
|
||||
Point(X+X0, Y+Y0, C<<8+C); \green + blue = cyan
|
||||
];
|
||||
repeat until KeyHit; \wait for keystroke
|
||||
SetVid($03); \restore normal text mode
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue