首页 \ 问答 \ 如何填充曲线内的颜色?(How to fill the color inside the curve?)

如何填充曲线内的颜色?(How to fill the color inside the curve?)

我想创建一个使用函数curve(...)创建一些封闭区域的图片,但我不知道如何填充内部颜色。

有没有办法填补头部和身体?

void setup(){
  size(800,800);
}

void draw(){
  background(170,243,255);
  fish();
}

void fish(){
  translate(width/2, height/2);//mouseX, mouseY

  //eye
  fill(231,255,188);
  stroke(0);
  ellipse(-100,-100,50,45);
  fill(0);
  ellipse(-100,-100,30,28);

  //head
  noFill();
  strokeWeight(2);
  stroke(157,88,255);
  curve(-400,-100,-200,-200,50,-150,150,50);
  curve(-100,-400,-200,-200,-150,50,0,100);
  curve(-300,50,-150,50,50,-150,50,-300);

  //body
  curve(-200,-350,50,-150,250,250,600,300);
  curve(-200,-200,-150,50,250,250,500,250);
}

I want to create a picture that has some closed areas using function curve(...), but I do not know how to fill the color inside.

Is there any way to fill inside the head and body?

void setup(){
  size(800,800);
}

void draw(){
  background(170,243,255);
  fish();
}

void fish(){
  translate(width/2, height/2);//mouseX, mouseY

  //eye
  fill(231,255,188);
  stroke(0);
  ellipse(-100,-100,50,45);
  fill(0);
  ellipse(-100,-100,30,28);

  //head
  noFill();
  strokeWeight(2);
  stroke(157,88,255);
  curve(-400,-100,-200,-200,50,-150,150,50);
  curve(-100,-400,-200,-200,-150,50,0,100);
  curve(-300,50,-150,50,50,-150,50,-300);

  //body
  curve(-200,-350,50,-150,250,250,600,300);
  curve(-200,-200,-150,50,250,250,500,250);
}

原文:https://stackoverflow.com/questions/32600237
更新时间:2023-09-01 08:09

最满意答案

目前你只是调用Wait() - 它将阻塞直到任务完成,但不会给你返回值。 如果您使用Result属性,则会阻塞并给出结果:

string certificate = saba.Login(username, password, site).Result;

现在,这将在控制台应用程序中工作,因为没有SynchronizationContext ...这意味着异步方法中的延续将在线程池线程上执行。 如果你使用WinForms UI线程中的相同代码(例如),那么你最终会遇到死锁 - UI线程将等待任务完成,但是直到进入UI时才能完成任务线程执行更多代码。

SabaCertificate一下,这似乎是在SabaModel中存储SabaCertificateSabaController ,但它不应该这样做。


Currently you're just calling Wait() - that will block until the task completes, but won't give you the return value. If you use the Result property instead, that will block and then give you the result:

string certificate = saba.Login(username, password, site).Result;

Now, that will work in a console app because there's no SynchronizationContext... which means continuations in the async method will be executed on a thread pool thread. If you use the same code from a WinForms UI thread (for example) then you'd end up with a deadlock - the UI thread would be waiting for the task to complete, but the task couldn't complete until it got onto the UI thread to execute some more code.

As an aside, this appears to be storing SabaCertificate and SabaModel in the SabaController, but it's not obvious that it should be doing that.

相关问答

更多
  • 好吧,所以:第一个代码块返回一个Task,但它实际上并没有返回任何地方。 确实。 您可以将其视为Task - 如果它是有效的。 它用于指示异步方法何时完成。 基本上,任何非void异步方法都会包装您在任务中返回的任何内容。 例如: async Task FooAsync() { // Do some async operations return "foo"; } 请注意, return语句中表达式的类型是string ,但方法的声明返回类型是Task
  • 您正在寻找的是Callback接口,根据您的需要,您需要使用单个参数实现单个方法的简单接口,因为Java 6(Android Java版本)没有开箱即用的约定,您可以自己轻松创建它: interface Callback { void act(List models); } 将它作为参数传递给firebase包装方法,并使用结果调用它。 public void getAllAttendeesFor(String UUID, final ArrayList
  • 你正在执行第二项任务。 继续((t)任务。 要运行正确的,你需要重构代码。 像这样拆分线条: Task t1 = Task.Run(() => program.GenerateXml()); t1.ContinueWith((t) => { return ""; }, TaskContinuationOptions.OnlyOnFaulted); tasks.Add(t1); 你可以像这样重构任务:(用于错误处理) tasks.Add(program.Generat ...
  • 您将需要使用闭包,或将您的函数更改为同步。 func ColorSwitch(label: [UILabel], completion:@escaping ([Int])->Void) { completion([1,2,3,4]) // when you want to return } ColorSwitch(label: [UILabel()]) { (output) in // output is the array of ints print("output: \(out ...
  • 要从Task获取值,您可以await异步等待任务完成的任务,然后返回结果。 另一个选项是调用Task.Result ,它阻塞当前线程直到结果可用。 这可能会导致GUI应用程序出现死锁 ,但在控制台应用程序中可以正常运行,因为它们没有SynchronizationContext 。 你不能在Main方法中使用await ,因为它不能是async因此一个选项是使用test1.Result : static void Main(string[] args) { Task test1 = Ta ...
  • 目前你只是调用Wait() - 它将阻塞直到任务完成,但不会给你返回值。 如果您使用Result属性,则会阻塞并给出结果: string certificate = saba.Login(username, password, site).Result; 现在,这将在控制台应用程序中工作,因为没有SynchronizationContext ...这意味着异步方法中的延续将在线程池线程上执行。 如果你使用WinForms UI线程中的相同代码(例如),那么你最终会遇到死锁 - UI线程将等待任务完成,但是 ...
  • 首先将getfavcity()返回类型从void更改为String 。 喜欢, public String getfavcity() { FavCity.clear(); String url = Utility.gBasepath + "getCityList/" + gCountryValue + "/" + gFavState.replaceAll(" ", "%20"); JSONObject json = Getjsonurl ...
  • 该功能是TAP本身(基于任务的异步模式)或async-await因为它主要被称为。 async关键字告诉编译器生成状态机,因此您可以使用await 。 它还会生成一个Task (带有结果值,如果有的话)或者在方法运行时可能出现的任何异常。 在你的情况下, pipeReader.ReadLineAsync()返回一个Task(Of String)而不是String 。 Await是使您能够在完成任务时“提取”该任务的实际结果的原因。 当你自己返回result ,编译器知道生成一个Task(Of String) ...
  • Task没有返回值; Task确实如此。 您必须修改PeriodicTaskFactory代码以返回Task ,然后创建Task对象。 该方法还应该接受Func (没有参数,返回T)而不是Action ,它没有返回值。 public static Task Start(Func func, int intervalInMilliseconds = Timeout.Infinite, int delayInMilliseconds = ...
  • 在LongRunningOperation内的代码中最后一个return语句的目的是什么。 返回字符串“Counter = 50000”并演示循环已完成。 这不是很有用,但显然,这是一个玩具的例子。 您可以将方法声明为static async Task而不是static async Task而不返回值。 当我在Task.Run调用这个LongrunningOperation ,它应该返回默认返回的等待方法。 然后为什么不这样做。 是什么让你认为它不是那样做的? 以下代码段是否未返回预期结果? ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)