Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
73
Task/Superellipse/Ada/superellipse.adb
Normal file
73
Task/Superellipse/Ada/superellipse.adb
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
with Ada.Numerics.Elementary_Functions;
|
||||
|
||||
with SDL.Video.Windows.Makers;
|
||||
with SDL.Video.Renderers.Makers;
|
||||
with SDL.Events.Events;
|
||||
|
||||
procedure Superelipse is
|
||||
|
||||
Width : constant := 600;
|
||||
Height : constant := 600;
|
||||
A : constant := 200.0;
|
||||
B : constant := 200.0;
|
||||
N : constant := 2.5;
|
||||
|
||||
Window : SDL.Video.Windows.Window;
|
||||
Renderer : SDL.Video.Renderers.Renderer;
|
||||
Event : SDL.Events.Events.Events;
|
||||
|
||||
procedure Draw_Superelipse
|
||||
is
|
||||
use type SDL.C.int;
|
||||
use Ada.Numerics.Elementary_Functions;
|
||||
Xx, Yy : Float;
|
||||
subtype Legal_Range is Float range 0.980 .. 1.020;
|
||||
begin
|
||||
for Y in 0 .. Height loop
|
||||
for X in 0 .. Width loop
|
||||
Xx := Float (X - Width / 2);
|
||||
Yy := Float (Y - Height / 2);
|
||||
if (abs (Xx / A)) ** N + (abs (Yy / B)) ** N in Legal_Range then
|
||||
Renderer.Draw (Point => (X => Width / 2 + SDL.C.int (Xx),
|
||||
Y => Height / 2 - SDL.C.int (Yy)));
|
||||
end if;
|
||||
|
||||
end loop;
|
||||
end loop;
|
||||
end Draw_Superelipse;
|
||||
|
||||
procedure Wait is
|
||||
use type SDL.Events.Event_Types;
|
||||
begin
|
||||
loop
|
||||
while SDL.Events.Events.Poll (Event) loop
|
||||
if Event.Common.Event_Type = SDL.Events.Quit then
|
||||
return;
|
||||
end if;
|
||||
end loop;
|
||||
delay 0.100;
|
||||
end loop;
|
||||
end Wait;
|
||||
|
||||
begin
|
||||
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
|
||||
return;
|
||||
end if;
|
||||
|
||||
SDL.Video.Windows.Makers.Create (Win => Window,
|
||||
Title => "Superelipse",
|
||||
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
|
||||
Size => SDL.Positive_Sizes'(Width, Height),
|
||||
Flags => 0);
|
||||
SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
|
||||
Renderer.Set_Draw_Colour ((0, 0, 0, 255));
|
||||
Renderer.Fill (Rectangle => (0, 0, Width, Height));
|
||||
Renderer.Set_Draw_Colour ((0, 220, 0, 255));
|
||||
|
||||
Draw_Superelipse;
|
||||
Window.Update_Surface;
|
||||
|
||||
Wait;
|
||||
Window.Finalize;
|
||||
SDL.Finalise;
|
||||
end Superelipse;
|
||||
50
Task/Superellipse/Pluto/superellipse.pluto
Normal file
50
Task/Superellipse/Pluto/superellipse.pluto
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
require "bitmap"
|
||||
|
||||
local bmp = bitmap.of(500, 500, color.black, "Superellipse")
|
||||
|
||||
local function superellipse(n, a)
|
||||
local hw = bmp:width() // 2
|
||||
local hh = bmp:height() // 2
|
||||
|
||||
-- Calculate y for each x.
|
||||
local y = {}
|
||||
for x = 1, a + 1 do
|
||||
local aa = a ^ n
|
||||
local xx = (x - 1) ^ n
|
||||
y[x] = math.round((aa - xx) ^ (1 / n))
|
||||
end
|
||||
|
||||
-- Draw quadrants.
|
||||
local prev = {hw + a, hh - y[a + 1]}
|
||||
for x = a - 1, 0, -1 do
|
||||
local curr = {hw + x, hh - y[x + 1]}
|
||||
bmp:line(prev[1], prev[2], curr[1], curr[2], color.white)
|
||||
prev = {curr[1], curr[2]}
|
||||
end
|
||||
|
||||
prev = {hw, hh + y[1]}
|
||||
for x = 1, a do
|
||||
local curr = {hw + x, hh + y[x + 1]}
|
||||
bmp:line(prev[1], prev[2], curr[1], curr[2], color.white)
|
||||
prev = {curr[1], curr[2]}
|
||||
end
|
||||
prev = {hw - a, hh + y[a + 1]}
|
||||
for x = a - 1, 0, -1 do
|
||||
local curr = {hw - x, hh + y[x + 1]}
|
||||
bmp:line(prev[1], prev[2], curr[1], curr[2], color.white)
|
||||
prev = {curr[1], curr[2]}
|
||||
end
|
||||
|
||||
prev = {hw, hh - y[1]}
|
||||
for x = 1, a do
|
||||
local curr = {hw - x, hh - y[x + 1]}
|
||||
bmp:line(prev[1], prev[2], curr[1], curr[2], color.white)
|
||||
prev = {curr[1], curr[2]}
|
||||
end
|
||||
end
|
||||
|
||||
-- Draw 200 concentric superellipses with gradually decreasing 'n'.
|
||||
for a = 200, 1, -1 do
|
||||
superellipse(a / 80, a)
|
||||
end
|
||||
bmp:view()
|
||||
6
Task/Superellipse/R/superellipse.r
Normal file
6
Task/Superellipse/R/superellipse.r
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
superellipse <- function(x,y) abs(x/200)^(2.5)+abs(y/200)^(2.5)-1
|
||||
x <- y <- seq(from=-200, to=200, length.out=1000)
|
||||
z <- outer(x, y, superellipse)
|
||||
png(filename="Superellipse-R.png", width=1000, height=1000)
|
||||
contour(x, y, z, levels=0)
|
||||
dev.off()
|
||||
60
Task/Superellipse/V-(Vlang)/superellipse.v
Normal file
60
Task/Superellipse/V-(Vlang)/superellipse.v
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import gg
|
||||
import gx
|
||||
import math
|
||||
|
||||
struct App {
|
||||
mut:
|
||||
n f64
|
||||
a int
|
||||
}
|
||||
|
||||
fn (mut app App) super_ellipse_points() []f32 {
|
||||
hw := 300.0
|
||||
hh := 200.0
|
||||
mut points := []f32{}
|
||||
mut y := []f64{len: app.a + 1}
|
||||
for x in 0 .. app.a + 1 {
|
||||
aa := math.pow(f64(app.a), app.n)
|
||||
xx := math.pow(f64(x), app.n)
|
||||
y[x] = math.pow(aa - xx, 1.0 / app.n)
|
||||
}
|
||||
for x := app.a; x >= 0; x-- {
|
||||
points << f32(hw + f64(x))
|
||||
points << f32(hh - y[x])
|
||||
}
|
||||
for x in 0 .. app.a + 1 {
|
||||
points << f32(hw + f64(x))
|
||||
points << f32(hh + y[x])
|
||||
}
|
||||
for x := app.a; x >= 0; x-- {
|
||||
points << f32(hw - f64(x))
|
||||
points << f32(hh + y[x])
|
||||
}
|
||||
for x in 0 .. app.a + 1 {
|
||||
points << f32(hw - f64(x))
|
||||
points << f32(hh - y[x])
|
||||
}
|
||||
return points
|
||||
}
|
||||
|
||||
fn frame(mut app App) {
|
||||
app.n = 2.5
|
||||
app.a = 200
|
||||
mut ctx := gg.Context{}
|
||||
ctx.begin()
|
||||
points := app.super_ellipse_points()
|
||||
ctx.draw_convex_poly(points, gx.white)
|
||||
ctx.end()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut context := gg.new_context(
|
||||
bg_color: gx.black
|
||||
width: 600
|
||||
height: 400
|
||||
window_title: "SuperEllipse"
|
||||
frame_fn: frame
|
||||
user_data: &App{}
|
||||
)
|
||||
context.run()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue