Skip to content

Instantly share code, notes, and snippets.

View mooman219's full-sized avatar
๐Ÿ„

mooo mooman219

๐Ÿ„
  • Seattle, Washington
View GitHub Profile
pub fn draw_line(&mut self, p0: &Point, p1: &Point) {
if p0.y == p1.y {
return;
}
let (dir, p0, p1) = if p0.y < p1.y {
(1.0, p0, p1)
} else {
(-1.0, p1, p0)
};
let dxdy = (p1.x - p0.x) / (p1.y - p0.y);
#[cfg(not(target_feature = "sse"))]
fn accumulate(src: &[f32]) -> Vec<u8> {
let mut acc = 0.0;
src.iter()
.map(|c| {
acc += c;
let y = acc.abs();
let y = if y < 1.0 {
y
} else {
public static void main(String[] args) {
JFrame w = new JFrame("Test");
w.add(new JComponent() {
/**
* This will draw a black cross on screen.
*/
protected void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, getHeight() / 2 - 10, getWidth(), 20);
extern crate log;
extern crate storm;
mod logger;
use cgmath::prelude::*;
use cgmath::*;
use log::LevelFilter;
use logger::*;
use storm::color::*;
extern crate log;
extern crate storm;
mod logger;
use cgmath::prelude::*;
use cgmath::*;
use log::LevelFilter;
use logger::*;
use storm::color::*;
pub fn tick(sprite: &mut SpriteDescription, particle: &mut Particle, delta: f32) {
let length_squared = particle.pos.x * particle.pos.x + particle.pos.y * particle.pos.y;
let length = f32::sqrt(length_squared);
let norm = particle.pos / length;
let norm_squared = particle.pos / length_squared;
particle.acceleration = -(norm * (Self::G * Self::MASS)).div_element_wise(norm_squared);
particle.velocity += particle.acceleration;
particle.pos += particle.velocity;
let velocity = particle.velocity + particle.acceleration * delta;
extern crate rand;
use rand::prelude::*;
use std::fmt;
#[derive(Debug, Clone)]
pub struct Item {
pub id: u32,
pub name: String,
}
const PI: f32 = 3.141592653589793238f32;
const PI_2: f32 = 1.570796326794896619f32;
const PI_NEG_2: f32 = -1.570796326794896619f32;
const CONST: f32 = 0.28087f32; // Trial and error
/// Average error of 0.00231 radians.
/// Largest error of 0.00488 radians.
/// Speedup of 20.67x over f32.atan2(y);
#[inline]
pub fn atan2(y: f32, x: f32) -> f32 {
~/Local/coffee (master) $ cargo run --example particles --release --features dx12,debug
Compiling coffee v0.2.0 (C:\Users\Mooma\Local\coffee)
Finished release [optimized] target(s) in 7.95s
Running `target\release\examples\particles.exe`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OutOfMemory(OutOfDeviceMemory)', src\libcore\result.rs:999:5
stack backtrace:
0: std::sys::windows::backtrace::set_frames
at /rustc/33fe1131cadba69d317156847be9a402b89f11bb\/src\libstd\sys\windows\backtrace\mod.rs:95
1: std::sys::windows::backtrace::unwind_backtrace
at /rustc/33fe1131cadba69d317156847be9a402b89f11bb\/src\libstd\sys\windows\backtrace\mod.rs:82
use std::cell::Cell;
use std::cell::UnsafeCell;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
const CACHELINE_LEN: usize = 64; // Usually 64 words
const CACHELINE: usize = CACHELINE_LEN / std::mem::size_of::<usize>();
#[repr(C)]
pub struct Buffer<T> {