Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
100
Task/Death-Star/FreeBASIC/death-star-2.basic
Normal file
100
Task/Death-Star/FreeBASIC/death-star-2.basic
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
Type vector
|
||||
v(2) As Double
|
||||
End Type
|
||||
|
||||
Type sphere
|
||||
cx As Integer
|
||||
cy As Integer
|
||||
cz As Integer
|
||||
r As Integer
|
||||
End Type
|
||||
|
||||
Function dot(x As vector, y As vector) As Double
|
||||
Return x.v(0)*y.v(0) + x.v(1)*y.v(1) + x.v(2)*y.v(2)
|
||||
End Function
|
||||
|
||||
Sub normalizeVector(v As vector)
|
||||
Dim invLen As Double = 1.0 / Sqr(dot(v, v))
|
||||
v.v(0) *= invLen
|
||||
v.v(1) *= invLen
|
||||
v.v(2) *= invLen
|
||||
End Sub
|
||||
|
||||
Function hitSphere(s As sphere, x As Integer, y As Integer, z1 As Double Ptr, z2 As Double Ptr) As Boolean
|
||||
Dim xx As Integer = x - s.cx
|
||||
Dim yy As Integer = y - s.cy
|
||||
Dim zsq As Integer = s.r*s.r - (xx*xx + yy*yy)
|
||||
|
||||
If zsq >= 0 Then
|
||||
Dim zsqrt As Double = Sqr(zsq)
|
||||
*z1 = s.cz - zsqrt
|
||||
*z2 = s.cz + zsqrt
|
||||
Return True
|
||||
End If
|
||||
Return False
|
||||
End Function
|
||||
|
||||
Function createDeathStar(posic As sphere, neg As sphere, k As Double, amb As Double, direc As vector) As Any Ptr
|
||||
Dim As Integer w = posic.r * 4
|
||||
Dim As Integer h = posic.r * 3
|
||||
|
||||
Dim As Any Ptr img = Imagecreate(w, h, Rgb(0,0,0))
|
||||
|
||||
Dim vec As vector
|
||||
Dim As Double z1, z2, zs1, zs2
|
||||
|
||||
For y As Integer = posic.cy - posic.r To posic.cy + posic.r
|
||||
For x As Integer = posic.cx - posic.r To posic.cx + posic.r
|
||||
If hitSphere(posic, x, y, @z1, @z2) Then
|
||||
Dim hit As Boolean = hitSphere(neg, x, y, @zs1, @zs2)
|
||||
|
||||
If hit Then
|
||||
If zs1 > z1 Then hit = False
|
||||
If zs2 > z2 Then Continue For
|
||||
End If
|
||||
|
||||
If hit Then
|
||||
vec.v(0) = neg.cx - x
|
||||
vec.v(1) = neg.cy - y
|
||||
vec.v(2) = neg.cz - zs2
|
||||
Else
|
||||
vec.v(0) = x - posic.cx
|
||||
vec.v(1) = y - posic.cy
|
||||
vec.v(2) = z1 - posic.cz
|
||||
End If
|
||||
|
||||
normalizeVector(vec)
|
||||
Dim s As Double = dot(direc, vec)
|
||||
If s < 0 Then s = 0
|
||||
|
||||
Dim lum As Double = 255 * (s^k + amb) / (1 + amb)
|
||||
If lum < 0 Then lum = 0
|
||||
If lum > 255 Then lum = 255
|
||||
|
||||
Dim shade As Integer = lum
|
||||
Pset img, (x + w\2, y + h\2), Rgb(shade, shade, shade)
|
||||
End If
|
||||
Next x
|
||||
Next y
|
||||
|
||||
Return img
|
||||
End Function
|
||||
|
||||
' Main program
|
||||
Screenres 500, 400, 32
|
||||
Windowtitle "Death Star FreeBASIC"
|
||||
|
||||
Dim direct As vector
|
||||
direct.v(0) = 20
|
||||
direct.v(1) = -40
|
||||
direct.v(2) = -10
|
||||
normalizeVector(direct)
|
||||
|
||||
Dim posic As sphere = Type(0, 0, 0, 120)
|
||||
Dim neg As sphere = Type(-50, -50, -30, 75)
|
||||
|
||||
Dim img As Any Ptr = createDeathStar(posic, neg, 1.5, 0.2, direct)
|
||||
Put (0, 0), img
|
||||
Imagedestroy(img)
|
||||
|
||||
Sleep
|
||||
86
Task/Death-Star/FutureBasic/death-star-1.basic
Normal file
86
Task/Death-Star/FutureBasic/death-star-1.basic
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
_window = 1
|
||||
begin enum 1
|
||||
_circularView
|
||||
_OvalView
|
||||
end enum
|
||||
|
||||
void local fn BuildWindow
|
||||
CGRect r = fn CGRectMake( 0, 0, 400, 400 )
|
||||
window _window, @"Rosetta Code Death Star", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
|
||||
WindowSetBackgroundColor( _window, fn ColorBlack )
|
||||
|
||||
r = fn CGRectMake( 20, 20, 360, 360 )
|
||||
subclass view _circularView, r, _window
|
||||
|
||||
r = fn CGRectMake( 50, 170, 200, 180 )
|
||||
subclass view _OvalView,r, _circularView
|
||||
end fn
|
||||
|
||||
local fn OvalView( tag as NSInteger )
|
||||
CGRect r = fn ViewBounds( tag )
|
||||
ViewSetWantsLayer( tag, YES )
|
||||
CFArrayRef cols = @[fn ColorWithRGB(0.125,0.125,0.125,1),fn ColorWithRGB(0.425,0.425,0.4425,1),fn ColorWithRGB(0.725,0.725,0.725,1),fn ColorWithRGB(0.925,0.925,0.925,1),fn ColorWhite,fn ColorWhite ]
|
||||
|
||||
CALayerRef layer = fn CALayerInit
|
||||
ViewSetLayer( tag, layer )
|
||||
CALayerSetCornerRadius( layer, r.size.height / 2.0 )
|
||||
CALayerSetMasksToBounds( layer, YES )
|
||||
CALayerSetBorderWidth( layer, 0.25 )
|
||||
CALayerSetBorderColor( layer, fn ColorBlue )
|
||||
|
||||
CAGradientLayerRef gradLayer = fn CAGradientLayerInit
|
||||
CAGradientLayerSetColors( gradLayer, cols )
|
||||
CALayerSetCornerRadius( gradLayer, r.size.Height / 2.0 )
|
||||
CAGradientLayerSetStartPoint( gradLayer, fn CGPointMake(1,0) )
|
||||
CAGradientLayerSetEndPoint( gradLayer, fn CGPointMake(0,1) )
|
||||
CALayerSetShadowOffset( gradLayer, fn CGSizeMake( 10, -10 ) )
|
||||
CALayerSetShadowRadius( gradLayer, 3.0 )
|
||||
CALayerSetShadowOpacity( gradLayer, 0.4 )
|
||||
CALayerSetFrame( gradLayer, fn CGRectMake(0,0,200,200) )
|
||||
|
||||
CALayerAddSublayer( layer, gradLayer )
|
||||
end fn
|
||||
|
||||
local fn CircularView( tag as NSinteger )
|
||||
CGRect r = fn ViewBounds( tag )
|
||||
ViewSetWantsLayer( tag, YES )
|
||||
CFArrayRef cols = @[fn ColorWithRGB(0.125,0.125,0.125,1),fn ColorWithRGB(0.425,0.425,0.4425,1),fn ColorWithRGB(0.725,0.725,0.725,1),fn ColorWithRGB(0.925,0.925,0.925,1),fn ColorWhite,fn ColorWhite ]
|
||||
CALayerRef layer = fn CALayerInit
|
||||
|
||||
ViewSetLayer( tag, layer )
|
||||
CALayerSetCornerRadius( layer, r.size.width / 2.0 )
|
||||
CALayerSetMasksToBounds( layer, YES )
|
||||
CALayerSetBorderWidth( layer, 0.25 )
|
||||
CALayerSetBorderColor( layer, fn ColorBlack )
|
||||
|
||||
CAGradientLayerRef gradLayer = fn CAGradientLayerInit
|
||||
CALayerSetCornerRadius( gradLayer, r.size.width / 2.0 )
|
||||
CAGradientLayerSetColors( gradLayer, cols )
|
||||
CAGradientLayerSetStartPoint( gradLayer, fn CGPointMake( 0,0.2 ) )
|
||||
CAGradientLayerSetEndPoint( gradLayer, fn CGPointMake( 1,1 ) )
|
||||
CALayerSetShadowOffset( gradLayer, fn CGSizeMake( 10, -10 ) )
|
||||
CALayerSetShadowRadius( gradLayer, 3.0 )
|
||||
CALayerSetShadowOpacity( gradLayer, 0.4 )
|
||||
CALayerSetFrame( gradLayer, fn CGRectMake(0,0,360,360) )
|
||||
CALayerAddSublayer( layer, gradLayer )
|
||||
end fn
|
||||
|
||||
|
||||
void local fn DoDialog( ev as long, tag as long, wnd as long )
|
||||
select ( ev )
|
||||
case _viewDrawRect
|
||||
select ( tag )
|
||||
case _circularView : fn CircularView( tag )
|
||||
|
||||
case _OvalView : fn OvalView( tag)
|
||||
|
||||
end select
|
||||
case _windowWillClose : end
|
||||
end select
|
||||
end fn
|
||||
|
||||
on dialog fn DoDialog
|
||||
|
||||
fn BuildWindow
|
||||
|
||||
HandleEvents
|
||||
60
Task/Death-Star/FutureBasic/death-star-2.basic
Normal file
60
Task/Death-Star/FutureBasic/death-star-2.basic
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
_window = 1
|
||||
begin enum 1
|
||||
_circularView
|
||||
_ovalView
|
||||
end enum
|
||||
|
||||
void local fn BuildWindow
|
||||
CGRect r = fn CGRectMake( 0, 0, 400, 400 )
|
||||
|
||||
window _window, @"Death Star", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
|
||||
WindowSetBackgroundColor( _window, fn ColorBlack )
|
||||
|
||||
r = fn CGRectMake( 20, 20, 360, 360 )
|
||||
subclass view _circularView, r
|
||||
|
||||
r = fn CGRectMake( 0, 120, 200, 200 )
|
||||
subclass view _ovalView, r
|
||||
end fn
|
||||
|
||||
local fn OvalView( tag as NSInteger )
|
||||
CGRect r = fn ViewBounds( tag )
|
||||
r.size.height *= 0.5
|
||||
CFArrayRef cols = @[fn ColorWithWhite(0.8,1),fn ColorBlack]
|
||||
BezierPathRef path = fn BezierPathWithOvalInRect( r )
|
||||
GradientRef grad = fn GradientWithColors( cols )
|
||||
GraphicsContextSaveGraphicsState
|
||||
AffineTransformRef tx = fn AffineTransformInit
|
||||
NSPoint center = fn CGPointMake( fn CGRectGetMidX(r), fn CGRectGetMidY(r))
|
||||
center.x -= 25
|
||||
AffineTransformTranslate( tx, center.x, center.y )
|
||||
AffineTransformRotateByDegrees( tx, 52 )
|
||||
AffineTransformConcat( tx )
|
||||
GradientDrawInBezierPath( grad, path, 0.0 )
|
||||
GraphicsContextRestoreGraphicsState
|
||||
end fn
|
||||
|
||||
local fn CircularView( tag as NSinteger )
|
||||
CGRect r = fn ViewBounds( tag )
|
||||
CFArrayRef cols = @[fn ColorWithWhite(0.1,1),fn ColorWhite]
|
||||
BezierPathRef path = fn BezierPathWithOvalInRect( r )
|
||||
GradientRef grad = fn GradientWithColors( cols )
|
||||
GradientDrawInBezierPath( grad, path, 0.0 )
|
||||
end fn
|
||||
|
||||
void local fn DoDialog( ev as long, tag as long )
|
||||
select ( ev )
|
||||
case _viewDrawRect
|
||||
select ( tag )
|
||||
case _circularView : fn CircularView( tag )
|
||||
case _ovalView : fn OvalView( tag)
|
||||
end select
|
||||
case _windowWillClose : end
|
||||
end select
|
||||
end fn
|
||||
|
||||
on dialog fn DoDialog
|
||||
|
||||
fn BuildWindow
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue