June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,45 @@
graphsize 300,300
level = 12 : len =63 # initial values
x = 230: y = 285
rotation = pi/2
A1 = pi/27 : A2 = pi/8 # constants which determine shape
C1 = 0.7 : C2 = 0.85
dim xs(level+1) : dim ys(level+1) # stacks
fastgraphics
color black
rect 0,0,graphwidth,graphheight
refresh
color green
gosub tree
refresh
imgsave "Fractal_tree_BASIC-256.png", "PNG"
end
tree:
xs[level] = x : ys[level] = y
gosub putline
if level>0 then
level = level - 1
len = len*C1
rotation = rotation - A1
gosub tree
len = len/C1*C2
rotation = rotation + A1 + A2
gosub tree
rotation = rotation - A2
len = len/C2
level = level + 1
end if
x = xs[level] : y = ys[level]
return
putline:
yn = -sin(rotation)*len + y
xn = cos(rotation)*len + x
line x,y,xn,yn
x = xn : y = yn
return

View file

@ -0,0 +1,60 @@
'Fractal Tree - for Run Basic - 29 Apr 2018
'from BASIC256 - http://rosettacode.org/wiki/Fractal_tree#BASIC256
'copy this text and go to http://www.runbasic.com
WindowWidth = 500 'Run Basic max size 800 x 600
WindowHeight = 350
c = 255 '255 for white '0 for black
graphic #w, WindowWidth, WindowHeight
#w cls("black") 'black background color
#w color(c,c,c) 'changes color to white
level = 10 ' initial values
leng = 50
x = 230: y = 325 ' initial values x = 230: y = 285
pi = 3.1415
rotation = 3.1415/2
'A1 = pi/27 : A2 = pi/8 ' constants which determine shape
'C1 = 0.7 : C2 = 0.85 ' tree is drifted left
A1 = pi/9 : A2 = pi/9 ' constants which determine shape
C1 = 0.85 : C2 = 0.85 ' Symmetrical Tree
dim xs(level+1) : dim ys(level+1) ' stacks
print : print "Welcome to the Run BASIC Fractal Tree Program"
#w color("green") 'color green
gosub [tree]
render #w
' imgsave "Fractal_tree_BASIC-256.png", "PNG"
Print "Thank you and goodbye"
end
[tree]
xs(level) = x : ys(level) = y
gosub [putline]
if level>0 then
level = level - 1
leng = leng*C1
rotation = rotation - A1
gosub [tree]
leng = leng/C1*C2
rotation = rotation + A1 + A2
gosub [tree]
rotation = rotation - A2
leng = leng/C2
level = level + 1
end if
x = xs(level) : y = ys(level)
return
[putline]
yn = -1*sin(rotation)*leng + y
xn = cos(rotation)*leng + x
#w line(x,y,xn,yn)
x = xn : y = yn
return
'end of code
End

View file

@ -0,0 +1,5 @@
Spread = 25
Scale = 0.76
SizeX% = 400
SizeY% = 300
Depth% = 10

View file

@ -0,0 +1,16 @@
VDU 23,22,SizeX%;SizeY%;8,16,16,128
PROCbranch(SizeX%, 0, SizeY%/2, 90, Depth%)
END
DEF PROCbranch(x1, y1, size, angle, depth%)
LOCAL x2, y2
x2 = x1 + size * COSRAD(angle)
y2 = y1 + size * SINRAD(angle)
VDU 23,23,depth%;0;0;0;
LINE x1, y1, x2, y2
IF depth% > 0 THEN
PROCbranch(x2, y2, size * Scale, angle - Spread, depth% - 1)
PROCbranch(x2, y2, size * Scale, angle + Spread, depth% - 1)
ENDIF
ENDPROC

View file

@ -0,0 +1,57 @@
//Cargo deps :
// piston = "0.35.0"
// piston2d-graphics = "0.23.0"
// piston2d-opengl_graphics = "0.49.0"
// pistoncore-glutin_window = "0.42.0"
extern crate piston;
extern crate graphics;
extern crate opengl_graphics;
extern crate glutin_window;
use piston::window::WindowSettings;
use piston::event_loop::{Events, EventSettings};
use piston::input::RenderEvent;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use graphics::{clear, line, Context};
const ANG: f64 = 20.0;
const COLOR: [f32; 4] = [1.0, 0.0, 0.5, 1.0];
const LINE_THICKNESS: f64 = 5.0;
const DEPTH: u32 = 11;
fn main() {
let mut window: Window = WindowSettings::new("Fractal Tree", [1024, 768])
.opengl(OpenGL::V3_2)
.exit_on_esc(true)
.build()
.unwrap();
let mut gl = GlGraphics::new(OpenGL::V3_2);
let mut events = Events::new(EventSettings::new());
while let Some(e) = events.next(&mut window) {
if let Some(args) = e.render_args() {
gl.draw(args.viewport(), |c, g| {
clear([1.0, 1.0, 1.0, 1.0], g);
draw_fractal_tree(512.0, 700.0, 0.0, DEPTH, c, g);
});
}
}
}
fn draw_fractal_tree(x1: f64, y1: f64, angle: f64, depth: u32, c: Context, g: &mut GlGraphics) {
let x2 = x1 + angle.to_radians().sin() * depth as f64 * 10.0;
let y2 = y1 - angle.to_radians().cos() * depth as f64 * 10.0;
line(
COLOR,
LINE_THICKNESS * depth as f64 * 0.2,
[x1, y1, x2, y2],
c.transform,
g,
);
if depth > 0 {
draw_fractal_tree(x2, y2, angle - ANG, depth - 1, c, g);
draw_fractal_tree(x2, y2, angle + ANG, depth - 1, c, g);
}
}