It's not over until you win

[Grasshopper] Fundamentals I-8. Object Expressions 본문

IT/Grasshopper

[Grasshopper] Fundamentals I-8. Object Expressions

캬옹몽몽이 2019. 1. 21. 18:32

8챕터. 


1-8-1. Custom Colors


Edit properties of an object

영어가 익숙하지 않아 단어의 의미를 명확하게 느끼지 못하니 object, property 뭐가 더 큰 범위에 속하는지 몸으로 느끼질 못한다.

연습해야만 알 수 있겠지.


예시로, 

var objectName = { propertyName : 'Coding is fun.', 

  otherPropertyName : 'this is also a key value' } ;

print ( objectName.propertyName ) ;   


그럼 'Coding is fun.'을 보여준다.

Object 안에 property가 있는거다. 


예시는 뭔가 어렵다. Magenta가 뭐냐? 마젠타라는 건 빨강과 파랑을 같은 비율로 섞을 때 나오는 색으로 분홍색과 비슷하지만 분홍색은 아니란다. 컴퓨터에서 색을 표현할 때 red, green, blue 에 각각 0 ~ 255의 값을 부여하면 여러 색을 표현할 수 있는데, Red 255, Green 0, Blue 255이면 Magenta의 색이 나올 수 있다. 음. 마젠타가 뭔질 알았더니 표현은 쉽다.


var someCustomColor = { red : 255. green : 0, blue : 255 } ;

print ( someCustomColor ) ;   



1-8-2. Which Transmission?


문제. transmission property의 값이 뭐냐고 물었다.

var car = { transmission : 'automatic', doors : 4, color : blue } ;



1-8-3. Make a Name for Yourself


var name = { first : 'Martin', middle : 'Luthuer', last : 'King' } ;

print ( name.first + name.middle + name.last ) ;   


여기서 first는 property이고, Martin은 property의 value 라는 걸 알려주기 위한 예시이다.



1-8-4. Accessed a Property


1-8-1을 다시 설명해준다.



1-8-5. Going Green


Instructions에 따라 그대로 했더니 Clear.

var rgbObject = { red : pickRandom(255), green : pickRandom(255), blue : pickRandom(255) } ;

if ( rgbObject.green>200 ) { drawBox (rgbObject) ; }

print (rgbObject) ;   



1-8-6. Which Color?


간단한 문제. 다음의 코드로 뭐가 나올꺼냐. 

var rgbObject = { red : 0, green : 0, blue : 255 } ;

drawBox (rgbObject) ; 



1-8-7. What's Sugar?


간단한 문제. 다음의 코드로 뭐가 나올꺼냐. 

var teacup = { red : 100, green : 50, blue : 50 } ;

var sugar = teacup.blue ;



1-8-8. Is It Blue Enough?


문제. blue가 10보다 크면 박스를 그려라. 라고 하려면 뭘 더 넣어야 하는가?

var rgbObject = { red : 128, green : 64, blue : 32 } ; 


if ( rgbObject.blue > 10 ) { drawBox (rgbObject) ; } 


Comments