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 asset = "pattern.jpg";
const path = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/2104200/";

const frame = new Frame("fit", 960, 960, "#000", "#333", asset, path);
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
   
		// the backings zoom in and out according to these boundaries
		let backingScale = 1;
		const backingMin = .45;
		const backingMax = 2;
		// the rotation speeds
		const rotationAmount = .05; // holder
		const innerRotationAmount = .15; // triangles
		// the edge length of a triangle in the hexagon
		const length = 200;
		const height = length/2*Math.sqrt(3); // grade 9

    // Hexagon class made with Triangle objects
    class Hexagon extends Container {
        constructor() {
            super();
            let angle = 0;
            let lastScale = 1;
            loop(6, i=>{
                let tc = new Container().addTo(this);
                let triangle = new Triangle(length, length, length)
                    .addTo(tc)
                    .reg(null, 0);
                lastScale *= -1; // mirror adjacent triangles
                patterns.push(
									pattern
										.clone()
										.addTo(tc)
										.sca(lastScale, 1)
										.setMask(triangle)
								);
                tc.rotation = angle;
                angle += 60;
            });
        }
    }

    // overall holder
    const holder = new Container().center();

    // container to hold image pattern so we can rotate and scale image inside
    const pattern = new Container();
		const backing = frame.asset("pattern.jpg")
        .centerReg(pattern)
        .loc(0, height/2)
        .sca(backingScale);

    // make the hexagons with triangles that mask the backings
    const patterns = []; // this will hold all pattern containers made
    const across = Math.ceil(stageW/length);
    const down = Math.ceil(stageH/height)+7; // fudge for rotation
    loop(across, i=>{
        loop(down, j=>{
            new Hexagon().addTo(holder)
                // obviously set the loc as follows:
                .loc(i*length*3+j%2*length*1.5, j*height);
        });
    });
    // write this code based on numbers in your dream
    holder.reg(holder.width/2-length*1.5, holder.height/2-height*2);


    // make backgrounds zoom in and out
    // and rotate and also rotate the overall holder
    let zoom = true;
    Ticker.add(()=>{
        if (zoom) {
            backingScale *= 1.002;
            if (backingScale > backingMax) {
                zoom = false;
                backingScale = backingMax;
            }
        } else {
            backingScale *= .998;
            if (backingScale < backingMin) {
                zoom = true;
                backingScale = backingMin;
            }
        }
        loop(patterns, pattern=>{
            let backing = pattern.getChildAt(0).sca(backingScale);
            backing.rotation += innerRotationAmount;
        });
        holder.rotation += rotationAmount;
        stage.update();
    });
  
    // DOCS FOR ITEMS USED
		// https://zimjs.com/docs.html?item=Frame
		// https://zimjs.com/docs.html?item=Container
		// https://zimjs.com/docs.html?item=Triangle
		// https://zimjs.com/docs.html?item=loop
		// 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=centerReg
		// https://zimjs.com/docs.html?item=center
		// https://zimjs.com/docs.html?item=setMask
		// https://zimjs.com/docs.html?item=loop
		// https://zimjs.com/docs.html?item=zog
		// https://zimjs.com/docs.html?item=Ticker
  

}); // end of ready
              
            
!
999px

Console