Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              //REF: https://ianchen.thisistap.com/object-oriented-design/
canvas#mycanvas
            
          
!
            
              var sketchProc = function(processingInstance) {
 with(processingInstance) {
  size(400, 400);
  frameRate(30);

  /************************
   ****母親區Creature*******
   ************************/
  //1 Creature 共通屬性母建構子
  background(255, 255, 255);
  
  var Creature = function(nickname, age, x, y) {
   this.nickname = nickname;
   this.age = age + "yrs old";
   this.x = x;
   this.y = y;
  };
  //2 Creature Method  母建構子的共通行為
  Creature.prototype.talk = function() {
   text("SUPPP!?!?!?!??!", this.x - 40, this.y + 70);
  };

  /************************
   ****小孩1區Hopper********
   ************************/

  //3 繼承母屬性
  //4 省略小孩獨特屬性
  var Hopper = function(nickname, age, x, y) {
   Creature.call(this, nickname, age, x, y);
   //補充:增加小孩獨特屬性方法
   //this.cover = cover;
  };
  //5 繼承母行為method
  Hopper.prototype = Object.create(Creature.prototype);
  //6.1 增加小孩獨特行為method
  Hopper.prototype.draw = function() {

   /*fill(217, 90, 0);
   var img = getImage("creatures/Hopper-Happy");
   image(img, this.x, this.y);*/

   //face
   fill(230, 230, 250);
   ellipse(this.x, this.y, 60, 100);

   //eyes
   fill(0, 0, 0);
   line(this.x + 10, this.y - 25, this.x + 25, this.y - 25);
   line(this.x - 10, this.y - 25, this.x + 5, this.y - 25);

   //month
   fill(252, 65, 65);
   triangle(this.x, this.y + 20, this.x + 10, this.y + 10, this.x + 20, this.y + 20);
   //txt
   fill(0, 0, 139);
   var txt = this.nickname + ", " + this.age;
   text(txt, this.x - 40, this.y - 60);
  };
  //6.2 增加小孩獨特行為2
  Hopper.prototype.hooray = function() {
   text("Hooooray!!!", this.x - 30, this.y + 70);
  };

  /************************
   ****小孩2區Winston********
   ************************/

  //3 繼承母屬性
  //4 省略小孩獨特屬性
  var Winston = function(nickname, age, x, y) {
   Creature.call(this, nickname, age, x, y);
  };
  //5 繼承母行為method
  Winston.prototype = Object.create(Creature.prototype);
  //6 增加小孩獨特行為method
  
  Winston.prototype.draw = function() {
   // face
   fill(255, 255, 0);
   ellipse(this.x, this.y, 90, 90);
   // eyes
   fill(46, 46, 41);
   ellipse(this.x - 20, this.y - 20, 15, 15);
   ellipse(this.x + 24, this.y - 25, 15, 15);
   // mouth
   fill(252, 65, 65);
   ellipse(this.x + 13, this.y + 18, 40, 40);
   var txt = this.nickname + ", " + this.age;
   text(txt, this.x - 50, this.y - 60);
  };

  /**********資料建構完畢,下面印出來*************/

  /******呼叫Hopper跟Hopper2.0*********/

  //A 呼叫資料(等於建立小孩的物件資料)
  var lilHopper = new Hopper("Little Hopper", 15, 50, 240);
  var bigHopper = new Hopper("Big Hopper", 30, 50 + 200, 240);
  //B 呼叫行為(實體化)
  bigHopper.draw();
  bigHopper.hooray();
  lilHopper.draw();
  lilHopper.talk();

  /******呼叫Winston跟Winston2.0*********/

  //A 呼叫資料(等於建立小孩的物件資料)
  var winstonTeen = new Winston("Winsteen", 15, 50, 70);
  var winstonAdult = new Winston("Mr. Winst-a-lot", 30, 50 + 200, 70);
  //B 呼叫行為(實體化)
  winstonTeen.draw();
  winstonTeen.talk();
  winstonAdult.draw();
 }
};

// Get the canvas that Processing-js will use
var canvas = document.getElementById("mycanvas");
// Pass the function sketchProc (defined in myCode.js) to Processing's constructor.
var processingInstance = new Processing(canvas, sketchProc);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console