-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Namespacing files under Reprocessing_ - Add module signature files - Add docs - Convert to named arguments - Do some cleanup to the examples - Update README Now all required functions/values/types should be accessible from Reprocessing.re
- Loading branch information
Showing
30 changed files
with
1,644 additions
and
932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
open Reprocessing; | ||
|
||
/* https://www.youtube.com/watch?v=KkyIDI6rQJI | ||
Purple rain processing demo */ | ||
type dropT = { | ||
x: int, | ||
y: int, | ||
z: int, | ||
len: int, | ||
yspeed: int, | ||
color: colorT, | ||
time: int | ||
}; | ||
|
||
let make w (ymin, ymax) time => { | ||
let z = Utils.random min::0 max::20; | ||
{ | ||
x: Utils.random min::0 max::w, | ||
y: Utils.random min::ymin max::ymax, | ||
z, | ||
len: Utils.remap value::z low1::0 high1::20 low2::10 high2::20, | ||
yspeed: Utils.remap value::z low1::0 high1::20 low2::5 high2::15, | ||
color: | ||
Utils.lerpColor | ||
low::Constants.white | ||
high::(Utils.color r::138 g::43 b::226) | ||
amt::(Utils.randomf min::0.3 max::1.), | ||
time | ||
} | ||
}; | ||
|
||
type state = { | ||
lst: array dropT, | ||
running: bool, | ||
time: int | ||
}; | ||
|
||
let setup env => { | ||
Env.size width::640 height::360 env; | ||
Draw.fill (Utils.color r::255 g::0 b::0) env; | ||
Draw.noStroke env; | ||
let lst = Array.init 500 (fun _ => make (Env.width env) ((-500), (-50)) 0); | ||
{lst, time: 0, running: true} | ||
}; | ||
|
||
let draw {lst, running, time} env => { | ||
Draw.background (Utils.color r::230 g::230 b::250) env; | ||
Draw.fill (Utils.color r::255 g::0 b::0) env; | ||
Utils.randomSeed time; | ||
let lst = | ||
Array.map | ||
( | ||
fun drop => | ||
switch (drop.y + drop.yspeed * (time - drop.time)) { | ||
| y when y > Env.height env + 500 => | ||
make (Env.width env) ((-500), (-50)) time | ||
| y when y < (-500) => | ||
make | ||
(Env.width env) (Env.height env + 50, Env.height env + 500) time | ||
| _ => drop | ||
} | ||
) | ||
lst; | ||
Array.iter | ||
( | ||
fun drop => { | ||
Draw.fill drop.color env; | ||
Draw.ellipse | ||
center::(drop.x, drop.y + drop.yspeed * (time - drop.time)) | ||
radx::(Utils.remap value::drop.z low1::0 high1::20 low2::1 high2::3) | ||
rady::drop.yspeed | ||
env | ||
} | ||
) | ||
lst; | ||
{lst, running, time: running ? time + 1 : time} | ||
}; | ||
|
||
let mouseDown state _env => {...state, running: false}; | ||
|
||
let mouseUp state _env => {...state, running: true}; | ||
|
||
let mouseDragged ({time} as state) env => { | ||
let (pmouseX, _) = Env.pmouse env; | ||
let (mouseX, _) = Env.mouse env; | ||
let newTime = time - (pmouseX - mouseX); | ||
{...state, time: newTime} | ||
}; | ||
|
||
run ::setup ::draw ::mouseDown ::mouseUp ::mouseDragged (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open Reprocessing.Utils; | ||
open Reprocessing.Draw; | ||
open Reprocessing.Env; | ||
open Reprocessing.Constants; | ||
|
||
let setup env => { | ||
size width::640 height::640 env; | ||
noStroke env; | ||
0.01 | ||
}; | ||
|
||
let draw z env => { | ||
background (color r::230 g::230 b::250) env; | ||
let res = 100; | ||
let w = float_of_int (width env) /. float_of_int res; | ||
let h = float_of_int (height env) /. float_of_int res; | ||
for i in 0 to (res - 1) { | ||
for j in 0 to (res - 1) { | ||
fill | ||
( | ||
lerpColor | ||
white | ||
black | ||
(noise (0.03 *. float_of_int i) (0.03 *. float_of_int j) z) | ||
) | ||
env; | ||
rectf | ||
pos::(float_of_int i *. w, float_of_int j *. h) width::w height::h env | ||
} | ||
}; | ||
z +. 0.05 | ||
}; | ||
|
||
Reprocessing.run ::setup ::draw (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
open Reprocessing.Draw; | ||
open Reprocessing.Env; | ||
open Reprocessing.Utils; | ||
|
||
type state = (int, int); | ||
|
||
let squareSize = 300; | ||
|
||
let setup env => { | ||
size width::600 height::600 env; | ||
fill Reprocessing.Constants.red env; | ||
(0, 0) | ||
}; | ||
|
||
let draw squarePos env => { | ||
background (color r::150 g::255 b::255) env; | ||
let (sx, sy) = squarePos; | ||
let (px, py) = pmouse env; | ||
let (x, y) as squarePos = | ||
if ( | ||
mousePressed env && | ||
px > sx && px < sx + squareSize && py > sy && py < sy + squareSize | ||
) { | ||
let (mx, my) = mouse env; | ||
let dx = mx - px; | ||
let dy = my - py; | ||
(sx + dx, sy + dy) | ||
} else { | ||
squarePos | ||
}; | ||
rect pos::(x, y) width::squareSize height::squareSize env; | ||
squarePos | ||
}; | ||
|
||
Reprocessing.run ::setup ::draw (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** Contains functions having to do with drawing to the screen */ | ||
module Draw = Reprocessing_Draw; | ||
|
||
/** Contains functions having to do with the environment: | ||
* ie window properties, user input | ||
*/ | ||
module Env = Reprocessing_Env; | ||
|
||
/** Contains types for events. */ | ||
module Events = Reasongl.Gl.Events; | ||
|
||
/** Contains utility functions */ | ||
module Utils = Reprocessing_Utils; | ||
|
||
/** Contains useful constants */ | ||
module Constants = Reprocessing_Constants; | ||
|
||
include Reprocessing_Types.TypesT; | ||
|
||
/** Entrypoint to the graphics library. The system | ||
* is designed for you to return a self-defined 'state' | ||
* object from setup, which will then be passed to every | ||
* callback you choose to implement. Updating the state | ||
* is done by returning a different value from the callback. | ||
*/ | ||
let run: | ||
setup::(glEnvT => 'a) => | ||
draw::('a => glEnvT => 'a)? => | ||
mouseMove::('a => glEnvT => 'a)? => | ||
mouseDragged::('a => glEnvT => 'a)? => | ||
mouseDown::('a => glEnvT => 'a)? => | ||
mouseUp::('a => glEnvT => 'a)? => | ||
keyPressed::('a => glEnvT => 'a)? => | ||
keyReleased::('a => glEnvT => 'a)? => | ||
keyTyped::('a => glEnvT => 'a)? => | ||
unit => | ||
unit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
open Reprocessing_Common; | ||
|
||
let white = {r: 255, g: 255, b: 255}; | ||
|
||
let black = {r: 0, g: 0, b: 0}; | ||
|
||
let red = {r: 255, g: 0, b: 0}; | ||
|
||
let green = {r: 0, g: 255, b: 0}; | ||
|
||
let blue = {r: 0, g: 0, b: 255}; | ||
|
||
let pi = 4.0 *. atan 1.0; | ||
|
||
let two_pi = 2.0 *. pi; | ||
|
||
let half_pi = 0.5 *. pi; | ||
|
||
let quarter_pi = 0.25 *. pi; | ||
|
||
let tau = two_pi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** Convenience constant for the color white */ | ||
let white: Reprocessing_Common.colorT; | ||
|
||
/** Convenience constant for the color black */ | ||
let black: Reprocessing_Common.colorT; | ||
|
||
/** Convenience constant for the color red */ | ||
let red: Reprocessing_Common.colorT; | ||
|
||
/** Convenience constant for the color green */ | ||
let green: Reprocessing_Common.colorT; | ||
|
||
/** Convenience constant for the color blue */ | ||
let blue: Reprocessing_Common.colorT; | ||
|
||
/** pi is a mathematical constant with the value 3.1415927. It is the ratio of | ||
* the circumference of a circle to its diameter. It is useful in combination | ||
* with the trigonometric functions `sin` and `cos`. | ||
*/ | ||
let pi: float; | ||
|
||
/** half_pi is a mathematical constant with the value 1.5707964. It is half | ||
* the ratio of the circumference of a circle to its diameter | ||
*/ | ||
let half_pi: float; | ||
|
||
/** quarter_pi is a mathematical constant with the value 0.7853982. It is one | ||
* quarter the ratio of the circumference of a circle to its diameter. | ||
*/ | ||
let quarter_pi: float; | ||
|
||
/** two_pi is a mathematical constant with the value 6.2831855. It is twice the | ||
* ratio of the circumference of a circle to its diameter. | ||
*/ | ||
let two_pi: float; | ||
|
||
/** tau is a mathematical constant with the value 6.2831855. It is the circle | ||
* constant relating the circumference of a circle to its linear dimension, the | ||
* ratio of the circumference of a circle to its radius. It has the same value | ||
* as two_pi. | ||
*/ | ||
let tau: float; |
Oops, something went wrong.