Nugroho's blog.: 2016

Friday, November 18, 2016

Pendengar

Kinanthi: Loh, gak berangkat jumatan to Meg?
Megatruh: Ntar dulu, masih khotbah, nanti aja dekat-dekat dengan sholat.

K: Bisa ya?
M: Lha biasanya gitu

K: Lha kalo semua kayak kamu, pas jumatan bisa saja khotib khotbah sendiri tanpa ada yang mendengarkan.

Wednesday, November 16, 2016

Princess


Kinanthi: Ngapain Meg, senyum-senyum sendiri?
Megatruh: Halo, Kin

K: Heh,
M: Habis baca cerita

K: Princess and The Pea?
M: Loh?

K: Yang kamu pegang itu
M: Eh, iya

K: Kayaknya dongeng anak itu bukan cerita humor deh
M: Memang, tapi ceritanya itu lho, entah mendidik atau gimana

K: Seingatku ada pangeran yang sedang mencari istri
M: Iya, mengundang empat putri dari empat kerajaan yang berbeda

K: Trus setelah pesta, keempat putri itu tidur di tumpukan dua puluh kasur...
M: ...yang sebelumnya diselipkan sebuah kacang polong untuk masing-masing putri

K: Oh iya, dan putri-putri itu tidur nyenyak kecuali satu. Dia tidak bisa tidur karena merasa ada sesuatu yang mengganjal di kasurnya.
M: Nah, bagiku ini lucu. Karena pangeran memilih menikah dengan putri yang tak bisa tidur ini.

K: oh
M: Mungkin pesan moralnya adalah seorang putri yang baik akan dapat menemukan ketidaksempurnaan sekecil apapun.

K: hm
M: Tapi aku berpikir, ini si putri kok manja banget ya. Sudah untung dapat kasur dua puluh tumpuk. Eh gak bisa tidur gara-gara kacang polong. Seakan tidak mensyukuri sesuatu yang besar.

Friday, October 28, 2016

Kesetimbangan



Dua bulan lalu di dinding kamar mandi mulai ada beberapa serangga seperti laron tetapi berukuran kecil,  sedikit lebih besar dari nyamuk. Semakin hari semakin banyak.

Tidak bisa diusir, disemprot pakai obat nyamuk pun tidak mati. Sampai saya membakar obat nyamuk di dalam kamar mandi pagi hari sebelum ngampus. Sorenya mereka tetap berada pada tempatnya, ckckck.

Sebulan yang lalu, mereka mulai berkurang, malah agak drastis. Tanpa diapa-apakan. Awalnya penasaran, apakah memang mereka pindah tempat atau yang lain. Sudahlah, yang penting mereka berangsur-angsur hilang.

Sampai suatu malam, tengah malam, ketika kebelet pipis. Di kamar mandi sedang ada sekitar lima cicak yang sedang berpesta pora, makan si serangga tadi. :)

Sekarang jadi suka senyum kalo lihat cicak-cicak gendut malas-malasan di dinding saat mandi pagi, :)


Thursday, September 1, 2016

Motivasi.

Ndak usah dipaksa maju jika tujuannya ada dibelakang.

Wednesday, August 31, 2016

Dalai Lama's Quote.

If you think you are too small to make a difference, try sleeping with a mosquito.

Tuesday, August 30, 2016

Pulang dari Kampus.


Alfa: Ayah, tadi jatuh pas naik sepeda gajah, berdarah. Ndak mandi, nanti perih.

(Sambil menunjukkan jempol kaki yang kulitnya terkelupas)

:)

Kangen.

Kinanthi: Lama nggak ngobrol ya Meg.

Meg: Iya Kin, lha sekarang semua sibuk ngurusi Mukidi.

K: (senyum)

Friday, August 19, 2016

Transmit serial data to an Android device, :)


.(Independent multitasking LEDs blink using Arduino FreeRTOS, and send the data wirelessly using bluetooth module HC-05. :) )



http://ift.tt/2b4YNBe.

the code is same as here

Independent Wireless Multitasking LEDs blink using Arduino FreeRTOS



and send the data wirelessly using bluetooth module HC-05. :)



http://ift.tt/2bi4MpP.
The code
#include <Arduino_FreeRTOS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

int n = 0;

// define two tasks for Blink & AnalogRead
void TaskBlink( void *pvParameters );
void TaskBlink2( void *pvParameters );
void TaskBlink3( void *pvParameters );
void TaskBlink4( void *pvParameters );
void TaskTadaa( void *pvParameters );

// the setup function runs once when you press reset or power the board
void setup() {
   // initialize serial communication at 9600 bits per second:
  mySerial.begin(9600);  

  // Now set up two tasks to run independently.
  xTaskCreate(
    TaskBlink
    ,  (const portCHAR *)"Blink"   // A name just for humans
    ,  128  // Stack size
    ,  NULL
    ,  2  // priority
    ,  NULL );
  xTaskCreate(TaskBlink2,(const portCHAR *)"Blink2",128, NULL,2,NULL );
  xTaskCreate(TaskBlink3,(const portCHAR *)"Blink3",128, NULL,2,NULL );
  xTaskCreate(TaskBlink4,(const portCHAR *)"Blink4",128, NULL,2,NULL );

  xTaskCreate(
    TaskTadaa
    ,  (const portCHAR *) "Tadaa"
    ,  128 // This stack size can be checked & adjusted by reading Highwater
    ,  NULL
    ,  1  // priority
    ,  NULL );

  // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}

void loop()
{
  // Empty. Things are done in Tasks.
}

/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/

void TaskBlink(void *pvParameters)  // This is a task.
{
  (void) pvParameters;

  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

  for (;;) // A Task shall never return or exit.
  {
    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
    mySerial.println("LED 13 Nyala");
    vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    mySerial.println("LED 13 Padam");
    vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
  }
}
void TaskBlink2(void *pvParameters){
  (void) pvParameters;
  pinMode(2, OUTPUT);
  for (;;) {
    digitalWrite(2, HIGH); vTaskDelay( 2000 / portTICK_PERIOD_MS );mySerial.println("LED 2 Nyala");
    digitalWrite(2, LOW);  vTaskDelay( 2000 / portTICK_PERIOD_MS );mySerial.println("LED 2 Padam"); 
  }
}

void TaskBlink3(void *pvParameters){
  (void) pvParameters;
  pinMode(3, OUTPUT);
  for (;;) {
    digitalWrite(3, HIGH); vTaskDelay( 500 / portTICK_PERIOD_MS );mySerial.println("LED 3 Nyala");
    digitalWrite(3, LOW);  vTaskDelay( 1500 / portTICK_PERIOD_MS );mySerial.println("LED 3 Padam"); 
  }
}

void TaskBlink4(void *pvParameters){
  (void) pvParameters;
  pinMode(4, OUTPUT);
  for (;;) {
    digitalWrite(4, HIGH); vTaskDelay( 500 / portTICK_PERIOD_MS );mySerial.println("LED 4 Nyala");
    digitalWrite(4, LOW);  vTaskDelay( 250 / portTICK_PERIOD_MS );mySerial.println("LED 4 Padam"); 
  }
}

void TaskTadaa(void *pvParameters)  // This is a task.
{
  (void) pvParameters;
  for (;;)
  {
    // read the input on analog pin 0:
    n++;
    if (n>100){n = 0;}
    // print out the value you read:
    mySerial.print("Tadaa...");
    mySerial.println(n);
    vTaskDelay(2000/portTICK_PERIOD_MS);// 2 second delay
    // one tick delay (15ms) in between reads for stability
  }
}

Thursday, August 18, 2016

Independent LEDs Blinking



 using Arduino FreeRTOS, realtime multi tasking, :)

 I programmed LED on pin 2, 3, 4 and 13 to blink at its own time. The advantage of this Arduino FreeRTOS is we don't have to calculate the timing of each pin in respect of sequential execution. It's has its own task and schedule, independent of each other.



http://ift.tt/2b4jwFJ.


#include <Arduino_FreeRTOS.h>
int n = 0;

// define two tasks for Blink & AnalogRead
void TaskBlink( void *pvParameters );
void TaskBlink2( void *pvParameters );
void TaskBlink3( void *pvParameters );
void TaskBlink4( void *pvParameters );
void TaskTadaa( void *pvParameters );

// the setup function runs once when you press reset or power the board
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

// Now set up two tasks to run independently.
xTaskCreate(
TaskBlink
, (const portCHAR *)"Blink" // A name just for humans
, 128 // Stack size
, NULL
, 2 // priority
, NULL );
xTaskCreate(TaskBlink2,(const portCHAR *)"Blink2",128, NULL,2,NULL );
xTaskCreate(TaskBlink3,(const portCHAR *)"Blink3",128, NULL,2,NULL );
xTaskCreate(TaskBlink4,(const portCHAR *)"Blink4",128, NULL,2,NULL );

xTaskCreate(
TaskTadaa
, (const portCHAR *) "Tadaa"
, 128 // This stack size can be checked & adjusted by reading Highwater
, NULL
, 1 // priority
, NULL );

// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}

void loop()
{
// Empty. Things are done in Tasks.
}

/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/

void TaskBlink(void *pvParameters) // This is a task.
{
(void) pvParameters;

// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);

for (;;) // A Task shall never return or exit.
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("LED 13 Nyala");
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
Serial.println("LED 13 Padam");
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
}
}
void TaskBlink2(void *pvParameters){
(void) pvParameters;
pinMode(2, OUTPUT);
for (;;) {
digitalWrite(2, HIGH); vTaskDelay( 2000 / portTICK_PERIOD_MS );Serial.println("LED 2 Nyala");
digitalWrite(2, LOW); vTaskDelay( 2000 / portTICK_PERIOD_MS );Serial.println("LED 2 Padam");
}
}

void TaskBlink3(void *pvParameters){
(void) pvParameters;
pinMode(3, OUTPUT);
for (;;) {
digitalWrite(3, HIGH); vTaskDelay( 500 / portTICK_PERIOD_MS );Serial.println("LED 3 Nyala");
digitalWrite(3, LOW); vTaskDelay( 1500 / portTICK_PERIOD_MS );Serial.println("LED 3 Padam");
}
}

void TaskBlink4(void *pvParameters){
(void) pvParameters;
pinMode(4, OUTPUT);
for (;;) {
digitalWrite(4, HIGH); vTaskDelay( 500 / portTICK_PERIOD_MS );Serial.println("LED 4 Nyala");
digitalWrite(4, LOW); vTaskDelay( 250 / portTICK_PERIOD_MS );Serial.println("LED 4 Padam");
}
}

void TaskTadaa(void *pvParameters) // This is a task.
{
(void) pvParameters;
for (;;)
{
// read the input on analog pin 0:
n++;
if (n>100){n = 0;}
// print out the value you read:
Serial.print("Tadaa...");
Serial.println(n);
vTaskDelay(2000/portTICK_PERIOD_MS);// 2 second delay
// one tick delay (15ms) in between reads for stability
}
}

Arduino FreeRTOS


(Real Time Operating System).

Multi Tasking on Arduino Nano.

Led Blink and Serial Communication



http://ift.tt/2b30d2l.
#include

int n = 0;

// define two tasks for Blink & AnalogRead
void TaskBlink( void *pvParameters );
void TaskTadaa( void *pvParameters );

// the setup function runs once when you press reset or power the board
void setup() {


// Now set up two tasks to run independently.
xTaskCreate(
TaskBlink
, (const portCHAR *)"Blink" // A name just for humans
, 128 // Stack size
, NULL
, 2 // priority
, NULL );

xTaskCreate(
TaskTadaa
, (const portCHAR *) "Tadaa"
, 128 // This stack size can be checked & adjusted by reading Highwater
, NULL
, 1 // priority
, NULL );

// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}

void loop()
{
// Empty. Things are done in Tasks.
}

/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/

void TaskBlink(void *pvParameters) // This is a task.
{
(void) pvParameters;

// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);

for (;;) // A Task shall never return or exit.
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
}
}

void TaskTadaa(void *pvParameters) // This is a task.
{
(void) pvParameters;

// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

for (;;)
{
// read the input on analog pin 0:
n++;
if (n>100){n = 0;}
// print out the value you read:
Serial.print("Tadaa...");
Serial.println(n);
vTaskDelay(2000/portTICK_PERIOD_MS);// 2 second delay
// one tick delay (15ms) in between reads for stability
}
}

Wednesday, August 10, 2016

Can not Detect Arduino Nano on El Capitan?

It because the nano used CH341 usb to serial adapter that will not install because El Capitan enforces kext driver signing.

So, I trace the step from https://tzapu.com/making-ch340-ch341-serial-adapters-work-under-el-capitan-os-x/

...and it works again, :)

To disable kext signing:

- Reboot and press CMD+R immediately after the chime to enter Recovery Mode
- Open Terminal from Recovery mode
- run the command csrutil enable --without kext
- run the command reboot







Monday, August 1, 2016

Old Mechanical Keyboard KPT-102 on iPad



Old Clicky Mechanical Keyboard on iPad, using Arduino as PS/2 to HID signal converter, :)

I use the code from https://gist.github.com/DorianRudolph/ca283dfdfd185bc812b7

But, as I use OSX, I can'n do this

"To make the programs work you need to open the file hardware/arduino/avr/cores/arduino/USBAPI.h located in your Arduino folder and make the Keyboard_::sendReport method public.
"

To do that I open the Finder, go to Applications Folder right click Arduino App, select Show Package Content and adit Keyboard.h at /Applications/Arduino.app/Contents/Java/libraries/Keyboard/src

Update: I tucked the Arduino  Pro Micro inside keyboard, :)


















http://ift.tt/2aIwnlw.

Saturday, July 30, 2016

Upload Sketch of Arduino Pro Micro on Standart IDE



Yup, we could choose Leonardo to upload sketch to Arduino Pro Micro, without Sparkfun addOn.



http://ift.tt/2amv1Lr.

Wednesday, July 13, 2016

Logis


Gendis: Duh, gawat.
Megatruh: kenapa nDhis?
G: Aku di-tag sama pacar baruku.
M: Bagus kan?
G: Masalahnya dia nge-tag aku di akun fb-ku
M: Memangnya kenapa?
G: Lha kan pacarku kan nanti tahu
M: Ya jelas to? Kan yang posting pacarmu sendiri.
G: Bukan, eh, iya, maksudku pacar-pacarku yang lain kan jadi tahu.
M: Walah
G: Memang lupa sih, biasanya kalo habis jadian pasti kubilang jangan nge-tag atau nyebut nama di medsos. Yang ini lupa, hehehe
M: ….

#edisiError

Sunday, July 3, 2016

Kebijakan

Jangan minder misal tak berprestasi akademik
Juga misal tak berprestasi non akademik
Atau cuma jadi pembuat onar
Atau tukang tidur di kelas
Siapa tahu di masa depan nanti
kamu jadi penentu kebijakan
yang ditakuti
sekaligus bikin pusing orang
yang saat ini adalah temanmu
yang paling pandai di kelas





#edisiError


Monday, June 13, 2016

Freebsd


 Have you encountered error like this when install kde on FreeBSD?

sysctl: unknown oid 'compat.linux.osrelease'

linuxulator is not (kld)loaded, exiting


 If it's so, then just do like this

#kldload linux


But it tell that no linux module on the system. Well, just install it

cd /usr/src/sys/modules/linux

make install clean


Ehm, there's more error

compat.linux.osrelease: 2.6.16 is not supported freebsd


apparently we have to edit the .conf manually


# printf "compat.linux.osrelease=2.6.18\n" >> /etc/sysctl.conf

# sysctl compat.linux.osrelease=2.6.18

# pkg install emulators/linux_base-c6


OK, back to kde install sequence, :)

# pkg install xorg

# pkg install nvidia-driver

# pkg install virtuoso

# pkg install kde

# pkg install gtk-oxygen-engine

# pkg install kde-gtk-config


Add to /boot/loader.conf:

linux_load="YES"

nvidia_load="YES"

Add to /etc/rc.conf:

dbus_enable="YES"

hald_enable="YES"

kdm4_enable="YES"


Load new kernel modules:

# kldload linux

# kldload nvidia


Create ~/.xinitrc for KDE (just this single line here):

exec /usr/local/kde4/bin/startkde


And we are good to go, :)

Malang saat Juni.

 Sangat menyenangkan mandi di air sedingin es setelah badan berselimut tebal semalaman.

Friday, June 3, 2016

To Tu Do Du.


 Pagi, mau bikin kopi.

 "Ibuk..."

 Adek jalan ke dapur.

 "Loh, adik sudah bangun, pinter" Kataku sambil buka stoples gula.

 "Ibuk" sambil meluk kakiku

 "Ibuk masih mandi, dek". Kuisi gelas dengan tiga sendok teh gula, (ehm, harusnya sendok kopi, err..., sendok gula, ...)

 "Ayah, ibuk mandi?"

 "Iya" Kataku sambil menaruh stoples gula ke rak plastik hijau  di atas meja.

 "Ayah bikin tupi?"

 "Iya, ayah bikin kopi"

"Ayok yah, to dopan" katanya mengajak ke depan. Gak jadi bikin kopi.

Adek nggandheng tanganku, diajak ke ruang tamu.

"Adek damun tendili"




"Iya pinter, adek bangun sendiri"

"Ayah, pintunya dibuka"

Kubuka pintu depan.

"Ayah, pake tatu"

Kupakaikan sepatu orange favorit baru-nya.

"Ke Dude" katanya sambil menarik tanganku, minta diantar.

"Loh, ke rumah Budhe? Gak mandi dulu"

"Mandi sama Dude saja" Kata adek.

"Ndak tunggu maem?" Biasanya habis mandi ibuk langsung menyiapkan bekal Alfa Beta tuk dimakan di rumah Budhe.

Seakan teringat sesuatu "Bawa iPad", walah

"Iya, ayah ambilkan"

Kuambil iPad coklat, adek nunggu di depan rumah, di jalan.

Kami gandhengan tangan ke rumah Budhe.

"Ayah, ada gukguk dahat" Katanya saat lewat rumah tetangga baru yang punya anjing gak henti-hentinya menggonggong

"Hehehe iya, ada gukguk jahat"

"Kalo Pabo, pintel" katanya lagi. Hm, kayaknya dia belajar hal baru lagi dari mas-nya

"Iya, kalo Pablo pinter, diam, gak teriak-teriak". Pablo adalah anjing pitbull tepat di samping rumah.

"Ayah, ke lumah mbah"

"Besok ya dek"

"Ayah masih tekolah?"

"Iya, ayah masih sekolah."

"Besok ke mbah naik dobil melah?"

"Iya, naik mobil merah"

"Adek pake dodet?"

"Ya ndak, kalo naik mobil gak usah pake jaket"

"Iya"

"Mau apa di rumah mbah dek?"

"Main sama Hahel"

"Dek Nahl". Dia secara alami menyebut seseorang dengan nama tanpa embel-embel dek atau mas atau mbak.

"Main sama adek Hahel"

"Trus apa lagi"

"Bilang mbah dodet balu"

"Joget baru? Yang mana, yang megal-megol kan mbah sudah tahu"

"Dodet haipaif"

"Oh, joget hi5 sama mas?"

"Iya.  Ayah, ayah, ada dunung" katanya adek sambil lihat ke gunung kawi

"Iya, ada gunung"

"Dunungnya ditutup awan putih"

"Iya"

"Bulan pumama-nya masih bubuk?"

"Iya, bulan purnamanya-masih bubuk"

Belok di pertigaan belakang rumah budhe.

"Ayah, dunungnya ditutup bambu"

"Iya" memang ada rumpun bambu di samping rumah budhe. Menutup pandangan ke arah gunung.

Sampai di rumah Budhe, adek membuka sendiri pintu samping yang langsung berbatasan dengan tempat cuci piring. Terdengar suara denting gelas yang sedang dicuci budhe.

"Dudee...."

"Waduh cantiknya,, baru bangun ya" Kata budhe yang memang sudah siap begitu dengar suara adek

"Tadi damun sendiri"

"Ooo, bangun sendiri, ayok digodokkan air dulu sama budhe, trus mandi ya?" kata budhe.

"Iya"

"Ayah bangunkan mas dulu ya dek" Kataku.

"Iya, maem"

(Sang Pengunyah selalu ingat , :) )

"Iya, nanti ayah bawakan, dadah...."

####

Siklus yang mirip berlanjut ke sang kakak, :)

####


Sore:

"Ibuk, ambilkan totet" Kata adek sambil pegang shuttlecock ke ibuknya yang sedang serius lihat pertandingan badminton di TV.

"Apa dek?"

"Mau main totet sama mas"

"oh, raket to?"

:)


Thursday, June 2, 2016

Collision.





 Here's the Code
#code
from visual import *
from random import uniform

display(center=(0,2,0),background=(1,1,1), autoscale=False, range=4.5,
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)

Ball = sphere(radius=2, length=4, opacity=.3)

Bola = []
n = 5
for i in arange (n):
bola = sphere(color=color.green,radius=uniform(.2,.73))
bola.pos = vector(uniform(-1.5,1.5),uniform(-1.5,1.5),uniform(-1.5,1.5))
bola.v = vector(uniform(-1,1),uniform(-1,1),uniform(-1,1))
Bola.append(bola)

dt = 1./16

def pantul():
global Bola
for bola in Bola:
r = bola.pos
v = bola.v
if mag(r)>=Ball.radius:
r = 1.9*norm(r)
vp = (dot(v,norm(r)))*norm(r)
vr = v-vp
v = vr - vp
bola.r = r
bola.v = v
for i in arange (n-1):
for j in range(i+1, n):
ri = Bola[i].pos
rj = Bola[j].pos
vi = Bola[i].v
vj = Bola[j].v
rc = rj-ri
if Bola[i].radius+Bola[j].radius>mag(rc):
vpi = dot(vi,norm(rc))*norm(rc)
vri = vi-vpi
vpj = -dot(vj,norm(rc))*norm(rc)
vrj = vj-vpj

vi = vpj+vri
vj = vpi+vrj

Bola[i].v = vi
Bola[i].v = vj

def proses():
for bola in Bola:
r = bola.pos
v = bola.v
a = vector(0,0,0)
v += a*dt
r += v*dt

bola.pos = r

pantul()

while 1:
rate(37)
proses()

.

Wednesday, June 1, 2016

Jaket Norak Kuning Menyala.


 Banyak fungsinya.

 Tidak dingin saat ngampus pagi-pagi

 Atau saat pulang dari kampus malam-malam

 Bisa berfungsi sebagai jas hujan karena anti air. Tapi percuma juga karena celana juga tetap basah.  Fungsi jaket norak kuning ini adalah melindungi tubuh bagian atas. Celanaku tidak kugunakan di tubuh bagian atas, jadi tetap basah.

 Agak mendingan untuk jalan ke parkiran saat hujan. Ada hoodie-nya.

 Yang paling penting, dengan memakai jaket norak kuning menyala secara konsisten setiap hari, satpam penjaga gerbang jadi hafal dan tak perlu menunjukkan STNK untuk keluar kampus.

 Sepertinya mereka berpikir hanya satu orang di kampus ini yang berani memakai jaket model gitu. Dan karena maling pun males mencuri jaket gituan, maka yang melintas tiap hari dengan jaket yang warnanya bikin sakit mata itu pasti hanya satu orang yang sama.

 :)



 #Naya
 #edisiError

The Trials of Apollo: The Hidden Oracle


 “Percy waved vaguely toward the north. “She’s in Boston for a few weeks. Some family emergency. The point is—”

 Excerpt From: Rick Riordan. “The Hidden Oracle.”

 So, the timeline is about the same time as Magnus Chase  The Sword of Summer

 Rick is very busy this last year, :)

Sunday, May 29, 2016

Bouncing Ball inside a Cone


  I use vector projection and rejection to calculate velocity after bouncing the side of cone, :)





#code
from visual import *
from random import uniform

display(center=(0,2,0),background=(1,1,1), autoscale=False, range=4.5,
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)

Cone = cone(pos = (0,0,0), axis=(0,5,0), radius = 3, opacity = .2)


bola = sphere(color=color.green,radius=.2)
bola.y = 1
bola.x = -1
bola.z = 1

v = vector(1,-1,0)
dt = 1./16
r = bola.pos
rc = Cone.radius
h = vector(Cone.axis)

def pantul():
global r,v
#tumbukan dengan lantai
if r.y<0:
r.y = 0
v.y *= -1

rp = vector(r.x,0,r.z)
hb = h.y - r.y
rmaks = hb/h.y*rc
c = h-rmaks*norm(rp) #vektor garis singgung
#selimut kerucut dengan bidang singgung
#tumbukan dengan selimut kerucut
if mag(rp)>rmaks:
rp = norm(rp)*rmaks
r = vector(rp.x,r.y,rp.z)
vp = dot(v,norm(c))*norm(c)
v = 2*vp-v
print v



def proses():
global r,v
a = vector(0,0,0)
v += a*dt
r += v*dt

bola.pos = r

pantul()

while 1:
rate(37)
proses()

.

Daun Jatuh.

 Megatruh: Apa-apaan ini Kin?

 Kinanthi: Apanya yang apa-apaan Meg?

 M: Puisimu ini?

 K: Kamu baca puisiku? Wow, horee..., aku punya tambahan penggemar

 M: Puisinya bagus...

 
 K: ...dari nol penggemar menjadi satu pengemar...

 M: ...tapi tak logis.

 K: ...dan semua penggemarku, yang cuma satu itu, bilang bagus.

 M: Yeah, tapi gak logis.

 K: Gakpapa, yang penting ada bagus-nya.

 M: Masak disini kamu tulis Daun jatuh tak membenci angin.  Lha jelas daun yang jatuh gara-gara angin itu kan daun tua yang kering, tentu saja pasrah saja dia tertiup angin.

 K: Puisi kan gak perlu logis to Meg.

 M: Ini bukan puisi penambah semangat.

 K: Memang bukan. Puisiku yang ini tentang pasrah setelah berusaha.

 M: Lha kalau gambarannya daun jatuh karena angin, berarti pasrah sampai tua dong.

 K: Eh, iya juga.

 M: Harusnya bikin yang menambah semangat atau tahan banting atau bertahan semacam Daun yang kuat takkan jatuh sekalipun badai.

 K: Wah, trims Meg, ide bagus buat bahan puisi baruku

 M: ... 

Saturday, May 28, 2016

Wednesday, May 25, 2016

Bouncing Ball inside Sphere


from visual import *
from random import uniform

display(center=(0,2,0),background=(1,1,1), autoscale=False, range=4.5,
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)

Ball = sphere(radius=2, length=4, opacity=.3)


bola = sphere(color=color.green,radius=.2)
bola.y = 1
bola.x = -1
bola.z = 1

v = vector(2,1,0)
dt = 1./16
r = bola.pos
rc = Ball.radius

def pantul():
global r,v
if mag(r)>=rc:
r = 1.99*norm(r)
vp = (dot(v,norm(r)))*norm(r)
vr = v-vp
v = vr - vp

def proses():
global r,v
a = vector(0,0,0)
v += a*dt
r += v*dt

bola.pos = r

pantul()

while 1:
rate(37)
proses()


.


Tuesday, May 24, 2016

Bouncing inside Cylinder




from visual import *
from random import uniform

display(center=(0,2,0),background=(1,1,1), autoscale=False, range=4.5,
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)

silinder = cylinder(radius=2, length=4, opacity=.3)
silinder.rotate(angle=pi/2, axis=(0,0,1),origin=(0,0,0))


bola = sphere(color=color.green,radius=.2)
bola.y = 0
bola.x = 0
bola.z = 1

v = vector(2,0,0)
dt = 1./16
r = bola.pos
rc = silinder.radius

def pantul():
global r,v
if mag(r)>=rc:
r = 1.9*norm(r)
vp = (dot(v,norm(r)))*norm(r)
vr = v-vp
v = vr - vp

def proses():
global r,v
a = vector(0,0,0)
v += a*dt
r += v*dt

bola.pos = r

pantul()

while 1:
rate(7)
proses()

.

Dot Product

Saturday, May 21, 2016

Thursday, May 12, 2016

Bounce Over Spherical Surface










#code
from visual import *
from random import uniform


display(center=(0,2,0),background=(1,1,1), autoscale=False, range=7.5,        
        width=600, height=600,  forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)

ball        = sphere(radius=2, color=color.red, opacity = .5)
r2          = ball.radius
silinder    = cylinder(radius=2, length=4, opacity=.3)
silinder.rotate(angle=pi/2, axis=(0,0,1),origin=(0,0,0))


bola        = sphere(color=color.green,radius=.2)
bola.y      = 3
bola.x      = uniform(-1,1)
bola.z      = uniform(-1,1)


v           = vector(0,2,0)
dt          = 1./8.
r           = bola.pos

def pantul():
    global r,v
    print v
    if mag(r)<r2:
        print mag(r)
        arah    = norm(r)
        dv      = dot(v,arah)
        v       -= dv*arah
        r       = (r2+.2)*arah
    
    

def proses():
    global r,v
    a   = vector(0,-1,0)
    v   += a*dt
    r   += v*dt

    bola.pos  = r

    pantul()

    

while 1:
    rate(11)
    proses()

.




Tuesday, May 10, 2016

N-Spring System

 Using Visual Python

 I like the result, :)

#code
from visual import *

n = 13
display(center=(n/2,0,0),background=(1,1,1), autoscale=False, range=(7),
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.orange)
dt = 1./8.
dx = []
k = []
m = []
l0 = []
l = []
v = []
x = []
for i in arange(n):
dx.append(.1)
k.append(1.)
m.append(1.)
l0.append(1.)
l.append(1.)
v.append(0.)
x.append(0.)
pegas = []
kotak = []

for i in arange(n):
spring = helix(pos=(0,0,0), axis=(5,0,0), radius=0.2, color=color.red, length=1.)
pegas.append(spring)
ko = box(pos=(0,0,0), width=.5, height=.5, length= .5, color= color.green)
kotak.append(ko)

box(pos=(-1,.64,0), width=n, height=2, length= 2, color=color.black)
box(pos=(n/2.,-.36,0), width=n, height=.2, length= n, color=color.white,opacity=.9)

#usikan
l[0] = 1.2
l[n-1] = .9
#posisi x
position = 0
for i in arange(n):
position +=l[i]
x[i] = position
kotak[i].x = x[i]


def updatePegas():
global l
for i in arange(n):
if i!=0:
pegas[i].x = x[i-1]
l[i] = x[i]-x[i-1]
else:
l[i] = x[i]

kotak[i].x = x[i]
pegas[i].length = l[i]

def proses():
for i in arange(n):
dx[i] = l[i]-l0[i]
f0 = -k[i]*dx[i]
if i<n-1:
dx[i+1] = l[i+1]-l0[i+1]
f1 = -k[i+1]*dx[i+1]
a = (f0-f1)/m[i]
else:
a = f0/m[i]
v[i] += a*dt
x[i] += v[i]*dt
updatePegas()
while 1:
rate (19)
proses()

.

Monday, May 9, 2016

Here's the Culprit



 In Visual Python, helix object will generate error if helix.length = some array like the code below. I use dl, an array, for the length value
from visual import *

display(center=(1,0,0),background=(1,1,1), autoscale=False, range=(2,2,2),
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)
n = 1
dt = 1./8.
dl = ones(1)

pegas = []

print dl


for i in arange(n):
spring = helix(pos=(0,0,0), axis=(5,0,0), radius=0.2, color=color.red, length=1.)
pegas.append(spring)

def updatePegas(l):
pegas[0].length = l



def proses():
global dl
l = pegas[0].length
if l>2:
l = 2
dl[0] *= -1
elif l<.5:
l = .5
dl[0] *= -1
l += dl[0]
updatePegas(l)

while 1:
rate (19)
proses()








.



And the result is
Traceback (most recent call last):
File "springList.py", line 40, in
proses()
File "springList.py", line 36, in proses
updatePegas(l)
File "springList.py", line 22, in updatePegas
pegas[0].length = l
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/VPython-6.11-py2.7-macosx-10.6-intel.egg/visual_common/primitives.py", line 850, in set_length
self.__frame.axis = self.__axis.norm()
AttributeError: 'numpy.ndarray' object has no attribute 'norm'


If we change dl from array to list, like the code below, everything is suddenly OK, :)
from visual import *

display(center=(1,0,0),background=(1,1,1), autoscale=False, range=(2,2,2),
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)
n = 1
dt = 1./8.
#dl = ones(1)
dl = []
dl.append(.1)
pegas = []

print dl


for i in arange(n):
spring = helix(pos=(0,0,0), axis=(5,0,0), radius=0.2, color=color.red, length=1.)
pegas.append(spring)

def updatePegas(l):
pegas[0].length = l



def proses():
global dl
l = pegas[0].length
if l>2:
l = 2
dl[0] *= -1
elif l<.5:
l = .5
dl[0] *= -1
l += dl[0]
updatePegas(l)

while 1:
rate (19)
proses()








.

Gonna rewrite the code.


Sunday, May 8, 2016

Double Spring System

Akhirnya.

With Visual Python module

I couldn't use list for spring length since it'll trigger some error for helix object. It's very unfortunate because it would come handy as we expand the number of spring and mass.

Anyway, here's the code

#code
from visual import *
from random import uniform,random
from visual.controls import *

display(center=(1,0,0),background=(1,1,1), autoscale=False, range=(2,2,2),
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)
n = 2
dt = 1./8.
pegas = []
kotak = []
box(pos=(-1,0,0), width=2, height=2, length= 2, color=color.black)
box(pos=(0,-.36,0), width=2, height=.2, length= 5, color=color.black,opacity=.3)
for i in arange(n):
spring = helix(pos=(0,0,0), axis=(5,0,0), radius=0.2, color=color.red, length=1.)
pegas.append(spring)
ko = box(pos=(0,0,0), width=.5, height=.5, length= .5, color= color.green)
kotak.append(ko)

k0 = 1.
k1 = 1.

m0 = 1.
m1 = 1.

l00 = 1.
l01 = 1.

l0 = 1.
l1 = 1.1

x0 = l0
x1 = l0+l1

v0 = 0.
v1 = 0.


y = 1.
print x1
def updatePegas():
global x0,x1
kotak[0].x = x0
pegas[0].length = l0

kotak[1].x = x1
pegas[1].x = l0
pegas[1].length = l1



def proses():
global l0,v0,x0,l1,v1,x1
#untuk m0
dx0 = l0-l00
f0 = -k0*dx0
dx1 = l1-l01
f1 = -k1*dx1
a0 = (f0-f1)/m0
v0 += a0*dt
x0 += v0*dt
l0 = x0
#untuk m1
a1 = f1/m1
v1 += a1*dt
x1 += v1*dt
l1 = x1-x0


updatePegas()

while 1:
rate (39)
y += .1
proses()








.


Saturday, May 7, 2016

Tangkisan.


 Banyak yang sibuk menangkis tuduhan dengan menyerang balik. Atau dengan menghabiskan waktu menjawab dan mengklarifikasi segala macam tuduhan.

 Jarang  ada yang membuktikan dengan tindakan bahwa tuduhan itu tak benar.

 Lebih jarang lagi yang cuek, melanjutkan hidup, tanpa perlu membuktikan apapun.

 Padahal yang terakhir membutuhkan energi yang lebih sedikit.

 #Megatruh

Menyambut Bulan Puasa.

 Tentu saja menyiapkan kuota.

 Menyimpan sebanyak mungkin puisi bagus untuk di-paste di grup-grup media sosial.

 Menyusun draft untuk meminta maaf via sms atau messenger lain sehari sebelum puasa, terlepas bahwa minta maaf itu harusnya terjadi saat kita melakukan kesalahan, atau pas hari raya. Yang penting ikut trend.

 Oh iya, bisa juga buka-buka sms lama tahun lalu, cari yang bahasanya keren, jawa kuno, lucu, atau yang gak jelas sekalian. Diusahakan tahun ini dikirim kepada kontak baru atau yang tahun lalu belum pernah dapat.

 Ehm, sekarang kan juga banyak "gambar tulisan" tentang segala hal. Tentu saja besar kemungkinan ada "gambar tulisan" tentang awal puasa.

 Ohya, jangan lupa set reminder untuk sepuluh hari terakhir puasa. Itu musim "sharing" tulisan-tulisan tentang keutamaan berbagai macam kegiatan, yang biasanya di bawahnya ada catatan: "kirim ke limapuluh kenalan agar dijamin masuk surga minimal level 5".  Meskipun berat di bandwith dan kuota, tak ada salahnya ikut tren yang ini.

 Kemungkinannya kecil, tapi usahakan cari masjid yang ada akses wifi gratis, biar saat selfie di sana bisa langsung upload. Mungkin saja seratus posting pertama dengan hashtag #tarwih mendapat bonus poin pahala.

 Selamat bersiap-siap, :)

#edisiError
#Naya

Normal Mode


 Planned to write coupled oscillator, using double spring.

 For some reason, Vpython refused to set length of helix with some value from array or list or any value derived from them. It only accept plain number or  number from simple variable (like a = 3. ). It hugely messed the whole script as I used l = [] for helix length.

 So, rewriting the code, create l0 and l1 manually.

 Didn't have energy to code the rest. So, at the moment, just call it "normal mode" coupled oscillator, heheh...

#code

from visual import *
from random import uniform,random
from visual.controls import *

display(center=(0,0,0),background=(1,1,1), autoscale=False, range=(5,5,3),
width=600, height=600, forward=(-1.4,-1.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)
n = 2
dt = 1./8.
pegas = []
kotak = []
w = ones(n)
w /= 2.
for i in arange(n):
spring = helix(pos=(0,0,0), axis=(5,0,0), radius=0.2, color=color.red, length=1.)
pegas.append(spring)
ko = box(pos=(0,0,0), width=.5, height=.5, length= .5, color= color.green)
kotak.append(ko)

k0 = 1.
m0 = 1.

l00 = 1.
l01 = 1.

l0 = 1.1
l1 = 1.

x0 = l0+w[0]/2

v0 = 0.
v1 = 0.


y = 1.
print pegas[0].length
def updatePegas():
global x0
kotak[0].x = x0
pegas[0].length = l0

x1 = l0+w[0]+l1+w[1]/2
kotak[1].x = x1
pegas[1].x = l0+w[0]



def proses():
global l0,v0,x0
dx = l0-l00
f0 = -k0*dx
a0 = f0/m0
v0 += a0*dt
l0 += v0*dt
x0 = l0+w[0]/2


updatePegas()

while 1:
rate (19)
y += .1
proses()








.



Sharing


 Jadi ceritanya gini:

 Saya berangkat sekolah,

 trus diperkosa,

 trus dibunuh.

 The End.

 Mohon dicopy dan sebarluaskan ke medsos ya, :D

 #edisiError
 #Naya

Friday, May 6, 2016

One Blog a Day keep Doc Away

 :)

Spring.

 Bahan baru buat ide jahil besok, :)


#code
from visual import *
from random import uniform,random
from visual.controls import *

display(center=(0,0,0),background=(1,1,1), autoscale=False, range=(3,5,3),
width=600, height=600, forward=(-1.4,-1.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)
spring = helix(pos=(0,2,1), axis=(5,0,0), radius=0.5, color=color.red)

dl = .1
l = 1.
def proses():
global l,dl
spring.length = l
if l>2:
l = 2
dl *= -1
elif l<.5:
l = .5
dl *= -1
l += dl

while 1:
rate (19)
proses()







.





Piston Free Expansion Oscillation.

The result of daydreaming, :)

#code
from visual import *
from random import uniform,random
from visual.controls import *

display(center=(0,0,0),background=(1,1,1), autoscale=False, range=(5,7,7),
width=600, height=600, forward=(0.4,-0.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)
cylinder(pos=(-4,0,0), axis=(7,0,0), radius=1, color=color.green, opacity=.1)
piston = cylinder(pos=(-2,0,0), axis=(1,0,0), radius=.7, color=color.red)
piston1 = cylinder(pos=(-2,0,0), axis=(5,0,0), radius=.1, color=color.red)

p0 = 1.
A = 1.
x0 = 5. #panjang piston
c = p0*A*x0
x = 3
dx = x0-x #
m = 1.
v = 0.
dt = 1./8.
def proses():
global x,v,dx
p = c/x
dp = p-p0
print x,dp
f = -dp
a = f/m
v += a*dt
dx += v*dt
x -= v*dt

piston.x = dx
piston1.x = dx
while 1:
rate (19)
proses()






.



Ball Oscillation Inside a Sphere

 with Visual Python.

 I use nonlinear solution, :)


#code
from visual import *
from random import uniform,random
from visual.controls import *

display(center=(0,0,0),background=(1,1,1), #autoscale=False,
width=600, height=600, forward=(-0.4,-0.3,-1)) #arah kamera

distant_light(direction=(1,1,1), color=color.red)

dl = .01
l = 1.1

box(color=color.white, pos=(0,0,0),length=2*l,height=dl, width=dl, opacity=.3)
box(color=color.white, pos=(0,0,0),length=dl,height=2*l, width=dl, opacity=.3)
box(color=color.white, pos=(0,0,0),length=dl,height=dl, width=2*l, opacity=.3)


bola1 = sphere (pos=(0,0,0), radius=1.1, color=color.green, opacity=.3)
bola = sphere (pos=(1,0,0), radius=.1, color=color.red)

r = 1.
x = 1.
m = 1.
g = 1.
vx = 0.
dt = 1./16.
def proses():
global x,vx
f = -m*g*x/r
a = f/m
vx += a*dt
x += vx*dt
r2 = r*r
x2 = x*x
if x2>r2:
x2 = r2
y = r-sqrt(r2-x2)
bola.x = x
print x
bola.y = y-r

while 1:
rate (19)
proses()







.




Monday, May 2, 2016

Thursday, April 28, 2016

3D Ball Collision in Python with Visual Module.


I only compute the collision between bed and blue one. They're bola[1] and bola[2] respectively


from visual import *
from random import uniform,random
from visual.controls import *

def change():
global jalan
if b.value:
jalan = True
for ball in(bola):
ball.vx = uniform(-7,7)
ball.vy = uniform(-7,7)
ball.vz = uniform(-7,7)
else:
jalan = False

c = controls(title='Tempat Tombol',x=800, y=0, width=300, height=300, range=50)
b = toggle( pos=(0,0), width=20, height=20, text='Click me', action=lambda: change() )
display(center=(0,0,0),background=(1,1,1), #autoscale=False,
width=600, height=600, forward=(-0.4,-0.3,-1)) #arah kamera
g = -1.
dt = .1
e = 1.
b.value = True
jalan = True
l = 17.
dl = .01
n = 11

distant_light(direction=(1,1,1), color=color.red)
lantai = box(color=color.white, pos=(0,0,0),length=l,height=dl, width=l, opacity=.3)
dindingKiri = box(color=color.white, pos=(-l/2,l/2,0),length=dl,height=l, width=l, opacity=.3)
dindingKanan= box(color=color.white, pos=(l/2,l/2,0),length=dl,height=l, width=l, opacity=.3)
dBelakang = box(color=color.white, pos=(0,l/2,-l/2),length=l,height=l, width=dl, opacity=.3)
atap = box(color=color.white, pos=(0,l,0),length=l,height=dl, width=l, opacity=.3)
bola = []
for i in arange(n):
ball = sphere (pos=(uniform(1,7),0,uniform(-7,7)), radius=.3, color=color.green)
ball.v = vector(uniform(-7,7),uniform(-7,7),uniform(-7,7))
bola.append(ball)


bola[1].radius = 2.5
bola[2].radius = 2.5

bola[1].color = color.red
bola[2].color = color.blue
def proses():
for ball in (bola):
a = g
ball.v[1] += a*dt
ball.pos+= ball.v*dt
tumbukan()
tumbukanBola()

def tumbukan():
for ball in(bola):
if ball.y<0:
ball.y = 0.01
ball.v[1] *=-1.*e
elif ball.y>l:
ball.y = l-.01
ball.v[1] *= -1
if ball.x<-l/2:
ball.x=-l/2+.01
ball.v[0] *= -1*e
if ball.x>l/2:
ball.x=l/2-.01
ball.v[0] *= -1*e
if ball.z<-l/2:
ball.z=-l/2+.01
ball.v[2] *= -1*e
if ball.z>l/2:
ball.z=l/2-.01
ball.v[2] *= -1*e

def tumbukanBola():
#pass
jarak = mag(bola[2].pos-bola[1].pos)
if jarak<(bola[1].radius+bola[2].radius):
arah = norm(bola[2].pos-bola[1].pos)
v1 = dot(bola[1].v,arah)
v2 = dot(bola[2].v,arah)
dv = v2-v1
bola[1].v += dv*arah
bola[2].v -= dv*arah



while 1:
rate (51)
if jalan:
proses()







.





Alright, Now Do It in Python, with style, :)


Python version of this flash action script of electron under Lorentz force, :)

from visual import *
from random import uniform

display(center=(0,0,0),background=(1,1,1), autoscale=False,
width=600, height=600,
#forward=(-0.4,-0.3,-1)
)

distant_light(direction=(1,1,1), color=color.red)


l = 11
dt = 1./8.
medan = box(color=color.white,
pos=(l/2,0,0),length=l,height=l,
width=l, opacity=.3)

ball = sphere (pos=(-7,0,0), radius=.3, color=(uniform(0,1),uniform(0,1),uniform(0,1)))

def awal():
global q,m,B,v
q = 1.
m = 1.
B = vector(0.,0.,1.)
v = vector(3.,0.,0.)


def proses():
global v,B
if ball.x > 0:
B = vector(0.,0.,1.)
else:
B = vector(0.,0.,0.)
print B
F = q*(cross(v,B))
a = F/m
v += a*dt

ball.pos += v*dt
print ball.x

awal()
while 1:
rate (37)
proses()



.





Menyapa Senjata Lama.


Sudah lama tidak otak-atik Macromedia Flash.

Yup, masih yang Macromedia, bukan Adobe, :) .

Membuat animasi bola bermuatan (atau elektron) yang bergerak lurus dengan kecepatan konstan tiba-tiba mencapai daerah dengan  medan magnet. Sesuai hukum Lorentz maka bola/elektron akan bergerak melengkung.

Action script hanya ditulis pada action di frame pertama layer background.






px0 = bola._x;
py0 = bola._y;
awal();
_root.onEnterFrame = function() {
if (jalan == true) {
proses();
}
//trace(jalan)
};
function awal() {
jalan = false;
bola._x = px0;
bola._y = py0;
q = 1;
B = 1;
tB.text = B;
//massa
m = 1;
tm.text = m;
//kecepatan
vx = 50;
vy = -10;
tvx.text = vx;
tvy.text = vy;
//percepatan
ax = 0;
ay = 0;
//posisi
px = 0;
py = 0;
dt = 1/8;
}
function bacaInput() {
vx = Number(tvx.text);
vy = Number(tvy.text);
m = Number(tm.text);
B = Number(tB.text);
}
function updateNilai() {
tB.text = B;
tm.text = m;
tvx.text = vx;
tvy.text = vy;
}
function proses() {
v = Math.sqrt(vx*vx+vy*vy);
if (bola._x>200) {
F = B*q*v;
} else {
F = 0;
}
a = F/m;
//arah vektor normal v
nvx = vx/v;
nvy = vy/v;
/*arah vektor percepatan
karena vektor yang tegak lurus a=(ax,ay) adalah at=(-ay,ax)
*/
nax = -nvy;
nay = nvx;
ax = a*nax;
ay = a*nay;
//hitung kecepatan baru
vx += ax*dt;
vy += ay*dt;
px += vx*dt;
py -= vy*dt;
trace(F);
//update posisi bola
bola._x = px0+px;
bola._y = py0+py;
updateNilai();
}
//tombol-tombol
//tombol tbJalan
tbJalan.onRelease = function() {
bacaInput();
jalan = true;
};
tbStop.onRelease = function() {
jalan = false;
};
tbReset.onRelease = function() {
awal();
};


.







Wednesday, April 27, 2016

Iterasi di Python


Jika kita punya sebuah list bernama bola yang didefinisikan sebagai:

bola = []

kemudian kita membuat obyek bernama ball

ball = sphere (pos=(uniform(1,7),0,uniform(-7,7)), radius=.3, color (uniform(0,1),uniform(0,1),uniform(0,1)))
ball.vx  = uniform(-7,7)
ball.vy  = uniform(-7,7)
ball.vz  = uniform(-7,7)
 
Obyek ini kita masukkan ke dalam bola dengan perintah

bola.append(ball)

Kita dapat melakukannya berkali-kali sehingga pada list bola terdapat beberapa obyek bernama ball

Jika kita ingin mengakses obyek tersebut, kita dapat menggunakan perintah semacam

bola[0].vx = 1

jika kita ingin mengakses vx di semua obyek bola, kita dapat menggunakan iterasi

for i in arange (n):
  bola[i].vx = 1


Namun di python ada cara lain yang juga mudah

for ball in (bola):
  ball.vx = 1

Berikut contoh kode yang menggunakan iterasi seperti itu

from visual import *
from random import uniform,random
from visual.controls import *

def change():
global jalan,vx,vy,vz
if b.value:
jalan = True
for ball in(bola):
ball.vx = uniform(-7,7)
ball.vy = uniform(-7,7)
ball.vz = uniform(-7,7)
else:
jalan = False

c = controls(title='Tempat Tombol',x=800, y=0, width=300, height=300, range=50)
b = toggle( pos=(0,0), width=20, height=20, text='Click me', action=lambda: change() )
display(center=(0,0,0),background=(1,1,1), #autoscale=False,
width=600, height=600, forward=(-0.4,-0.3,-1)) #arah kamera
g = -1.
dt = .1
e = 1.
b.value = True
jalan = True
l = 17.
dl = .01
n = 11

distant_light(direction=(1,1,1), color=color.red)
lantai = box(color=color.white, pos=(0,0,0),length=l,height=dl, width=l, opacity=.3)
dindingKiri = box(color=color.white, pos=(-l/2,l/2,0),length=dl,height=l, width=l, opacity=.3)
dindingKanan= box(color=color.white, pos=(l/2,l/2,0),length=dl,height=l, width=l, opacity=.3)
dBelakang = box(color=color.white, pos=(0,l/2,-l/2),length=l,height=l, width=dl, opacity=.3)
atap = box(color=color.white, pos=(0,l,0),length=l,height=dl, width=l, opacity=.3)
bola = []
for i in arange(n):
ball = sphere (pos=(uniform(1,7),0,uniform(-7,7)), radius=.3, color=(uniform(0,1),uniform(0,1),uniform(0,1)))
ball.vx = uniform(-7,7)
ball.vy = uniform(-7,7)
ball.vz = uniform(-7,7)
bola.append(ball)

def proses():
global vx,vy,vz
for ball in (bola):
a = g
ball.vy += a*dt
ball.pos+= vector(ball.vx*dt,ball.vy*dt,ball.vz*dt)
tumbukan()

def tumbukan():
global vx,vy,vz
for ball in(bola):
if ball.y<0:
ball.y = 0.01
ball.vy *=-1.*e
elif ball.y>l:
ball.y = l-.01
ball.vy *= -1
if ball.x<-l/2:
ball.x=-l/2+.01
ball.vx *= -1*e
if ball.x>l/2:
ball.x=l/2-.01
ball.vx *= -1*e
if ball.z<-l/2:
ball.z=-l/2+.01
ball.vz *= -1*e
if ball.z>l/2:
ball.z=l/2-.01
ball.vz *= -1*e

while 1:
rate (100)
if jalan:
proses()


.




323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)