Skip to content

Instantly share code, notes, and snippets.

@sbauer322
Created July 26, 2020 15:30
Show Gist options
  • Save sbauer322/560c4dc8ed061fb86d7dd9f156c61247 to your computer and use it in GitHub Desktop.
Save sbauer322/560c4dc8ed061fb86d7dd9f156c61247 to your computer and use it in GitHub Desktop.
Square stroke cap results in same behavior as butt stroke cap bug
use nannou::prelude::*;
/// Generative Artistry Blog, Tiled Lines
fn main() {
nannou::app(model)
.run();
}
struct Model {
}
fn model(app: &App) -> Model {
let _window = app.new_window()
.size(720, 720)
.view(view)
.build()
.unwrap();
Model { }
}
fn view(app: &App, _model: &Model, frame: Frame){
if app.elapsed_frames() == 1 {
let draw = app.draw();
draw.background().color(WHITE);
draw.rect()
.wh(app.window_rect().wh())
.color(WHITE);
let left = app.window_rect().left() as i32;
let right = app.window_rect().right() as i32;
let top = app.window_rect().top() as i32;
let bottom = app.window_rect().bottom() as i32;
let step = 60;
for i in (left..right).step_by(step) {
for j in (bottom..top).step_by(step) {
draw_line(&draw, i as f32, j as f32, step as f32, step as f32);
}
}
draw.to_frame(app, &frame).unwrap();
}
}
fn draw_line(draw: &Draw, x: f32, y: f32, w: f32, h: f32) {
let left_to_right = random_f32() >= 0.5;
if left_to_right {
let start_point = pt2(x, y);
let end_point = pt2(x+w, y+h);
draw.line()
.start(start_point)
.end(end_point)
// .caps_square()
// .caps_round()
.caps_butt()
.weight(10.0)
.color(PINK);
draw.rect()
.xy(start_point)
.w_h(2.0, 2.0)
.color(BLACK);
draw.rect()
.xy(end_point)
.w_h(2.0, 2.0)
.color(BLACK);
} else {
let start_point = pt2(x+w, y);
let end_point = pt2(x, y+h);
draw.line()
.start(start_point)
.end(end_point)
// .caps_square()
// .caps_round()
.caps_butt()
.weight(10.0)
.color(PINK);
draw.rect()
.xy(start_point)
.w_h(2.0, 2.0)
.color(BLACK);
draw.rect()
.xy(end_point)
.w_h(2.0, 2.0)
.color(BLACK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment