回答編集履歴

1

追記

2023/12/04 07:35

投稿

TN8001
TN8001

スコア9367

test CHANGED
@@ -36,3 +36,82 @@
36
36
  }
37
37
  ```
38
38
  ![証拠動画](https://ddjkaamml8q8x.cloudfront.net/questions/2023-12-02/e762c245-b6b7-4f94-8269-38ea770d1e4d.gif)
39
+
40
+ ---
41
+
42
+ ## 追記
43
+ 端的に言うと14行目より前の部分がいらないです(コメント化しましたが削除してしまって結構です)
44
+ ```Processing
45
+ //size(300,300);
46
+ //smooth();
47
+ //background(0);
48
+ //imageMode(CENTER);
49
+
50
+ //PImage img=loadImage("C_Pro.png");
51
+
52
+ // int x=int(random(width));
53
+ // int y=int(random(height));
54
+ // float scale=random(0.2,0.8);
55
+
56
+ // image(img,x,y,img.width*scale, img.height*scale);
57
+
58
+ PImage img;
59
+
60
+ void setup(){
61
+ size(300,300);
62
+ smooth();
63
+ background(0);
64
+ imageMode(CENTER);
65
+
66
+ img=loadImage("C_Pro.png");
67
+
68
+ frameRate(3);
69
+ }
70
+ void draw(){
71
+ int x=int(random(width));
72
+ int y=int(random(height));
73
+ color c=getRandomColor();
74
+
75
+ drawChara(x,y,c);
76
+ }
77
+
78
+ color getRandomColor(){
79
+ colorMode(HSB,360,100,100);
80
+ color c=color(random(60,300),80,99);
81
+ return c;
82
+ }
83
+ void drawChara(float charaX,float charaY,color charaColor){
84
+ tint(charaColor);
85
+ image(img,charaX,charaY);
86
+ }
87
+ ```
88
+
89
+ Processingではstaticモードとactiveモードという2つの書き方があります。
90
+ 提示のコードは両方が混じってしまっています。そのためエラーになっています(エラー文がよくないですが...
91
+
92
+ 例えばこういうのがstaticモードです。
93
+ 動きがないスケッチなら、setupやdrawを書かずに短くシンプルに書くことができます。
94
+ ```Processing
95
+ size(400, 400);
96
+ background(192, 64, 0);
97
+ stroke(255);
98
+ line(150, 25, 270, 350);
99
+ ```
100
+
101
+ そしてこういうのがactiveモードです。
102
+ 動きがあるスケッチは初回に実行されるsetupと、毎フレーム呼ばれるdrawが必要です。
103
+ ```Processing
104
+ void setup() {
105
+ size(400, 400);
106
+ stroke(255);
107
+ background(192, 64, 0);
108
+ }
109
+ void draw() {
110
+ line(150, 25, mouseX, mouseY);
111
+ }
112
+ ```
113
+
114
+ ---
115
+
116
+ エラー文が改善したと思っていたんですが、いつの間にか戻ってますねぇ^^;
117
+ ["Missing operator, semicolon, or '}' near 'setup'?"  のエラー表示が消えない](https://teratail.com/questions/ho21mdgc7hmba8)