Draw a sphere: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(14 intermediate revisions by 7 users not shown) | |||
Line 1,318:
rem more info: https://www.dostips.com/forum/viewtopic.php?f=3&t=6744
rem integer sqrt arithmetic function by Aacini, penpen and
rem source: https://www.dostips.com/forum/viewtopic.php?f=3&t=5819&start=30#p44016
set "sqrt(N)=( M=(N),j=M/(11*1024)+40, j=(M/j+j)>>1, j=(M/j+j)>>1, j=(M/j+j)>>1, j=(M/j+j)>>1, j=(M/j+j)>>1, j+=(M-j*j)>>31 )"
Line 1,379:
set /a "sqrdR=R*R*100*100" %== R*R is mult. by 100*100 ==%
set "k=2" %== k is hardcoded to 2 ==%
set "ambient=%
rem start draw line-by-line
for /l %%i in (%negR%, 1, %R%) do (
Line 1,903:
{{out}}
[[Media:Draw a sphere cpp.png]]
=={{header|Clojure}}==
Line 1,993:
}
</syntaxhighlight>
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">let j = 2
for i = 221 to 0 step j * -1
for k = -3.14 to 3.14 step .01
dot 221 + i * sin(k), 222 + 221 * cos(k)
dot 221 + 221 * sin(k), 222 + (i - 1) * cos(k)
wait
next k
let j = j + 1
next i</syntaxhighlight>
=={{header|D}}==
Line 2,420 ⟶ 2,438:
</pre>
=={{header|Evaldraw}}==
Draw a sphere. We dont need to wrap the main () function with braces if we have no functions.
[[File:Evaldraw draw sphere.png|thumb|alt=A red sphere on a black background.|A red sphere, 5 units in front of camera.]]
<syntaxhighlight lang="C">
()
cls(0);
clz(1e32);
setcam(0,0,-5,0,0);
setcol(128,64,64);
drawsph(0,0,0,1);
</syntaxhighlight>
=={{header|Factor}}==
Line 2,630 ⟶ 2,663:
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum output 1
_sphereImageView
end enum
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 400, 400 )
window _window, @"Rosetta Code Sphere", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
r = fn CGRectMake( 20, 20, 360, 360 )
imageview _sphereImageView, YES, , r, NSImageScaleAxesIndependently, NSImageAlignCenter, NSImageFrameNone, _window
end fn
local fn SphereImageWithCIFilter( imageDimension as NSUInteger, sphereColor as ColorRef, backgroundColor as ColorRef, radiusBlur as float, radiusSphere as float ) as ImageRef
CIVectorRef civ = fn CIVectorWithXY( imageDimension/2, imageDimension/2 )
CIFilterRef filter = fn CIFilterWithName( @"CIRadialGradient" )
CIFilterSetDefaults( filter )
ObjectSetValueForKey( filter, civ, @"inputCenter" )
ObjectSetValueForKey( filter, fn NumberWithFloat( radiusBlur ), @"inputRadius0" )
ObjectSetValueForKey( filter, fn NumberWithFloat( radiusSphere ), @"inputRadius1" )
ObjectSetValueForKey( filter, fn CIColorWithCGColor( fn ColorCGColor( sphereColor ) ), @"inputColor0" )
ObjectSetValueForKey( filter, fn CIColorWithCGColor( fn ColorCGColor( backgroundColor ) ), @"inputColor1" )
ImageRef resultImage = fn ImageWithSize( fn CGSizeMake( imageDimension, imageDimension ) )
ImageLockFocus( resultImage )
CIImageDrawAtPoint( fn CIFilterOutputImage( filter ), CGPointZero, fn CGRectMake( 0, 0, imageDimension, imageDimension ), NSCompositeDestinationAtop, 1.0 )
ImageUnlockFocus( resultImage )
end fn = resultImage
local fn BuildSphere
ImageRef sphereImage = fn SphereImageWithCIFilter( 340, fn ColorWithRGB( 0.988, 0.335, 0.176, 1.0 ), fn ColorBlack, 0.0, 125.0 )
ImageViewSetImage( _sphereImageView, sphereImage )
end fn
fn BuildWindow
fn BuildSphere
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Rosetta Code Sphere.png]]
=={{header|Go}}==
Line 5,321 ⟶ 5,320:
{{out}}
[[Media:Draw a sphere rust.png]]
=={{header|Scala}}==
Line 5,810 ⟶ 5,809:
eeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeee</pre>
=={{header|V (Vlang)}}==
Graphical
<syntaxhighlight lang="Zig">
import gg
import gx
const (
win_width = 600
win_height = 600
)
struct App {
mut:
gg &gg.Context = unsafe {nil}
}
fn main() {
mut app := &App{
gg: 0
}
app.gg = gg.new_context(
bg_color: gx.white
width: win_width
height: win_height
create_window: true
window_title: 'Circle'
frame_fn: frame
user_data: app
)
app.gg.run()
}
fn frame(app &App) {
app.gg.begin()
app.draw()
app.gg.end()
}
fn (app &App) draw() {
app.gg.draw_circle_filled(300, 300, 150, gx.red)
}
</syntaxhighlight>
=={{header|Wren}}==
{{trans|C}}
<syntaxhighlight lang="
var light = [30, 30, -50]
Line 5,953 ⟶ 5,995:
next n
end sub</syntaxhighlight>
=={{header|Zig}}==
{{trans|Factor}}
{{libheader|raylib}}
<syntaxhighlight lang="zig">
const std = @import("std");
const c = @cImport({
@cInclude("raylib.h");
});
pub fn main() !void {
c.SetConfigFlags(c.FLAG_WINDOW_RESIZABLE | c.FLAG_VSYNC_HINT);
c.InitWindow(600, 480, "Draw a Sphere");
defer c.CloseWindow();
const camera = c.Camera3D{
.position = .{ .x = 4.5, .y = 4.5, .z = 4.5 },
.target = .{ .x = 0, .y = 0, .z = 0 },
.up = .{ .x = 0, .y = 1, .z = 0 },
.fovy = 45.0,
.projection = c.CAMERA_PERSPECTIVE,
};
c.SetTargetFPS(60);
while (!c.WindowShouldClose()) {
c.BeginDrawing();
defer c.EndDrawing();
c.ClearBackground(c.BLACK);
{
c.BeginMode3D(camera);
defer c.EndMode3D();
c.DrawSphereWires(.{ .x = 0, .y = 0, .z = 0 }, 2, 20, 20, c.LIME);
}
}
}
</syntaxhighlight>
=={{header|zkl}}==
|