Processing3.3.5でPythonを用いて以下のようなプログラムを実行しました.
Python
1# シリアル通信ライブラリ追加 2add_library('serial') 3 4# 最低・最大温度 5min_temp = 20 / 0.25 6max_temp = 38 / 0.25 7 8def setup(): 9 # ウィンドウタイトルと画面サイズ設定 10 size(384 * 2, 384) 11 frame.setTitle("GridEye View") 12 13 14 # シリアルポート初期化 15 print Serial.list() 16 portIndex = 3 # 環境に合わせて変更してください 17 print "Connecting to", Serial.list()[portIndex] 18 global myPort 19 myPort = Serial(this, Serial.list()[portIndex], 115200) 20 21 # ピクセル温度データ初期化 22 global pixel_buffer 23 pixel_buffer = [0 for i in range(64)] 24 25 # 8x8イメージ作成 26 global pg 27 pg = createGraphics(8, 8) 28 29 # グラデーションテーブル作成 30 global gradient 31 gradient = [] 32 last_c = color(6, 3, 25) 33 base_c = [color(51, 24, 131), 34 color(163, 38, 135), 35 color(210, 38, 41), 36 color(239, 121, 37), 37 color(250, 216, 54), 38 color(254, 247, 210)] 39 for c in base_c: 40 for i in range(15): 41 # 中間色を追加 42 inter = lerpColor(last_c, c, .0625 * (i + 1)) 43 gradient.append(inter) 44 last_c = c 45 # print len(gradient) 46 # print gradient 47 48def draw(): 49 global pixel_buffer 50 # ピクセルデータ受信 51 while myPort.available() >= 130: 52 # ヘッダチェック1 53 if myPort.read() == 0x55: 54 # ヘッダチェック2 55 if myPort.read() == 0xaa: 56 # 128バイト分読み出し 57 for i in range(64): 58 # 1ピクセル2バイトの整数型で下位バイト、上位バイトの順で送られてくる 59 lo = myPort.read() 60 hi = myPort.read() 61 temp = (hi << 8) | lo 62 pixel_buffer[i] = temp 63 print pixel_buffer 64 break 65 # 8x8イメージ更新 66 pg.beginDraw() 67 for y in range(pg.height): 68 for x in range(pg.width): 69 # 温度を色に変換 70 c = temp2Color(pixel_buffer[((8 - y - 1) * 8) + (8 - x - 1)]) 71 # ピクセル設定 72 pg.set(x, y, c) 73 pg.endDraw() 74 75 # ウィンドウの左側に転送 76 half_width = width / 2 77 image(pg, 0, 0, half_width, height) 78 79 # ウィンドウの右側にグリッド状に描画 80 rw = half_width / 8 81 rh = height / 8 82 padding = 4 83 fill(15) 84 noStroke() 85 rect(half_width, 0, half_width, height) 86 for y in range(pg.height): 87 for x in range(pg.width): 88 fill(pg.get(x, y)) 89 rect(half_width + (rw * x) + padding, (rh * y) + padding, 90 rw - (padding * 2), rh - (padding * 2), 5) 91 92def temp2Color(temp): 93 i = map(constrain(temp, min_temp, max_temp), 94 min_temp, max_temp, 0, len(gradient) - 1) 95 return gradient[int(i)]
そうすると以下のようなエラーが発生しました.
processing.app.SketchException: AttributeError: 'NoneType' object has no attribute 'setTitle' at jycessing.mode.run.SketchRunner.convertPythonSketchError(SketchRunner.java:240) at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:119) at java.lang.Thread.run(Thread.java:748)
これはどのようにプログラムを直せば解決するのでしょうか?
ちなみにframe.setTitle("GridEye View")のframeをsurfaceに変えてみてもダメでした.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。