[−][src]Crate metropolis
this crate is a high level easy to use graphics renderer inspired by processing in java and p5 in javascript. Working with it utilizes high level function like arc,line,rect and such that are you to make sveral canvases and display them as you wish. 3D is also coming and is currently under development(for now it's just 2D functions). the way to use the library is to use the size function to create a canvas with a fixed size(width,height), afterwards, you create some setup variable and setup the background for the animation/game/test/simulation you want to run, then you create a closure and save it to a variable, and finally send it to the show function(designed to loop over the draw function). like this (grvaity example):
use metropolis::*; use metropolis::color::*; fn main() { //here I set up the background, height, width,spd,and the position on y let height = 900; let width = 1200; size(width,height); let mut spd = 0; let mut posy = 0; background(grayscale(100)); let draw =move || { //inside the draw function I create the accelaration to simulate gravity spd+=1; if posy+50< height{ posy+=spd; } // and those are the library functions fill-which makes the filled color be pinkish // and circle which draws a circle with a center in 400(in x) and posy(changing y), with a //radius of 100. fill(rgb(255,0,100)); circle(400,posy,100); }; //finally I send the draw function into show like that(should be used without the commenting, //it's commented because it loopes over with no timeout //show(draw); }
or you can do something similar only with a safe canvas struct(take your pick for your use case: the public canvas struct(there is actually an inner one for the static functions). it is
use metropolis::color::*; use metropolis::canvas::Canvas; fn main(){ let height = 600; let width = 800; //size(width, height); let mut canv:Canvas= Canvas::new(width,height); canv.background(grayscale(100)); let draw = |mut canvas:Canvas|->Canvas { let curve_vec: Vec<[i64; 2]> = vec![ [0, 400], [30, 370], [50, 300], [75, 257], [80, 240], [150, 150], [250, 050], ]; canvas.bezierCurve(curve_vec); canvas }; canv.show(draw); }
as you may see the draw loop is designed a bit different.
Re-exports
pub use canvas::*; |
Modules
canvas | the canvas mod contains the canvas and image structs used to create multiple and multithreading safe canvases |
color | a module used for coloring in this crate, will be adding more functions and easier set in the future. |
elements | |
math | |
vector | a module to provide some mathematical help functions from the crate. Will be much expanded upon in the near future. |
Structs
Image | This struct is meant for loading and saving the image once and not every frame |
Enums
MouseButton | Describes a button of a mouse controller. |
keyCode | Symbolic name for a keyboard key. |
Statics
FPS | |
HEIGHT | |
WIDTH |
Functions
arc | create an arc from a circle, recieves the center of the circle and the radius and the degrees covered by the arc (360 degree arc is a full circle). |
background | sets the background color(using the color struct). |
bezierCurve | loopes over the array and uses curveVertex to create a bezier curve |
bezierCurveVertex | uses the cubic bezier curve algorithm in order to create a curve |
circle | recieves the x and y of the center of the circle and the radius and builds it with them. |
curve | loopes over the array and uses curveVertex to create a catmull rom chain curve |
curveVertex | uses the catmull rom chain algorithm in order to create a curve |
ellipse | recieves the x and the y of the center of the ellipse and the width and height of the ellipse and creates it accordingly |
fill | enables fill and receives the color of the fill(the struct color) and sets the fill color to be the color. |
get_modifiers | returns the current state of the modifiers |
img | takes a path to the image and loads it into an Image struct should strictly be used outside the draw loop! |
keyPressed | returns the current key that is pressed. |
line | recieves the x and y of the top point and then the x and the y of the bottom point and creates a line between them. |
lockKeyEvent | keeps the key pressed in the key event until a new key is pressed |
mouseClick | returns the current key that is pressed on the mouse. |
mouseScrollX | returns the x scroll delta of the mouse |
mouseScrollY | returns the y scroll delta of the mouse |
mouseX | returns the x position of the mouse |
mouseY | returns the y position of the mouse |
noFill | disables fill on the canvas. |
noStroke | disables stroke on the canvas. |
point | recieves the x and the y and makes a small circle in the spot(size depends on strokeWeight). |
quad | recieves the x and y of the 4 points of the quad and creates it based on them |
rect | recieves the x and y of the top spot and then the width and height of the rectangle you want built. |
show | this is the function used to run the animation |
size | creates the canvas with the width and height sent to this function |
square | recieves the x and y of the top spot and then the width of the sqaure you want built. |
stroke | enables stroke and receives the color of the stroke(the struct color) and sets the stroke color to be the color. |
strokeWeight | sets the stroke weight(the width of lines and points |
text | drawes a text of a certain color and locaion on the canvas |
textSize | recieves f32 ext size and sets the canvases text_size to that size |
triangle | recieves the x and y of the 3 points of the triangle and creates it based on them |