Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/imagine.js/0.1.0/imagine.min.js"></script>
<div id="wrapper">
    <p>The text object has event handling and logs events.<p>
    <p id="loadingtime"></p>
    <canvas id="canvas" width="400" height="400"></canvas>
    <div id="console"></div>
</div>
              
            
!

CSS

              
                #wrapper {
    width: 820px;
}

#canvas {
    border: 1px dashed #f2f2f2;
    float: left;
}

#console {
    width: 400px;
    height: 400px;
    border: 1px solid #f2f2f2;
    float: right;
    overflow-y: auto;
}

              
            
!

JS

              
                var t1, t2,
    consoleEl = document.getElementById('console'),
    startTimer = function() {
        t1 = new Date().getTime();
        return t1;
    },
    stopTimer = function() {
        t2 = new Date().getTime();
        return t2 - t1;
    },
    randomIntFromInterval = function(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    },
    logToConsole = function(text) {
        consoleEl.insertAdjacentHTML('beforeend', text + '<br>');
    };

startTimer();
var c1 = new imagine.Canvas('canvas');

var rect = new imagine.Rectangle({
    top: 200
});

var circle = new imagine.Circle();

var text = new imagine.Text({
    top: 200,
    left: 150,
    font: 'Helvetica Neue',
    text: 'ImagineJS is simple!'
});

var imageObj = new Image();
imageObj.src = 'http://www.w3.org/html/logo/downloads/HTML5_Logo_512.png';
imageObj.addEventListener('load', function() {
    img = new imagine.Image(imageObj, {
        left: 30,
        top: 0,
        angle: 0,
        opacity: .5,
        width: 128,
        height: 128
    });
    c1.add(img);
}, false);

c1.add(circle);
c1.add(rect);
c1.add(text);

for (var i = 0; i < 15; i++) {
    var circle = new imagine.Circle({
        top: randomIntFromInterval(0, 400),
        left: randomIntFromInterval(0, 400),
        radius: randomIntFromInterval(2, 30),
        fill: '#' + Math.floor(Math.random() * 16777215).toString(16)
    });
    c1.add(circle);
}

logToConsole('Canvas objects loaded in ' + stopTimer() + 'ms');

text.on('dragging', function() {
    this.set({
        text: 'dragging'
    })
    c1.reDrawObjects();
    logToConsole('dragging');
});

text.on('mousedown', function() {
    this.set({
        text: 'mousedown'
    });
    c1.reDrawObjects();
    logToConsole('mousedown');
});

text.on('mouseup', function() {
    this.set({
        text: 'mouseup'
    })
    c1.reDrawObjects();
    logToConsole('mouseup');
});

text.on('mouseover', function() {
    this.set({
        text: 'mouseover'
    })
    c1.reDrawObjects();
    logToConsole('mouseover');
});

text.on('mouseout', function() {
    this.set({
        text: 'mouseout'
    });
    c1.reDrawObjects();
    logToConsole('mouseout');
});
              
            
!
999px

Console