All resent features on 360YEREVAN

image

As during 2 months we have added quite many functional and very soon we will change the whole interface, I thought to share all functional we have done so far and make sure that it has been validated by users.

First of all we have added “Add Story” draggable button. It is small round button that user can drag to any part of the screen and add story to that coordinates.

image

Another important feature we have added was Embed window from the menu icon. It is very easy to copy code from there for any Tour and embed it into HTML page, Blog post or even to Facebook Page’s tab.

image

And the last functional that we have added was tour sharing directly.

image

Happy hour at GeekdomSF.

The idea that ‘coding isn’t art’ is fast becoming a fossil of our time. I mean, I began painting on canvas and then found it was too messy, expensive and well, difficult in my location, so I was forced to experiment with digital art, partly inspired by David Hockney . And so I began with Artrage on my laptop, but I found out pretty quickly that my imagination was limited to the software, and unless I could code, I was limited to what I could and couldn’t do. Hence, the journey continued to software and programming with ProcessingJS  and Javascript, which I am manically studying, now.

What seemed like gobble-de-gook a few months ago is now taking some semblance of order, and I can see the potential of it all, the enormous cavern of creativity, linking art and code. 

When I learnt to speak Portuguese, it was a similar process. First, the sounds were complete mush, but then slowly, over a few months it all began to make sense, my confidence grew, and all of a sudden I could speak. Finding my voice with code, I imagine, will take in a similar set of emotions until I reach the point when I can say, ‘I´m producing art and code - yeehaa woop woop’. Of course, I´m not there yet, in fact I am a million miles away, but, each day I get closer and each month I can reflect on my progress.

It’s the first step,  in building a new career that includes tech, art, education and ‘social change’  - all the things I love. I don’t know where it will lead me, but I am not too worried about that either.

I´m sharing this, because I imagine other English teachers, artists, chefs, heck, anyone really, thinking about code as I did previously. Which was, ‘code and programming, oh God, how boring, how am I ever going to learn to code’. So, I spent a year thinking about it. Anyway, I´m stoked I´ve made the leap, and devoting the time. It’s far more rewarding than I had every imagined. So, get stuck in - you will not regret it.

Need inspiration? - visit Codeame here where you will find some inspiring artists. This is what Ian Winters says:

“As an artist Winters strives to make technology (if used) an essential, inseparable tool — but still to be fundamentally a tool for exploration rather than a means in itself.  Even when the conceptual or political material may be complex — such as explorations of memory & series; temporality, scale, and physical sites; exploration of the complex social relationship of technology and the landscape; and the intersections of live performance; the social and technology — Winters sees the emerging role of technology as one of a fundamental democratization and opening of individual and social possibility.”

Watch on gregbabula.com

Architecting large Single Page Applications with Knockout.js

This talk is about experiences of building large SPAs and maintaining them over time. In part, I’ll demonstrate pros and cons of various technology choices, such as TypeScript, Grunt, and AMD module optimisers. In part, I’ll demonstrate some Knockout.js-specific techniques, such as the new and powerful “components” feature that improves maintenance, testability, and runtime performance.

I finished building my website! Finally found the time and energy to dedicate three days to it.

I’m gonna be customizing my tumblrlrlrlr theme, and setting up a patreon in the near future too. A lot of overhauling is taking place. The absence of finished artwork isn’t me hitting a creative roadblock…quite the opposite, in fact! I’m just doing things behind-the-scenes.

You can check out the website here.

Excuse the lack of artwork in the portfolio galleries- I lost most my old art due to technical difficulties and the watermarks are extremely outdated which I can no longer edit. That, and my art did take a large leap in technical skill recently when I dedicated time to studying lighting, perspective etc - so everything else I’ve drawn prior looks so out of place. 

All images sans the social media buttons are mine, I have yet to hunt down the maker again but they were free//no credit needed (I’ll add a link to them somewhere tho when I track ‘em down again.)

Let me know what you think!

Long Time No Post != Long Time No Code

Haven’t been writing any personal posts lately, I guess I was just riding on the wave of how many people took interest in the Guide I created. :P

But as the title suggests, this doesn’t mean that I haven’t been active in my coding endeavors. I just didn’t realize that my new followers might actually want to hear about my personal progress, rather than watching me reblog random pictures. Hehe.

So literally 10 minutes ago I finished Codecademy’s HTML/CSS track, and my last little “Build Your Resume” project on there kinda sucks because I just wanted to complete the course. However, I feel that I’m very comfortable with the syntax, and now I feel even more confident that I’m choosing the correct path for a career: front-end dev. I like making things look pretty, okay? I like colors and graphics and buttons and things.
Oh and I knowww I’m not following the exact order of my guide, I have yet to finish the Tuts+ HTML/CSS course only because I like listening to music when I code, and with the Tuts+ things I have to watch/listen to videos (as opposed to Codecademy which is just written instruction). Though the Tuts+ teacher, Jeffrey Way, is awesome and his tutorials are super helpful! I’m going to be starting up again with those soon.

Also, the other day I finished my Programming for Everybody (Python) course on Coursera, which was gratifying, oh yeah and I finished the Python track on Codecademy before that as well. Python is really great, but I want to learn Ruby as well; Rails seems like an intriguing language to play with. So I also just signed up for a new Coursera course called Web Application Architecture, which teaches Ruby on Rails, and then I’m also going to follow the “Web Programming with Ruby on Rails” tutorials on University of Reddit (I love Reddit).

So yeah, that’s the plan for now. I’m gonna learn Javascript soon after the initial workload from the new courses subsides. OH WAIT. I also have college courses starting today. Shit, I forgot. Ugh okay so I’m also taking another HTML/CSS web dev course from a community college, along with Programming Fundamentals (taught in C), and a C# class, and possibly a C++ class and Multimedia class in October. Yes, I am crazy. Pray for me.

I’ll try to post updates more often, so that I don’t procrastinate and feel like I have to write long posts like this. Yeah. I’ll write like one paragraph. That’s okay right?

Gonna go make my brain explode. K bye.

Framework: Strongloop's Loopback

Framework: Strongloop’s Loopback for Node.js APIs

Recently I did a series for New Relic on three frameworks, both for APIs and web apps. I titled it “Evaluating Node.js Frameworks: hapi.js, Restify, and Geddy” and it is available via the New Relic Blog. To check out those frameworks give that blog entry a read, then below I’ve added one more framework to the list, Strongloop’s Loopback.

Strength: Very feature-rich generation of models, data…

View On WordPress

習作 1-2 視差滾動設計與 requestAnimationFrame

image

上一篇我們用了純粹的CSS來製作視差滾動,但是使用CSS的缺點非常明顯,就是IE系列無法使用。除此之外在各種不同瀏覽器版本中也會出現一些不一致的問題。所以若是要做出跨各種主流瀏覽器的視差滾動頁面,最終還是要回歸髒髒的JavaScript來解決。

正宗的視差滾動網頁實作技巧主要是用position absolute在各個圖層上,配上z-index做出前後順序。然後用JavaScript在onScroll事件上計算每個圖層應該移動多少距離。整個步驟中最複雜的是計算出每次Scroll每個圖層到底要對應移動多少。

那就開始來做吧。首先我們先做出最基本的網頁構造:

<div class=”parallax”>
  <div class=”parallax__group”>
    <div class=”parallax__layer parallax__layer—fore”>

    </div>

    <div class=”parallax__layer parallax__layer—base”>

    </div>

    <div class=”parallax__layer parallax__layer—back”>

    </div>

    <div class=”parallax__layer parallax__layer—deep”>
….
    </div>
  </div>
</div>

這邊的parallax__layer—deep是最底層,也是要移動最慢的一層,而越往上的移動速度就要越快。

網頁結構搞定之後,接著要把最主要的CSS建立起來。基本上它是重寫第一個習作的CSS檔案,將各種CSS3的屬性去除,加上所有要用JavaScript實作滾動視差所需的最基本定義:

      .parallax {
        width:100%;
        height:100vh;
        overflow-y:scroll
      }
      .parallax__group {
        position: relative;
        width:100%;
        height:100vh;
      }
      .parallax__layer {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
      .parallax__layer--fore {
        z-index:4;
      }
      .parallax__layer--base {
        z-index:3;
      }
      .parallax__layer--back {
        z-index:2;
      }
      .parallax__layer--deep {
        z-index:1;
      }

我們必須保證最外圍的容器必須有全螢幕的寬度(100%)與長度(100vh),並且用overflow-y=scroll強迫瀏覽器可以捲動容器內的各個圖層。

而在parallax__layer上我們規定position:absolute,這樣各個圖層就能彼此重疊。最後為每個圖層定義z-index,這樣不同圖層就有先後次序不同的堆疊順序了。

到目前為止,我們能得到一個排版正確,可以捲動但是各個圖層的捲動速度一樣的網頁,接下來就是JavaScript出場的時候了!

在寫JavaScript之前,我們必須幫每個圖層的移動速度做一下定義。在第一個習作中,每個圖層的移動速度是:

  1. deep層,66.66%
  2. back層,100% (基準圖層)
  3. base層,200%
  4. fore層,300%

也就是說每當back層捲動了一個螢幕的範圍,deep層只有移動了2/3層,而base層已經捲動兩個螢幕了,fore更是飛過了三個螢幕那麼多的內容。

當我們把移動速率決定之後,剩下的事情其實很簡單,就是把每個圖層都抓出來,然後在捲動事件裡面調整每個圖層的top值:

      var body = document.querySelector('.parallax'), scrollTop = 0;
      var lv0 = body.querySelector('.parallax__layer--deep'),
        lv1 = body.querySelector('.parallax__layer--back'),
        lv2 = body.querySelector('.parallax__layer--base')
        lv3 = body.querySelector('.parallax__layer--fore');
      body.addEventListener('scroll', function (e){
        scrollTop = body.scrollTop;
        lv0.style.top=parseInt(scrollTop * 0.333) + 'px';
        lv2.style.top=(scrollTop*-1) + 'px';
        lv3.style.top=(scrollTop*-2) + 'px';
      });

這邊的數字是這樣算出來的:假設我們目前在scrollTop = 100px時:

  • deep層(lv0)應該設定top=33px,所以相對於目前的捲動進度,它只移動了 100 - 33 = 67個象素。
  • back層(lv1)沒有調整,所以他就是移動了100個象素。
  • base層(lv2)設定成top=-100px,因為是負的100個象素,所以等於跑了100 - (-100) = 200個象素的距離。
  • fore層(lv3)設定成top=-200px,這樣等於飛了 100 - ( -200) = 300個象素。

這個測試頁面就是用此方法製作出來的視差滾動頁面。大家可以玩玩看,感受一下各大瀏覽器通用的視差滾動實作法。

image

除此之外,為了避免這次的習作內容太過單薄,讓我們來練習一下如何幫網頁的JavaScript做效能最佳化吧!

由於我們是使用onScroll事件做計算圖層移動的觸發點,因此很有可能會發生這樣的事情:

  1. 第0秒,使用者觸發onScroll事件,計算每個圖層的top
  2. 第0.01秒,使用者觸發onScroll事件,計算每個圖層的top
  3. 第0.02秒,使用者觸發onScroll事件,計算每個圖層的top
  4. 第0.03秒,瀏覽器啟動repaint,重畫整個視窗的物件

在這種情況,我們在瀏覽器重畫之前觸發了三次onScroll,也就等於重算了三次全部圖層的top,但是只有第三次的onScroll算出來的數值才會真的拿來重畫視窗,第一次與第二次的onScroll基本上是算心酸的,浪費了電池的電與CPU的運算能力。這在桌面環境或許不怎麼樣,但是在手機與平板等移動裝置上就很糟糕。

那怎麼辦呢?現代的瀏覽器都提供了一個方法可以,讓我們可以在該運算的時候才運算,就是本習作的另一個主題 — requestAnimationFrame。

微軟的技術文件有非常詳細的說明,基本的原理就是,瀏覽器的window物件提供了一個函數requestAnimationFrame,它接受一個callback函式,讓瀏覽器在真的要重畫之前才呼叫此callback函式一次。因此我們可以把所有重畫的邏輯都寫在callback裡面。

這個callback函式會傳入一個參數,代表該次重畫的時間。因為該次重畫前所有透過requestAnimationFrame註冊的callback函式都會拿到同樣的時間,所以使用者能用這個時間來防止同樣的callback重複呼叫。

講起來有點複雜,就讓code說話吧:

  1. 首先,我們定義一個函式來計算各個圖層的top:

            var doScroll = function (newScrollTop){
              lv0.style.top=parseInt(newScrollTop * 0.333) + 'px';
              lv2.style.top=(newScrollTop*-1) + 'px';
              lv3.style.top=(newScrollTop*-2) + 'px';
            };
    
  2. 之後,我們來定義requestAnimationFrame需要的callback函式:

            var prevAnimationTime = 0;
            var tickScroll = function (time) {
              if (prevAnimationTime === time){ return; }
              prevAnimationTime = time;
              doScroll(scrollTop);
            };
    

    這個函式的參數time就是重畫的時間點,我們拿time與上一個tickScroll函式執行的時間prevAnimationTime相比,如果一樣就代表有不只一個tickScroll在這次重畫時間執行過了,這樣我們就可以直接return,避免重複計算每個圖層的top

  3. 最後,我們改造onScroll事件的處理函式,讓它呼叫requestAnimationFrame來註冊瀏覽器重畫時要呼叫的函式:

            window.requestAnimationFrame = 
            window.requestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.webkitRequestAnimationFrame || 
            window.oRequestAnimationFrame;
        body.addEventListener('scroll', function (e){
            scrollTop = body.scrollTop;
            if (requestAnimationFrame){
              requestAnimationFrame(tickScroll);
            } else {
              doScroll(scrollTop);
            }
        });
    

    首先,由於各家瀏覽器對於requestAnimationFrame函式的名稱沒有統一,所以先將他整合成一個名稱。

    再來在onScroll的處理函式裡面驗證這個瀏覽器是否支援requestAnimationFrame,如果支援就把tickScroll這個函式傳進去,瀏覽器重畫時就會呼叫它了。

    如果瀏覽器太老舊,不支援這個方法,我們只好依照笨笨地每次onScroll都重算圖層的top值了。

這個效能調校之後的測試網頁在此,乍看之下跟前一個測試頁面一樣,沒有差異,但是這一頁的CPU負擔與耗能確實較低一些。

requestAnimationFrame這個函式並不常用在onScroll事件上,它最常用的時機是在手機等移動版頁面的動畫效果上,例如CSS無法做到的客製化動畫,像反覆變換透明度的圖示,不簡單的模塊或圖形移動,在老舊或廉價裝置上依照資源的多寡變動重畫動畫物件的頻率。這都是requestAnimationFrame最適合的場合。

Happy Coding Day!

"A callback function, also known as a higher-order function, is a function that is passed to another function (let’s call this other function “otherFunction”) as a parameter, and the callback function is called (executed) inside otherFunction. A callback function is essentially a pattern (an established solution to a common problem), and therefore, the use of a callback function is also known as a callback pattern."

Text
Photo
Quote
Link
Chat
Audio
Video