Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                const parts = [
    ["legs.png", "body.png", "fringe.png", "rightHair.png", "leftHair.png", "rightEar.png", "leftEar.png", "rightLashes.png", "leftLashes.png", "rightEye.png", "leftEye.png"],
    ["a_legs.png", "a_brain.png", "a_body.png", "a_rightEye.png", "a_leftEye.png", "a_rightBall.png", "a_leftBall.png", "a_rightLashes.png", "a_leftLashes.png"]
];
const assets = [{font:"Fungus" , src:"Fungus.otf"}, ...parts[0], ...parts[1]];
const path = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1604712/";
const waiter = new Waiter({corner:0, backgroundColor:dark});

const frame = new Frame("fit", 1024, 768, yellow, dark, assets, path, waiter);
frame.on("ready", ()=>{ // ES6 Arrow Function - similar to function(){}
    zog("ready from ZIM Frame"); // logs in console (F12 - choose console)

    // often need below - so consider it part of the template
    let stage = frame.stage;
    let stageW = frame.width;
    let stageH = frame.height;

    // REFERENCES for ZIM at http://zimjs.com
    // see http://zimjs.com/learn.html for video and code tutorials
    // see http://zimjs.com/docs.html for documentation
    // see https://www.youtube.com/watch?v=pUjHFptXspM for INTRO to ZIM
    // see https://www.youtube.com/watch?v=v7OT0YrDWiY for INTRO to CODE

    // CODE HERE
	
	 // We cut the aliens up into parts and will add them to ZIM Parallax 
	 // To get the locations, we can use the place() method 
	 // this reveals loc() x and y in the console once dragged and dropped
   
    // used this to get locations
    // loop(parts[1], p=>{
    //     frame.asset(p).center().place(p);
    // });
	
	 // We store unique aspects of the aliens in an array of alien objects 
	 // This allows us to use these object / data without cluttering our code
	 // The Parallax objects are in here too - one for x and one for y 
	 // Often, we can just use one Parallax object but in this case, we use custom input 
	 // and there is a unique Parallax object needed for each type of custom input 
	
	 // PARALLAX 
	 // Parallax works on layers - normally, the x position of the mouse changes the x 
	 // of the layers - with the layer behind moving less, etc. Same for y if desired. 
	 // This makes for a very easy format - see https://zimjs.com/docs?item=Parallax
	 // In this case, we are using the x and y position of a guide object - not the mouse x, and y 
	 // This is so we can change to various animations (dance, yes, no, etc.) 
	 // These animations are mostly set up by wiggling containers 
	 // We add the guide to the container with the right animation as we change the type
	 // In the FREE case, we are using a MotionController rather than a wiggle
	
	 // The aliens array holding objects with properties unique to each alien
 
    const aliens = [
        {
            body:new Container(),
            color:blue,
            parts:parts[0],
            locations:[[176, 370],[129, 183],[162, 374],[238, 226],[141, 220],[240, 261],[138, 259],[238, 272],[34, 267],[118, 338],[261, 338]],
            changes:[10, 30, 30, 35, 35, 37, 37, 60, 60, 50, 50],
            moveX:new Parallax({auto:false}),
            moveY:new Parallax({auto:false}),
            guide:new Circle(20,blue).alp(0).addTo()
        },
        {
            body:new Container(),
            color:pink,
            parts:parts[1],
            locations:[[484, 448],[442, 309],[436, 303],[589, 440],[380, 443],[600, 442],[394, 445],[533, 423],[331, 426]],
            changes:[10, 30, 25, 65, 65, 68, 68, 45, 45],
            moveX:new Parallax({auto:false}),
            moveY:new Parallax({auto:false}),
            guide:new Circle(20,pink).alp(0).addTo()
        }
    ];
	
	 // The containers for moving the guide    

    const dance = new Container(1,1)
        .reg(stageH/2)
        .loc(stageW/2,stageH/2)
        .wiggle({
            property:"rotation",
            baseAmount:0,
            minAmount:360*2,
            maxAmount:360*2,
            minTime:3000,
            maxTime:5000,
            ease:"linear"
        });
	
    const yes = new Container(1,1)
        .loc(stageW/2,stageH/2)
        .wiggle({
            property:"y",
            baseAmount:stageH/2,
            minAmount:stageH/2+50,
            maxAmount:stageH/2+50,
            minTime:400,
            maxTime:600,
        });
	
    const no = new Container(1,1)
        .loc(stageW/2,stageH/2)
        .wiggle({
            property:"x",
            baseAmount:stageW/2,
            minAmount:stageW/2-50,
            maxAmount:stageW/2-50,
            minTime:800,
            maxTime:900,
        });
	
    const free = new Container(1,1).addTo();
    new MotionController({target:free, type:"mousemove", mouseMoveOutside:true, speed:200, damp:1});

	 // Here we loop through the aliens and add the parts and Parallax layers 
	 // Note that we have two aliens - but this could easily be modified for any number 
	 // The only change would be in the overall positioning of the aliens 
	 // Simplifying code is one of the benefits of abstraction
	
	 const factor = .3; // for less movement in the y
    loop(aliens, (alien, j)=>{
        loop(alien.parts, (p, i)=>{
            var part = frame.asset(p).loc(alien.locations[i][0], alien.locations[i][1], alien.body);
			   // the split parameter makes it so x and y work from the middle not the top left corner
            alien.moveX.addLayer({obj:part, prop:"x", split:true, propChange:alien.changes[i]});
            alien.moveY.addLayer({obj:part, prop:"y", split:true, propChange:alien.changes[i]*factor});
        });
        alien.guide.loc(0,0,yes); // start off in the yes container wiggling up and down
        alien.body.center().mov(200-400*j, j*20).drag({all:true});
        frame.asset(alien.parts[1]).sha(alien.color, 0, 0, 100);
    });

	 // use a Ticker to step through the Parallax as auto is set to false 
	 // remember to take the localToGlobal point of the guide as it is sometimes in containers
    Ticker.add(()=>{
        loop(aliens, function (alien, i) {
            var point = alien.guide.localToGlobal(0,0)
            alien.moveX.step(point.x);
            alien.moveY.step(point.y);
            if (i==1) { // make second alien move opposite way
                if (tabs.selectedIndex==1) alien.moveX.step(stageW-point.x);
                if (tabs.selectedIndex==2) alien.moveY.step(stageH-point.y);
                if (tabs.selectedIndex==3) alien.moveX.step(stageW-point.x);
            }
        });
    });

	 // create the interface beneath the aliens
    STYLE = {
        type:{
            Tabs:{size:20}
        }
    }
    var tabs = new Tabs({
        color:blue,
        backgroundColor:"rgba(255,255,255,.4)",
        selectedBackgroundColor:blue,
        selectedColor:white,
        rollBackgroundColor:"rgba(255,255,255,.7)",
        width:stageW/2+50,
        corner:0,
        base:"none",
        height:45,
        spacing:10,
        tabs:["FREE", "DANCE", "YES", "NO", "RIGHT", "LEFT"]
    })
	 	.pos(0,0,false,true).ske(5).sca(.5).center(aliens[0].body).mov(0,180).change(change);
    tabs.selectedIndex = 2;
    tabs.alien = aliens[0];

    var tabs = tabs.clone()
	 	.pos(0,0,false,true).ske(5).sca(.5).center(aliens[1].body).mov(0,160).change(change);
    tabs.selectedIndex = 2;
    tabs.alien = aliens[1];
    tabs.selectedBackgroundColor = pink;
    tabs.color = pink;

	 // add the guide to the right animation container as the tabs change
    function change(e) {
        var tabs = e.target;
        if (tabs.text == "FREE") {
            tabs.alien.guide.loc(0,0,free);
        } else if (tabs.text == "DANCE") {
            tabs.alien.guide.loc(0,0,dance);
        } else if (tabs.text == "YES") {
            tabs.alien.guide.loc(0,0,yes);
        } else if (tabs.text == "NO") {
            tabs.alien.guide.loc(0,0,no);
        }  else if (tabs.text == "RIGHT") {
            tabs.alien.guide.loc(stageW,stageH/2,stage);
        } else if (tabs.text == "LEFT") {
            tabs.alien.guide.loc(0,stageH/2,stage);
        }
    };

    new Label("ZIM ... Stick Aliens", 130, "Fungus")
		 	.center().pos(null,30).ske(10).alp(.3);
	
	 
    stage.update(); // this is needed to show any changes
  
    // DOCS FOR ITEMS USED
	 // https://zimjs.com/docs.html?item=Frame
	 // https://zimjs.com/docs.html?item=Container
	 // https://zimjs.com/docs.html?item=Circle
	 // https://zimjs.com/docs.html?item=Label
	 // https://zimjs.com/docs.html?item=Button
	 // https://zimjs.com/docs.html?item=Waiter
	 // https://zimjs.com/docs.html?item=Tabs
	 // https://zimjs.com/docs.html?item=tap
	 // https://zimjs.com/docs.html?item=change
	 // https://zimjs.com/docs.html?item=drag
	 // https://zimjs.com/docs.html?item=wiggle
	 // https://zimjs.com/docs.html?item=loop
	 // https://zimjs.com/docs.html?item=sha
	 // https://zimjs.com/docs.html?item=pos
	 // https://zimjs.com/docs.html?item=loc
	 // https://zimjs.com/docs.html?item=mov
	 // https://zimjs.com/docs.html?item=alp
	 // https://zimjs.com/docs.html?item=ske
	 // https://zimjs.com/docs.html?item=reg
	 // https://zimjs.com/docs.html?item=sca
	 // https://zimjs.com/docs.html?item=addTo
	 // https://zimjs.com/docs.html?item=center
	 // https://zimjs.com/docs.html?item=place
	 // https://zimjs.com/docs.html?item=Parallax
	 // https://zimjs.com/docs.html?item=MotionController
	 // https://zimjs.com/docs.html?item=zog
	 // https://zimjs.com/docs.html?item=zgo
	 // https://zimjs.com/docs.html?item=STYLE
	 // https://zimjs.com/docs.html?item=Ticker 
	
    // FOOTER
	
	 // Please see a greeting message and then come visit us at https://zimjs.com
	 createGreet();
	
    // call remote script to make ZIM Foundation for Creative Coding icon
    createIcon(); 

}); // end of ready
              
            
!
999px

Console