Skip to content

Commit

Permalink
Merge pull request #1 from edeetee/master
Browse files Browse the repository at this point in the history
Fixed images, backgrounds, added niceties
  • Loading branch information
dribnet authored Aug 19, 2019
2 parents ae82dad + 62d6174 commit d1b40fd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phenakistoscopeJS",
"version": "1.1.0",
"version": "1.1.1",
"description": "A small framework built on top of p5js for automating the process of making phenakistoscopes with javascript. This framework is a part of the \"Creative Coding projects\" youtube channel.",
"homepage": "https://www.youtube.com/channel/UCQJBw4IgWV9Tp3CNgT5YtwA",
"repository": {
Expand Down
22 changes: 10 additions & 12 deletions sample_code/my_phenakistoscope.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ function setup_pScope(pScope){
}

function setup_layers(pScope){
var layer1 = new PLayer(animate1, background1);
//lets us draw the whole circle background, ignoring the boundaries
new PLayer(null, 220);

var layer1 = new PLayer(flowers);
layer1.mode( SWIRL(5) );
layer1.set_boundary( 400, 1000 );
layer1.set_boundary( 200, 1000 );

var layer2 = new PLayer(animate2, background2);
var layer2 = new PLayer(squares, radarBackground);
layer2.mode( RING );
layer2.set_boundary( 0, 400 );
}



function background1(animation, pScope){
}

function animate1(x, y, animation, pScope){
function flowers(x, y, animation, pScope){
translate(0, 0);
scale(animation.frame*2);
for (var i = 0; i < 12; i++) {
Expand All @@ -31,11 +29,11 @@ function animate1(x, y, animation, pScope){
ellipse(0,0,5,5);
}


function background2(animation, pScope){
function radarBackground(animation, pScope){
pScope.fill_background(200, 0, 0, 50*animation.frame)
}

function animate2(x, y, animation, pScope){
function squares(x, y, animation, pScope){
translate(0, 0);
rect(-10,-300-animation.wave()*50,20,20);
}
6 changes: 4 additions & 2 deletions src/PImageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default class PImageLoader{

load_image_sequence(name, file_type, sequence_length){
this._total_images_to_load += sequence_length;
for(var i = 0; i < image_count; ++i){
this._image_sequences[name] = []
for(var i = 0; i < sequence_length; ++i){
this._image_sequences[name][i] = loadImage("assets/"+name+"/"+name+"_"+i+"."+file_type, this.image_loaded.bind(this));
}
}
Expand All @@ -26,7 +27,8 @@ export default class PImageLoader{
}

draw_image_from_sequence(name, frame_lerp, ctx, x, y){
let frame = math.floor(frame_lerp*this._image_sequences[name].length);
let imgs = this._image_sequences[name].length
let frame = Math.floor(frame_lerp*imgs)%imgs
ctx.image(this._image_sequences[name][frame], x, y);
}

Expand Down
27 changes: 21 additions & 6 deletions src/PLayer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import globals from "./PGlobals.js"
import {animate_ring} from "./PAnimationFunctions.js"

function blank (){}

export default class PLayer{

constructor(i_draw_function, i_background_function){
this._draw_function = i_draw_function.bind(this);
this._background_function = i_background_function.bind(this);
constructor(i_draw_function, ...background){
i_draw_function = i_draw_function || blank
this._draw_function = i_draw_function.bind(this);

let background_t = typeof background[0]

if(background_t === "function")
this._background_function = background[0].bind(this);
else if(background_t !== "undefined"){
this._background_function = () => this.fill_background.call(this,...background)
} else
this._background_function = () => {}


this._animation_function = animate_ring(globals.phenakistoscope).bind(this);
this._do_draw_boundaries = true;
this.set_boundary(0,1000);
Expand Down Expand Up @@ -59,10 +72,12 @@ export default class PLayer{
return this._animation_variables;
}

fill_background(fill_color){
fill(fill_color);
stroke(fill_color);
fill_background(...args){
push()
fill(...args);
stroke(...args);
this.draw_wedge();
pop()
}

draw_boundry(){
Expand Down
2 changes: 0 additions & 2 deletions src/POutputFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ function set_initial_transforms(pScope){
}

function draw_wedge(pScope, layer, wedge_number){

push();
layer.animation_function(wedge_number, layer.boundary.low, layer.boundary.high);
pop();
layer.draw_boundry();

}

function draw_disk(pScope, layer){
Expand Down
11 changes: 6 additions & 5 deletions src/PScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export default class PScope{
this._draw_slits = do_draw;
}

fill_background(fill_color){
this._layers[this._current_layer].fill_background(fill_color);
fill_background(...color){
this._layers[this._current_layer].fill_background(...color);
}

set print(do_print){
Expand Down Expand Up @@ -197,11 +197,12 @@ export default class PScope{
load_image_sequence(name, file_type, sequence_length){
this._image_loader.load_image_sequence(name, file_type, sequence_length);
}

draw_image(name, x, y){
this._image_loader.draw_image(name, globals.p5js_default_gfx, x, y);
this._image_loader.draw_image(name, globals.p5, x, y);
}
draw_image_from_sequence(name, ctx, x, y){
this._image_loader.draw_image_from_sequence(name, this.frame, globals.p5js_default_gfx, x, y);
draw_image_from_sequence(name, x, y, lerp){
this._image_loader.draw_image_from_sequence(name, lerp, globals.p5, x, y);
}
//-----------------------------------------------------------

Expand Down

0 comments on commit d1b40fd

Please sign in to comment.